partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit e4da8bd0be4421e606a7bd6f6e6b3cd286f28d08
parent 22af0258cde07295cf76bfa77723ed1a904c8858
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 12 Oct 2015 19:00:11 +0200

Only allow password changing if the internal provider is used

Diffstat:
Msrc/PartKeepr/AuthBundle/Action/ChangePasswordAction.php | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Auth/AuthenticationProvider.js | 7++-----
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/User/Preferences/UserPasswordChangePanel.js | 54++++++++++++++++++++++++++++++++++++------------------
3 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/src/PartKeepr/AuthBundle/Action/ChangePasswordAction.php b/src/PartKeepr/AuthBundle/Action/ChangePasswordAction.php @@ -68,7 +68,7 @@ class ChangePasswordAction $encoded_pass = $encoder->encodePassword($request->request->get("oldpassword"), $FOSUser->getSalt()); if ($FOSUser->getPassword() != $encoded_pass) { - throw new \Exception("Passwords don't match"); + throw new \Exception("Old password is wrong"); } $this->userManipulator->changePassword($user->getUsername(), $request->request->get("newpassword")); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Auth/AuthenticationProvider.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Auth/AuthenticationProvider.js @@ -119,11 +119,8 @@ Ext.define('PartKeepr.Auth.AuthenticationProvider', { if (response.status == "401") { this.fireEvent("authenticate", false); } else { - var user = Ext.create("PartKeepr.AuthBundle.Entity.User", - Ext.decode(response.responseText) - ); - - this.setUser(user); + var records = PartKeepr.AuthBundle.Entity.User.getProxy().getReader().read(response); + this.setUser(records.getRecords()[0]); this.fireEvent("authenticate", true); } }, diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/User/Preferences/UserPasswordChangePanel.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/User/Preferences/UserPasswordChangePanel.js @@ -2,6 +2,7 @@ Ext.define('PartKeepr.UserPasswordChangePanel', { extend: 'Ext.form.FormPanel', title: i18n("Change Password"), bodyStyle: 'background:#DBDBDB;padding: 10px;', + layout: 'card', initComponent: function () { @@ -33,26 +34,38 @@ Ext.define('PartKeepr.UserPasswordChangePanel', { }); this.items = [ - this.oldPassword, - this.newPassword, - this.newPasswordConfirm, { - xtype: 'fieldcontainer', - hideEmptyLabel: false, - width: 300, - labelWidth: 150, - items: { - xtype: 'button', - handler: this.onChangePassword, - scope: this, - width: 145, - iconCls: 'web-icon accept', - text: i18n("Change Password") - } + border: false, + bodyStyle: 'background:#DBDBDB;padding: 10px;', + items: [ + this.oldPassword, + this.newPassword, + this.newPasswordConfirm, + { + xtype: 'fieldcontainer', + hideEmptyLabel: false, + width: 300, + labelWidth: 150, + items: { + xtype: 'button', + handler: this.onChangePassword, + scope: this, + width: 145, + iconCls: 'web-icon accept', + text: i18n("Change Password") + }}] + },{ + border: false, + bodyStyle: 'background:#DBDBDB;padding: 10px;', + html: i18n("You are authenticated via an external user provider, password changing is not available.") } ]; this.callParent(); + + if (PartKeepr.getApplication().getLoginManager().getUser().getProvider().get("editable") === false) { + this.layout.setActiveItem(1); + } }, onChangePassword: function () { @@ -64,12 +77,17 @@ Ext.define('PartKeepr.UserPasswordChangePanel', { "oldpassword": this.oldPassword.getValue(), "newpassword": this.newPassword.getValue() }, Ext.bind(this.onAfterPasswordChange, this)); - // @TODO Logout the user after succesful password change } }, - onAfterPasswordChange: function (data) + onAfterPasswordChange: function (opts, success, response) { - Ext.Msg.alert(data); + if (success) { + Ext.MessageBox.alert(i18n("Password successfully changed"), i18n("You need to re-login with the new password. Click OK to re-login."), this.relogin, this); + } + }, + relogin: function () { + PartKeepr.getApplication().getLoginManager().logout(); + PartKeepr.getApplication().getLoginManager().login(); }, validatePassword: function () {