Closes #164: admin can send a password reset email to users

This commit is contained in:
Benjamin Gamard 2018-01-07 19:56:11 +01:00
parent b2d9684738
commit 7fc50f2629
3 changed files with 30 additions and 9 deletions

View File

@ -7,7 +7,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
/** /**
* Returns true if in edit mode (false in add mode). * Returns true if in edit mode (false in add mode).
*/ */
$scope.isEdit = function() { $scope.isEdit = function () {
return $stateParams.username; return $stateParams.username;
}; };
@ -15,7 +15,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
* In edit mode, load the current user. * In edit mode, load the current user.
*/ */
if ($scope.isEdit()) { if ($scope.isEdit()) {
Restangular.one('user', $stateParams.username).get().then(function(data) { Restangular.one('user', $stateParams.username).get().then(function (data) {
data.storage_quota /= 1000000; data.storage_quota /= 1000000;
$scope.user = data; $scope.user = data;
}); });
@ -24,7 +24,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
/** /**
* Update the current user. * Update the current user.
*/ */
$scope.edit = function() { $scope.edit = function () {
var promise = null; var promise = null;
var user = angular.copy($scope.user); var user = angular.copy($scope.user);
user.storage_quota *= 1000000; user.storage_quota *= 1000000;
@ -39,7 +39,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
.put(user); .put(user);
} }
promise.then(function() { promise.then(function () {
$scope.loadUsers(); $scope.loadUsers();
$state.go('settings.user'); $state.go('settings.user');
}, function (e) { }, function (e) {
@ -55,7 +55,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
/** /**
* Delete the current user. * Delete the current user.
*/ */
$scope.remove = function() { $scope.remove = function () {
var title = $translate.instant('settings.user.edit.delete_user_title'); var title = $translate.instant('settings.user.edit.delete_user_title');
var msg = $translate.instant('settings.user.edit.delete_user_message'); var msg = $translate.instant('settings.user.edit.delete_user_message');
var btns = [ var btns = [
@ -63,9 +63,9 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
{ result:'ok', label: $translate.instant('ok'), cssClass: 'btn-primary' } { result:'ok', label: $translate.instant('ok'), cssClass: 'btn-primary' }
]; ];
$dialog.messageBox(title, msg, btns, function(result) { $dialog.messageBox(title, msg, btns, function (result) {
if (result == 'ok') { if (result === 'ok') {
Restangular.one('user', $stateParams.username).remove().then(function() { Restangular.one('user', $stateParams.username).remove().then(function () {
$scope.loadUsers(); $scope.loadUsers();
$state.go('settings.user'); $state.go('settings.user');
}, function() { }, function() {
@ -75,4 +75,14 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
}); });
}; };
$scope.passwordReset = function () {
Restangular.one('user').post('password_lost', {
username: $stateParams.username
}).then(function () {
var title = $translate.instant('settings.user.edit.password_lost_sent_title');
var msg = $translate.instant('settings.user.edit.password_lost_sent_message', { username: $stateParams.username });
var btns = [{result: 'ok', label: $translate.instant('ok'), cssClass: 'btn-primary'}];
$dialog.messageBox(title, msg, btns);
});
};
}); });

View File

@ -249,7 +249,10 @@
"storage_quota_placeholder": "Storage quota (in MB)", "storage_quota_placeholder": "Storage quota (in MB)",
"password": "Password", "password": "Password",
"password_confirm": "Password (confirm)", "password_confirm": "Password (confirm)",
"disabled": "Disabled user" "disabled": "Disabled user",
"password_reset_btn": "Send a password reset email to this user",
"password_lost_sent_title": "Password reset email sent",
"password_lost_sent_message": "A password reset email has been sent to <strong>{{ username }}</strong> for a password reset"
} }
}, },
"security": { "security": {

View File

@ -109,5 +109,13 @@
</button> </button>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-warning" ng-click="passwordReset()" ng-show="user.username != 'guest'">
<span class="glyphicon glyphicon-repeat"></span> {{ 'settings.user.edit.password_reset_btn' | translate }}
</button>
</div>
</div>
</form> </form>
</div> </div>