mirror of
https://github.com/nextcloud/passman.git
synced 2025-01-27 17:57:55 +08:00
Merge branch 'master' of github.com:nextcloud/passman
This commit is contained in:
commit
cbd10de133
9 changed files with 55 additions and 19 deletions
|
@ -38,9 +38,26 @@ class VaultController extends ApiController {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function listVaults() {
|
||||
|
||||
$result = array();
|
||||
$vaults = $this->vaultService->getByUser($this->userId);
|
||||
return new JSONResponse($vaults);
|
||||
|
||||
$protected_credential_fields = array('getDescription','getEmail','getUsername','getPassword');
|
||||
|
||||
foreach($vaults as $vault){
|
||||
$credential = $this->credentialService->getRandomCredentialByVaultId($vault->getId(), $this->userId);
|
||||
$secret_field = $protected_credential_fields[array_rand($protected_credential_fields)];
|
||||
array_push($result, array(
|
||||
'vault_id' => $vault->getId(),
|
||||
'guid' => $vault->getGuid(),
|
||||
'name' => $vault->getName(),
|
||||
'created' => $vault->getCreated(),
|
||||
'public_sharing_key' => $vault->getPublicSharingKey(),
|
||||
'last_access' => $vault->getlastAccess(),
|
||||
'challenge_password' => $credential->{$secret_field}()
|
||||
));
|
||||
}
|
||||
|
||||
return new JSONResponse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ angular.module('passmanApp')
|
|||
.controller('SettingsCtrl', ['$scope', '$rootScope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$http', 'EncryptService','NotificationService',
|
||||
function ($scope, $rootScope, SettingsService, VaultService, CredentialService, $location, $routeParams, $http, EncryptService, NotificationService) {
|
||||
$scope.vault_settings = {};
|
||||
$scope.new_vault_name = '';
|
||||
$scope.active_vault = VaultService.getActiveVault();
|
||||
if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) {
|
||||
if (!$scope.active_vault) {
|
||||
|
@ -35,7 +36,8 @@ angular.module('passmanApp')
|
|||
'avoidAmbiguousCharacters': false,
|
||||
'requireEveryCharType': true,
|
||||
'generateOnCreate': true
|
||||
})
|
||||
});
|
||||
$scope.new_vault_name = angular.copy($scope.active_vault.name);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +45,11 @@ angular.module('passmanApp')
|
|||
|
||||
$scope.saveVaultSettings = function () {
|
||||
var _vault = $scope.active_vault;
|
||||
_vault.name = $scope.new_vault_name;
|
||||
_vault.vault_settings = angular.copy($scope.vault_settings);
|
||||
VaultService.updateVault(_vault).then(function () {
|
||||
VaultService.setActiveVault(_vault);
|
||||
$scope.active_vault.name = angular.copy(_vault.name);
|
||||
NotificationService.showNotification('Settings saved', 5000);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -101,19 +101,17 @@ angular.module('passmanApp')
|
|||
_vault.vaultKey = angular.copy(vault_key);
|
||||
|
||||
VaultService.setActiveVault(_vault);
|
||||
VaultService.getVault(vault).then(function (vault) {
|
||||
var credential = vault.credentials[0];
|
||||
try {
|
||||
var c = CredentialService.decryptCredential(credential);
|
||||
if ($scope.remember_vault_password) {
|
||||
SettingsService.setSetting('defaultVaultPass', vault_key);
|
||||
}
|
||||
_loginToVault(vault, vault_key);
|
||||
|
||||
} catch (e) {
|
||||
$scope.error = 'Incorrect vault password!'
|
||||
try {
|
||||
var c = EncryptService.decryptString(vault.challenge_password);
|
||||
if ($scope.remember_vault_password) {
|
||||
SettingsService.setSetting('defaultVaultPass', vault_key);
|
||||
}
|
||||
})
|
||||
_loginToVault(vault, vault_key);
|
||||
|
||||
} catch (e) {
|
||||
$scope.error = 'Incorrect vault password!'
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -73,8 +73,9 @@ angular.module('passmanApp')
|
|||
},
|
||||
updateVault: function (vault) {
|
||||
var _vault = angular.copy(vault);
|
||||
delete vault.defaultVaultPass;
|
||||
delete vault.defaultVault;
|
||||
delete _vault.defaultVaultPass;
|
||||
delete _vault.defaultVault;
|
||||
delete _vault.vaultKey;
|
||||
_vault.vault_settings = window.btoa(JSON.stringify(_vault.vault_settings))
|
||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + _vault.vault_id);
|
||||
return $http.patch(queryUrl, _vault).then(function (response) {
|
||||
|
|
|
@ -51,7 +51,7 @@ angular.module('views/partials/forms/settings/export.html', []).run(['$templateC
|
|||
angular.module('views/partials/forms/settings/general_settings.html', []).run(['$templateCache', function($templateCache) {
|
||||
'use strict';
|
||||
$templateCache.put('views/partials/forms/settings/general_settings.html',
|
||||
'<div class="row"><div class="col-xs-12 col-md-6"><h3>Change vault key</h3><label>Old vault password</label><input type="password" ng-model="oldVaultPass"><label>New vault password</label><password-gen ng-model="newVaultPass"></password-gen><ng-password-meter password="newVaultPass"></ng-password-meter><label>New vault password</label><input type="password" ng-model="newVaultPass2"> <button ng-click="changeVaultPassword(oldVaultPass,newVaultPass,newVaultPass2)" tooltip="\'Not working :P\'">Change</button></div><div class="col-xs-12 col-md-6"><h3>About passman</h3><p>Version: <b>{{passman_version}}</b><br>Bla bla about passman, changelog.<br><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6YS8F97PETVU2" target="_blank" class="link">Donate to support development</a></p></div></div>');
|
||||
'<div class="row"><div class="col-xs-12 col-md-6"><h3>Rename vault</h3><label>New vault name</label><input type="text" ng-model="$parent.new_vault_name"> <button ng-click="saveVaultSettings()" tooltip="\'Not working :P\'">Change</button><h3>Change vault key</h3><label>Old vault password</label><input type="password" ng-model="oldVaultPass"><label>New vault password</label><password-gen ng-model="newVaultPass"></password-gen><ng-password-meter password="newVaultPass"></ng-password-meter><label>New vault password</label><input type="password" ng-model="newVaultPass2"> <button ng-click="changeVaultPassword(oldVaultPass,newVaultPass,newVaultPass2)" tooltip="\'Not working :P\'">Change</button></div><div class="col-xs-12 col-md-6"><h3>About passman</h3><p>Version: <b>{{passman_version}}</b><br>Bla bla about passman, changelog.<br><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6YS8F97PETVU2" target="_blank" class="link">Donate to support development</a></p></div></div>');
|
||||
}]);
|
||||
|
||||
angular.module('views/partials/forms/settings/import.html', []).run(['$templateCache', function($templateCache) {
|
||||
|
|
|
@ -32,6 +32,12 @@ class CredentialMapper extends Mapper {
|
|||
return $this->findEntities($sql, [$user_id, $vault_id]);
|
||||
}
|
||||
|
||||
public function getRandomCredentialByVaultId($vault_id, $user_id) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' .
|
||||
'WHERE `user_id` = ? and vault_id = ? ORDER BY RAND() LIMIT 1';
|
||||
return $this->findEntities($sql, [$user_id, $vault_id]);
|
||||
}
|
||||
|
||||
public function getExpiredCredentials($timestamp){
|
||||
$sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' .
|
||||
'WHERE `expire_time` > 0 AND `expire_time` < ?';
|
||||
|
|
|
@ -49,7 +49,7 @@ class Vault extends Entity implements \JsonSerializable{
|
|||
protected $privateSharingKey;
|
||||
protected $sharingKeysGenerated;
|
||||
protected $vaultSettings;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
// add types in constructor
|
||||
$this->addType('created', 'integer');
|
||||
|
|
|
@ -44,6 +44,10 @@ class CredentialService {
|
|||
return $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
|
||||
}
|
||||
|
||||
public function getRandomCredentialByVaultId($vault_id, $user_id) {
|
||||
return array_pop($this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id));
|
||||
}
|
||||
|
||||
public function getExpiredCredentials($timestamp) {
|
||||
return $this->credentialMapper->getExpiredCredentials($timestamp);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<h3>Rename vault</h3>
|
||||
<label>New vault name</label>
|
||||
<input type="text" ng-model="$parent.new_vault_name">
|
||||
<button ng-click="saveVaultSettings()" tooltip="'Not working :P'">Change</button>
|
||||
|
||||
|
||||
<h3>Change vault key</h3>
|
||||
<label>Old vault password</label>
|
||||
<input type="password" ng-model="oldVaultPass">
|
||||
|
|
Loading…
Reference in a new issue