Skip to content

Commit

Permalink
Fix force password change
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Feb 26, 2019
1 parent a025413 commit f307dab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 53 deletions.
3 changes: 1 addition & 2 deletions contribs/gmf/apps/desktop/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@
</ngeo-modal>
<ngeo-modal
ngeo-modal-closable="false"
ng-model="mainCtrl.userMustChangeItsPassword()"
ng-model-options="{getterSetter: true}">
ng-model="mainCtrl.userMustChangeItsPassword">
<div class="modal-header">
<h4 class="modal-title">
{{'You must change your password' | translate}}
Expand Down
3 changes: 1 addition & 2 deletions contribs/gmf/apps/mobile/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
</gmf-authentication>
</nav>
<ngeo-modal
ng-model="mainCtrl.userMustChangeItsPassword()"
ng-model-options="{getterSetter: true}">
ng-model="mainCtrl.userMustChangeItsPassword">
<div class="modal-header">
<h4 class="modal-title">
{{'You must change your password' | translate}}
Expand Down
27 changes: 2 additions & 25 deletions contribs/gmf/src/authentication/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,18 @@
type="button"
class="form-control btn btn-default"
value="{{'Cancel' | translate}}"
ng-if="!$ctrl.userMustChangeItsPassword()"
ng-if="!$ctrl.userMustChangeItsPassword"
ng-click="$ctrl.changePasswordReset()" />
<input
type="button"
class="form-control btn btn-default"
value="{{'Logout' | translate}}"
ng-if="$ctrl.userMustChangeItsPassword()"
ng-if="$ctrl.userMustChangeItsPassword"
ng-click="$ctrl.logout()" />
</div>
</form>

<div ng-show="$ctrl.error" class="gmf-authentication-error help-block"></div>

<ngeo-modal
ng-model="$ctrl.changePasswordModalShown">
<div class="modal-header">
<button type="button"
class="close"
data-dismiss="modal"
aria-label="{{'Close' | translate}}">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">
{{'Password Changed' | translate}}
</h4>
</div>
<div class="modal-body">
{{'Your password has successfully been changed.' | translate}}
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-default"
data-dismiss="modal">{{'OK' | translate}}</button>
</div>
</ngeo-modal>
</div>

<div ng-if="!$ctrl.gmfUser.username">
Expand Down
26 changes: 12 additions & 14 deletions contribs/gmf/src/authentication/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function gmfAuthenticationTemplateUrl($element, $attrs, gmfAuthenticationTemplat
*
* <ngeo-modal
* ngeo-modal-closable="false"
* ng-model="mainCtrl.userMustChangeItsPassword()"
* ng-model-options="{getterSetter: true}">
* ng-model="mainCtrl.userMustChangeItsPassword">
* <div class="modal-header">
* <h4 class="modal-title">
* {{'You must change your password' | translate}}
Expand Down Expand Up @@ -268,6 +267,7 @@ exports.AuthenticationController_ = class {
if (this.forcePasswordChange) {
this.changingPassword = true;
}
this.userMustChangeItsPassword = (this.gmfUser.is_password_changed === false && this.forcePasswordChange);
}


Expand Down Expand Up @@ -319,8 +319,11 @@ exports.AuthenticationController_ = class {
// Send request with current credentials, which may fail if the old password given is incorrect.
this.gmfAuthenticationService_.changePassword(oldPwd, newPwd, confPwd)
.then(() => {
this.changePasswordModalShown = true;
this.changePasswordReset();
this.setError_(
[gettextCatalog.getString('Your password has successfully been changed.')],
ngeoMessageMessage.Type.INFORMATION
);
})
.catch((err) => {
this.setError_(gettextCatalog.getString('Incorrect old password.'));
Expand Down Expand Up @@ -408,20 +411,15 @@ exports.AuthenticationController_ = class {
this.newPwdConfVal = '';
}

/**
* @return {boolean} True if the user must change is password and if the "forcePasswordChange" option of
* this component is set to true.
* @export
*/
userMustChangeItsPassword() {
return (this.gmfUser.is_password_changed === false && this.forcePasswordChange);
}

/**
* @param {string|Array.<string>} errors Errors.
* @param {ngeoMessageMessage.Type} [messageType] Type.
* @private
*/
setError_(errors) {
setError_(errors, messageType) {
if (messageType == undefined) {
messageType = ngeoMessageMessage.Type.ERROR;
}
if (this.error) {
this.resetError_();
}
Expand All @@ -438,7 +436,7 @@ exports.AuthenticationController_ = class {
this.notification_.notify({
msg: error,
target: container,
type: ngeoMessageMessage.Type.ERROR
type: messageType
});
}, this);
}
Expand Down
17 changes: 7 additions & 10 deletions contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ const exports = function(config, $scope, $injector) {
* @export
*/
this.gmfUser = $injector.get('gmfUser');
this.userMustChangeItsPassword = false;
$scope.$watch(
() => this.gmfUser.is_password_changed,
(value) => {
this.userMustChangeItsPassword = value === false;
}
);

/**
* @type {ngeox.miscGetBrowserLanguage}
Expand Down Expand Up @@ -622,16 +629,6 @@ const exports = function(config, $scope, $injector) {
};


/**
* @return {boolean} Return true if a user exists and its 'is_password_changed' value is explicitly set
* to false.
* @export
*/
exports.prototype.userMustChangeItsPassword = function() {
return this.gmfUser.is_password_changed === false;
};


/**
* @param {Array.<ol.layer.Base>} layers Layers list.
* @param {Array.<string>} labels default_basemap list.
Expand Down

0 comments on commit f307dab

Please sign in to comment.