Remove password field for user email change

This commit is contained in:
Johannes Zellner
2016-02-25 14:34:16 +01:00
parent f600ebcf19
commit d3b8bd1314
2 changed files with 28 additions and 41 deletions

View File

@@ -53,25 +53,16 @@
</div>
<div class="modal-body">
<form name="emailchange_form" role="form" novalidate ng-submit="doChangeEmail(emailchange_form)" autocomplete="off">
<fieldset>
<div class="form-group" ng-class="{ 'has-error': (emailchange_form.email.$dirty && emailchange_form.email.$invalid) }">
<label class="control-label" for="inputEmailChangeEmail">New Email Address</label>
<div class="control-label" ng-show="(!emailchange_form.email.$dirty && emailchange.error.email) || (emailchange_form.email.$dirty && emailchange_form.email.$invalid)">
<small ng-show="emailchange_form.email.$error.required">A valid email address is required</small>
<small ng-show="(emailchange_form.email.$dirty && emailchange_form.email.$invalid) && !emailchange_form.email.$error.required">The Email address is not valid</small>
</div>
<input type="email" class="form-control" ng-model="emailchange.email" id="inputEmailChangeEmail" name="email" required autofocus>
<input type="password" style="display: none;">
<div class="form-group" ng-class="{ 'has-error': (emailchange_form.email.$dirty && emailchange_form.email.$invalid) }">
<label class="control-label" for="inputEmailChangeEmail">New Email Address</label>
<div class="control-label" ng-show="(!emailchange_form.email.$dirty && emailchange.error.email) || (emailchange_form.email.$dirty && emailchange_form.email.$invalid)">
<small ng-show="emailchange_form.email.$error.required">A valid email address is required</small>
<small ng-show="(emailchange_form.email.$dirty && emailchange_form.email.$invalid) && !emailchange_form.email.$error.required">The Email address is not valid</small>
</div>
<div class="form-group" ng-class="{ 'has-error': (emailchange_form.password.$dirty && emailchange_form.password.$invalid) || (!emailchange_form.password.$dirty && emailchange.error.password) }">
<label class="control-label" for="inputEmailChangePassword">Password</label>
<div class="control-label" ng-show="(emailchange_form.password.$dirty && emailchange_form.password.$invalid) || (!emailchange_form.password.$dirty && emailchange.error.password)">
<small ng-show=" emailchange_form.password.$dirty && emailchange_form.password.$invalid">Password required</small>
<small ng-show="!emailchange_form.password.$dirty && emailchange.error.password">Wrong password</small>
</div>
<input type="password" class="form-control" ng-model="emailchange.password" id="inputEmailChangePassword" name="password" required autofocus>
</div>
<input class="ng-hide" type="submit" ng-disabled="emailchange_form.$invalid"/>
</fieldset>
<input type="email" class="form-control" ng-model="emailchange.email" id="inputEmailChangeEmail" name="email" required autofocus>
</div>
<input class="ng-hide" type="submit" ng-disabled="emailchange_form.$invalid"/>
</form>
</div>
<div class="modal-footer">

View File

@@ -18,8 +18,7 @@ angular.module('Application').controller('AccountController', ['$scope', '$locat
$scope.emailchange = {
busy: false,
error: {},
email: '',
password: ''
email: ''
};
function passwordChangeReset (form) {
@@ -36,11 +35,10 @@ angular.module('Application').controller('AccountController', ['$scope', '$locat
}
}
function emailChangeReset (form) {
function emailChangeReset(form) {
$scope.emailchange.busy = false;
$scope.emailchange.error.email = null;
$scope.emailchange.error.password = null;
$scope.emailchange.email = '';
$scope.emailchange.password = '';
if (form) {
form.$setPristine();
@@ -83,29 +81,27 @@ angular.module('Application').controller('AccountController', ['$scope', '$locat
$scope.doChangeEmail = function (form) {
$scope.emailchange.error.email = null;
$scope.emailchange.error.password = null;
$scope.emailchange.busy = true;
Client.changeEmail($scope.emailchange.email, $scope.emailchange.password, function (error) {
var user = {
id: $scope.user.id,
email: $scope.emailchange.email
};
Client.updateUser(user, function (error) {
$scope.emailchange.busy = false;
if (error) {
if (error.statusCode === 403) {
$scope.emailchange.error.password = true;
$scope.emailchange.password = '';
$scope.emailchange_form.password.$setPristine();
$('#inputEmailChangePassword').focus();
} else {
console.error('Unable to change email.', error);
}
} else {
emailChangeReset(form);
// update user info in the background
Client.refreshUserInfo();
$('#emailChangeModal').modal('hide');
console.error('Unable to change email.', error);
return;
}
$scope.emailchange.busy = false;
emailChangeReset(form);
// update user info in the background
Client.refreshUserInfo();
$('#emailChangeModal').modal('hide');
});
};