diff --git a/appinfo/database.xml b/appinfo/database.xml
new file mode 100644
index 00000000..29b75449
--- /dev/null
+++ b/appinfo/database.xml
@@ -0,0 +1,86 @@
+
+ *dbname*
+ true
+ false
+ utf8
+
+ *dbprefix*passman_vaults
+
+
+ id
+ integer
+ true
+ true
+ true
+ true
+ 8
+
+
+ guid
+ text
+
+ true
+ 64
+
+
+
+ user_id
+ text
+
+ true
+ 64
+
+
+ name
+ text
+ 100
+ true
+
+
+
+ created
+ integer
+ 8
+ 0
+ false
+ true
+
+
+ last_access
+ integer
+ 0
+ 8
+ false
+ true
+
+
+
+ passman_last_access_index
+
+ last_access
+
+
+
+
+ passman_vault_guid_index
+
+ guid
+
+
+
+
+ npassman_vault_id_index
+
+ id
+
+
+
+
+ passman_vault_uid_id_index
+
+ user_id
+
+
+
+
+
\ No newline at end of file
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 01306efc..39d70b08 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,7 +5,7 @@
A password manager for Nextcloud
AGPL
Sander Brand
- 1.0.1
+ 1.0.2.1
Passman
other
https://github.com/nextcloud/passman/
diff --git a/controller/vaultcontroller.php b/controller/vaultcontroller.php
index 335273a6..61023887 100644
--- a/controller/vaultcontroller.php
+++ b/controller/vaultcontroller.php
@@ -14,15 +14,19 @@ namespace OCA\Passman\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
-use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\ApiController;
-
+use OCA\Passman\Service\VaultService;
class VaultController extends ApiController {
private $userId;
+ private $vaultService;
- public function __construct($AppName, IRequest $request, $UserId) {
+ public function __construct($AppName,
+ IRequest $request,
+ $UserId,
+ VaultService $vaultService) {
parent::__construct($AppName, $request);
$this->userId = $UserId;
+ $this->vaultService = $vaultService;
}
/**
@@ -30,40 +34,16 @@ class VaultController extends ApiController {
*/
public function listVaults() {
- $vaults = [
- array(
- 'vault_id' => uniqid(),
- 'name' => 'Vault ' . rand(1, 20),
- 'created' => time(),
- 'last_access' => time()
- ),
- array(
- 'id' => uniqid(),
- 'name' => 'Vault ' . rand(1, 20),
- 'created' => time(),
- 'last_access' => time()
- ),
- array(
- 'id' => uniqid(),
- 'name' => 'Vault ' . rand(1, 20),
- 'created' => time(),
- 'last_access' => time()
- ),
- array(
- 'id' => uniqid(),
- 'name' => 'Vault ' . rand(1, 20),
- 'created' => time(),
- 'last_access' => time()
- )
- ];
+ $vaults = $this->vaultService->getByUser($this->userId);
return new JSONResponse($vaults);
}
/**
* @NoAdminRequired
*/
- public function create() {
- return;
+ public function create($vault_name) {
+ $vault = $this->vaultService->createVault($vault_name, $this->userId);
+ return new JSONResponse($vault);
}
/**
diff --git a/js/app/controllers/vault.js b/js/app/controllers/vault.js
index 1a501132..d78950f8 100644
--- a/js/app/controllers/vault.js
+++ b/js/app/controllers/vault.js
@@ -26,9 +26,15 @@ angular.module('passmanApp')
$scope.selectVault = function(vault){
$scope.list_selected_vault = vault;
- }
+ };
$scope.newVault = function(){
$scope.creating_vault = true;
- }
+ };
+
+ $scope.createVault = function(vault_name){
+ VaultService.createVault(vault_name).then(function (result) {
+ console.log(result)
+ })
+ };
}]);
diff --git a/js/app/services/vaultservice.js b/js/app/services/vaultservice.js
index ad29a76c..c4d0aecf 100644
--- a/js/app/services/vaultservice.js
+++ b/js/app/services/vaultservice.js
@@ -21,8 +21,45 @@ angular.module('passmanApp')
}
});
},
- createVault: function (vault) {
-
+ createVault: function (vaultName) {
+ var queryUrl = OC.generateUrl('apps/passman/api/v1/vaults');
+ return $http.post(queryUrl, { vault_name: vaultName }).then(function (response) {
+ if(response.data){
+ return response.data;
+ } else {
+ return response;
+ }
+ });
+ },
+ getVault: function (vault) {
+ var queryUrl = OC.generateUrl('apps/passman/api/v1/vaults/' + vault.vault_id);
+ return $http.get(queryUrl).then(function (response) {
+ if(response.data){
+ return response.data;
+ } else {
+ return response;
+ }
+ });
+ },
+ updateVault: function (vault) {
+ var queryUrl = OC.generateUrl('apps/passman/api/v1/vaults/' + vault.vault_id);
+ return $http.post(queryUrl).then(function (response) {
+ if(response.data){
+ return response.data;
+ } else {
+ return response;
+ }
+ });
+ },
+ deleteVault: function (vault) {
+ var queryUrl = OC.generateUrl('apps/passman/api/v1/vaults/' + vault.vault_id);
+ return $http.delete(queryUrl).then(function (response) {
+ if(response.data){
+ return response.data;
+ } else {
+ return response;
+ }
+ });
}
}
}]);
diff --git a/js/templates.js b/js/templates.js
index 4f8e7cc2..a0ec2bfe 100644
--- a/js/templates.js
+++ b/js/templates.js
@@ -3,5 +3,5 @@ angular.module('templates-main', ['views/vaults.html']);
angular.module('views/vaults.html', []).run(['$templateCache', function($templateCache) {
'use strict';
$templateCache.put('views/vaults.html',
- '
- + Create a new vault
{{vault.name}}
Created: {{vault.created * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}} | Last accessed: {{vault.last_access * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}
');
+ '- + Create a new vault
{{vault.name}}
Created: {{vault.created * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}} | Last accessed: {{vault.last_access * 1000 | date:\'dd-MM-yyyy @ HH:mm:ss\'}}- No vaults found, why not create one?
');
}]);
diff --git a/lib/Credential.php b/lib/Db/Credential.php
similarity index 96%
rename from lib/Credential.php
rename to lib/Db/Credential.php
index ffb328d2..569182b4 100644
--- a/lib/Credential.php
+++ b/lib/Db/Credential.php
@@ -9,7 +9,7 @@
* @copyright Sander Brand 2016
*/
-namespace OCA\Passman;
+namespace OCA\Passman\Db;
use OCP\Activity\IManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
diff --git a/lib/Db/Vault.php b/lib/Db/Vault.php
new file mode 100644
index 00000000..c35b5901
--- /dev/null
+++ b/lib/Db/Vault.php
@@ -0,0 +1,44 @@
+
+ * @copyright Sander Brand 2016
+ */
+
+namespace OCA\Passman\Db;
+use \OCP\AppFramework\Db\Entity;
+
+/**
+ * @method integer getId()
+ * @method void setId(integer $value)
+ * @method void setName(string $value)
+ * @method string getName()
+ * @method void setGuid(string $value)
+ * @method string getGuid()
+ * @method void setUserId(string $value)
+ * @method string getUserid()
+ * @method void setCreated(integer $value)
+ * @method integer getCreated()
+ * @method void setlastAccess(integer $value)
+ * @method integer getlastAccess()
+ */
+
+
+class Vault extends Entity {
+
+ protected $guid;
+ protected $name;
+ protected $userId;
+ protected $created;
+ protected $lastAccess;
+
+ public function __construct() {
+ // add types in constructor
+ $this->addType('created', 'integer');
+ $this->addType('lastAccess', 'integer');
+ }
+}
\ No newline at end of file
diff --git a/lib/Db/VaultMapper.php b/lib/Db/VaultMapper.php
new file mode 100644
index 00000000..27d31253
--- /dev/null
+++ b/lib/Db/VaultMapper.php
@@ -0,0 +1,53 @@
+
+ * @copyright Sander Brand 2016
+ */
+namespace OCA\Passman\Db;
+
+use OCA\Passman\Utility\Utils;
+
+use OCP\IDBConnection;
+use OCP\AppFramework\Db\Mapper;
+//use OCA\Passman\Db\Vault;
+class VaultMapper extends Mapper {
+ private $utils;
+ public function __construct(IDBConnection $db, Utils $utils) {
+ parent::__construct($db, 'passman_vaults');
+ $this->utils = $utils;
+ }
+
+
+ /**
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ */
+ public function find($vault_id) {
+ $sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' .
+ 'WHERE `user_id` = ?';
+ return $this->findEntities($sql, [$vault_id]);
+ }
+
+ public function findVaultsFromUser($userId){
+ $sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' .
+ 'WHERE `user_id` = ? ';
+ $params = [$userId];
+ return $this->findEntities($sql, $params);
+ }
+
+ public function create($vault_name, $userId){
+ $vault = new Vault();
+ $vault->setName($vault_name);
+ $vault->setUserId($userId);
+ $vault->setGuid($this->utils->GUID());
+ $vault->setCreated($this->utils->getTime());
+ $vault->setlastAccess(0);
+ return parent::insert($vault);
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Service/VaultService.php b/lib/Service/VaultService.php
new file mode 100644
index 00000000..c8e2380e
--- /dev/null
+++ b/lib/Service/VaultService.php
@@ -0,0 +1,35 @@
+
+ * @copyright Sander Brand 2016
+ */
+
+namespace OCA\Passman\Service;
+
+use OCP\IConfig;
+use OCP\AppFramework\Db\DoesNotExistException;
+
+use OCA\Passman\Db\VaultMapper;
+
+
+class VaultService {
+
+ private $vaultMapper;
+
+ public function __construct(VaultMapper $vaultMapper) {
+ $this->vaultMapper = $vaultMapper;
+ }
+
+ public function getByUser($userId) {
+ return $this->vaultMapper->findVaultsFromUser($userId);
+ }
+
+ public function createVault($vault_name, $userId) {
+ return $this->vaultMapper->create($vault_name, $userId);
+ }
+}
\ No newline at end of file
diff --git a/lib/Utility/Utils.php b/lib/Utility/Utils.php
new file mode 100644
index 00000000..98e8c7bd
--- /dev/null
+++ b/lib/Utility/Utils.php
@@ -0,0 +1,33 @@
+
+ * @copyright Sander Brand 2016
+ */
+
+namespace OCA\Passman\Utility;
+class Utils {
+ public function getTime() {
+ return time();
+ }
+ /**
+ * @return int the current unix time in miliseconds
+ */
+ public function getMicroTime() {
+ list($millisecs, $secs) = explode(" ", microtime());
+ return $secs . substr($millisecs, 2, 6);
+ }
+
+ public function GUID() {
+ if (function_exists('com_create_guid') === true)
+ {
+ return trim(com_create_guid(), '{}');
+ }
+
+ return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
+ }
+}
\ No newline at end of file
diff --git a/lib/Vault.php b/lib/Vault.php
deleted file mode 100644
index 039ea2e2..00000000
--- a/lib/Vault.php
+++ /dev/null
@@ -1,39 +0,0 @@
-
- * @copyright Sander Brand 2016
- */
-
-namespace OCA\Passman;
-use OCP\Activity\IManager;
-use OCP\DB\QueryBuilder\IQueryBuilder;
-use OCP\IDBConnection;
-use OCP\IL10N;
-/**
- * @brief Class for managing the data in the activities
- */
-class Vault {
-
- /** @var IDBConnection */
- protected $connection;
- /**
- * @param IManager $activityManager
- * @param IDBConnection $connection
- */
- public function __construct(IDBConnection $connection) {
- $this->connection = $connection;
- }
-
- public function get(){
-
- }
-
- public function save(Vault $vault){
-
- }
-}
\ No newline at end of file
diff --git a/sass/app.scss b/sass/app.scss
index 8f5427a9..242902b5 100644
--- a/sass/app.scss
+++ b/sass/app.scss
@@ -1,5 +1,6 @@
@import 'container';
+@import 'variables';
@import 'mixins';
@import 'partials/button';
@import 'vaults';
diff --git a/sass/variables.scss b/sass/variables.scss
new file mode 100644
index 00000000..e69de29b
diff --git a/templates/views/vaults.html b/templates/views/vaults.html
index bd9e1848..cff25b43 100644
--- a/templates/views/vaults.html
+++ b/templates/views/vaults.html
@@ -18,19 +18,20 @@
+ No vaults found, why not create one?