diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-06-25 10:28:18 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-06-25 16:03:41 +0200 |
commit | 5084395b0360e760fac3d8c128f6852a5ba707e6 (patch) | |
tree | 964036953ee2bad5cf5849776f4983e908af8483 /server/sonar-web/src/main/js/apps/account | |
parent | ba0948cc74731af55f25fda950913e8d68c97c0a (diff) | |
download | sonarqube-5084395b0360e760fac3d8c128f6852a5ba707e6.tar.gz sonarqube-5084395b0360e760fac3d8c128f6852a5ba707e6.zip |
SONAR-6507 use ws to change password
Diffstat (limited to 'server/sonar-web/src/main/js/apps/account')
3 files changed, 86 insertions, 1 deletions
diff --git a/server/sonar-web/src/main/js/apps/account/app.js b/server/sonar-web/src/main/js/apps/account/app.js index 2d7421e24c6..7559a916e48 100644 --- a/server/sonar-web/src/main/js/apps/account/app.js +++ b/server/sonar-web/src/main/js/apps/account/app.js @@ -1,4 +1,6 @@ -define(function () { +define([ + './change-password-view' +], function (ChangePasswordView) { var $ = jQuery; var shouldShowAvatars = window.SS && window.SS.lf && window.SS.lf.enableGravatar; @@ -22,6 +24,11 @@ define(function () { $(e.currentTarget).hide(); showExtraFavorites(); }); + + $('#account-change-password-trigger').on('click', function (e) { + e.preventDefault(); + new ChangePasswordView().render(); + }); } }; diff --git a/server/sonar-web/src/main/js/apps/account/change-password-view.js b/server/sonar-web/src/main/js/apps/account/change-password-view.js new file mode 100644 index 00000000000..86522a8dc40 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/account/change-password-view.js @@ -0,0 +1,52 @@ +define([ + 'components/common/modal-form', + './templates' +], function (ModalForm) { + + var $ = jQuery; + + return ModalForm.extend({ + template: Templates['account-change-password'], + + onFormSubmit: function (e) { + this._super(e); + if (this.checkPasswords()) { + this.sendRequest(); + } else { + this.showErrors([{ msg: t('user.password_doesnt_match_confirmation') }]); + } + }, + + checkPasswords: function () { + var p1 = this.$('#password').val(), + p2 = this.$('#password_confirmation').val(); + return p1 === p2; + }, + + sendRequest: function () { + var that = this; + var data = { + login: window.SS.user, + password: this.$('#password').val(), + previousPassword: this.$('#old_password').val() + }; + var opts = { + type: 'POST', + url: baseUrl + '/api/users/change_password', + data: data, + statusCode: { + // do not show global error + 400: null + } + }; + this.disableForm(); + $.ajax(opts).done(function () { + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/account/templates/account-change-password.hbs b/server/sonar-web/src/main/js/apps/account/templates/account-change-password.hbs new file mode 100644 index 00000000000..8cfe6bde02f --- /dev/null +++ b/server/sonar-web/src/main/js/apps/account/templates/account-change-password.hbs @@ -0,0 +1,26 @@ +<form id="pass_form_tag" name="pass_form_tag"> + <div class="modal-head"> + <h2>{{t 'my_profile.password.title'}}</h2> + </div> + + <div class="modal-body"> + <div class="js-modal-messages"></div> + <div class="modal-field"> + <label for="old_password">{{t 'my_profile.password.old'}}<em class="mandatory">*</em></label> + <input autocomplete="off" id="old_password" name="old_password" required type="password"> + </div> + <div class="modal-field"> + <label for="password">{{t 'my_profile.password.new'}}<em class="mandatory">*</em></label> + <input autocomplete="off" id="password" name="password" required type="password"> + </div> + <div class="modal-field"> + <label for="password_confirmation">{{t 'my_profile.password.confirm'}}<em class="mandatory">*</em></label> + <input autocomplete="off" id="password_confirmation" name="password_confirmation" required type="password"> + </div> + </div> + + <div class="modal-foot"> + <input name="commit" type="submit" value="{{t 'my_profile.password.submit'}}"> + <a class="js-modal-close" href="#">{{t 'cancel'}}</a> + </div> +</form> |