partkeepr

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

PasswordConfiguration.js (2939B)


      1 Ext.define('PartKeepr.Components.UserPreferences.Preferences.PasswordConfiguration', {
      2     extend: 'PartKeepr.Components.Preferences.PreferenceEditor',
      3 
      4     layout: 'card',
      5 
      6     initComponent: function ()
      7     {
      8         this.oldPassword = Ext.create("Ext.form.field.Text", {
      9             inputType: "password",
     10             name: 'password',
     11             labelWidth: 150,
     12             style: 'border-bottom: 1px solid grey; padding-bottom: 10px;',
     13             width: 300,
     14             fieldLabel: i18n("Current Password")
     15         });
     16 
     17         this.newPassword = Ext.create("Ext.form.field.Text", {
     18             style: 'margin-top: 10px',
     19             inputType: "password",
     20             name: 'password',
     21             labelWidth: 150,
     22             width: 300,
     23             fieldLabel: i18n("New Password")
     24         });
     25 
     26         this.newPasswordConfirm = Ext.create("Ext.form.field.Text", {
     27             inputType: "password",
     28             name: 'password',
     29             labelWidth: 150,
     30             width: 300,
     31             validator: Ext.bind(this.validatePassword, this),
     32             fieldLabel: i18n("New Password (Confirm)")
     33         });
     34 
     35         this.items = [
     36             {
     37                 border: false,
     38                 items: [
     39                     this.oldPassword,
     40                     this.newPassword,
     41                     this.newPasswordConfirm
     42                 ]
     43             }, {
     44                 border: false,
     45                 html: i18n("You are authenticated via an external user provider, password changing is not available.")
     46             }
     47         ];
     48 
     49         this.callParent();
     50 
     51         if (PartKeepr.getApplication().getLoginManager().getUser().getProvider().get("editable") === false) {
     52             this.layout.setActiveItem(1);
     53         }
     54     },
     55     onSave: function ()
     56     {
     57         if (this.getForm().isValid()) {
     58 
     59             var user = PartKeepr.getApplication().getLoginManager().getUser();
     60 
     61             user.callPutAction("changePassword", {
     62                 "oldpassword": this.oldPassword.getValue(),
     63                 "newpassword": this.newPassword.getValue()
     64             }, Ext.bind(this.onAfterPasswordChange, this));
     65         }
     66     },
     67     onAfterPasswordChange: function (opts, success)
     68     {
     69         if (success) {
     70             Ext.MessageBox.alert(i18n("Password successfully changed"),
     71                 i18n("You need to re-login with the new password. Click OK to re-login."), this.relogin, this);
     72         }
     73     },
     74     relogin: function ()
     75     {
     76         PartKeepr.getApplication().getLoginManager().logout();
     77         PartKeepr.getApplication().getLoginManager().login();
     78     },
     79     validatePassword: function ()
     80     {
     81         if (this.newPassword.getValue() !== this.newPasswordConfirm.getValue()) {
     82             return i18n("Passwords don't match");
     83         }
     84 
     85         return true;
     86     },
     87     statics: {
     88         iconCls: 'fugue-icon ui-text-field-password-green',
     89         title: i18n('Password'),
     90         menuPath: []
     91     }
     92 });