diff --git a/js/settings/PasswdPanel.js b/js/settings/PasswdPanel.js new file mode 100644 index 0000000..2ae8615 --- /dev/null +++ b/js/settings/PasswdPanel.js @@ -0,0 +1,144 @@ +Ext.namespace('Zarafa.plugins.passwd.settings'); + +/** + * @class Zarafa.plugins.passwd.settings.PasswdPanel + * @extends Ext.form.FormPanel + * + * Panel which holds a form that will be used to change the password + */ +Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { + /** + * @property + * @type Ext.LoadMask + * Save mask that will be displayed when request has been sent to server for password change + * and waiting for the response. + */ + saveMask : undefined, + + /** + * @constructor + * @param {Object} config configuration object that needs to be used when creating this dialog + */ + constructor : function(config) + { + config = config || {}; + + Ext.applyIf(config, { + xtype : 'zarafa.passwdpanel', + labelWidth : 150, + defaults : { + width : 200 + }, + border : false, + items : [{ + xtype : 'displayfield', + name : 'username', + fieldLabel : 'User name' + }, { + xtype : 'textfield', + name : 'current_password', + fieldLabel : 'Current password', + inputType : 'password', + listeners : { + change : this.onFieldChange, + scope : this + } + }, { + xtype : 'textfield', + name : 'new_password', + fieldLabel : 'New password', + inputType : 'password', + listeners : { + change : this.onFieldChange, + scope : this + } + }, { + xtype : 'textfield', + name : 'new_password_repeat', + fieldLabel : 'Retype new password', + inputType : 'password', + listeners : { + change : this.onFieldChange, + scope : this + } + }] + }); + + this.addEvents( + /** + * @event userchange + * Fires when a field is modified in the form panel + */ + 'userchange' + ); + + Zarafa.plugins.passwd.settings.PasswdPanel.superclass.constructor.apply(this, arguments); + + this.on('afterrender', this.initialize, this); + }, + + /** + * Function will initialize this dialog with some default values and will + * also create object of {@link #saveMask}. + */ + initialize : function() + { + this.getForm().setValues({ + username : container.getUser().getUserName() + }); + + this.saveMask = new Ext.LoadMask(this.getEl(), { + msg : _('Saving please wait ...') + }) + }, + + /** + * Handler function will be called when user changes any field in the form. + * This will fire custom event on this form to indicate that settings model + * should be marked as dirty + */ + onFieldChange : function(field, newValue, oldValue) + { + this.fireEvent('userchange', this); + }, + + /** + * Function will be called when user presses apply to change password. + */ + saveChanges : function() + { + // show load mask + this.saveMask.show(); + + var data = this.getForm().getFieldValues(); + + // send request + container.getRequest().singleRequest('passwdmodule', 'save', data, new Zarafa.plugins.passwd.data.PasswdResponseHandler({ + callbackFn : this.callbackFn, + scope : this + })); + }, + + /** + * Function will be called when user presses discard button to reset + * fields. + */ + discardChanges : function() + { + // reset user changes + this.getForm().reset(); + }, + + /** + * Callback function that will be executed after response is received from server. + * @param {Boolean} success boolean to indicate response contains success/failure data. + * @param {Object} response response sent by server. + */ + callbackFn : function(success, response) + { + // hide load mask + this.saveMask.hide(); + } +}); + +Ext.reg('zarafa.passwdpanel', Zarafa.plugins.passwd.settings.PasswdPanel); \ No newline at end of file diff --git a/js/settings/SettingsPasswdCategory.js b/js/settings/SettingsPasswdCategory.js new file mode 100644 index 0000000..87f3753 --- /dev/null +++ b/js/settings/SettingsPasswdCategory.js @@ -0,0 +1,33 @@ +Ext.namespace('Zarafa.plugins.passwd.settings'); + +/** + * @class Zarafa.plugins.passwd.settings.SettingsPasswdCategory + * @extends Zarafa.settings.ui.SettingsCategory + * @xtype zarafa.settingspasswdcategory + * + * The passwd settings category that will allow users to change their passwords + */ +Zarafa.plugins.passwd.settings.SettingsPasswdCategory = Ext.extend(Zarafa.settings.ui.SettingsCategory, { + /** + * @constructor + * @param {Object} config Configuration object + */ + constructor : function(config) + { + config = config || {}; + + Ext.applyIf(config, { + title : _('Change Password'), + categoryIndex : 9997, + xtype : 'zarafa.settingspasswdcategory', + items : [{ + xtype : 'zarafa.settingspasswdwidget', + settingsContext : config.settingsContext + }] + }); + + Zarafa.plugins.passwd.settings.SettingsPasswdCategory.superclass.constructor.call(this, config); + } +}); + +Ext.reg('zarafa.settingspasswdcategory', Zarafa.plugins.passwd.settings.SettingsPasswdCategory); diff --git a/js/settings/SettingsPasswdWidget.js b/js/settings/SettingsPasswdWidget.js new file mode 100644 index 0000000..2143c45 --- /dev/null +++ b/js/settings/SettingsPasswdWidget.js @@ -0,0 +1,95 @@ +Ext.namespace('Zarafa.plugins.passwd.settings'); + +/** + * @class Zarafa.plugins.passwd.settings.SettingsPasswdWidget + * @extends Zarafa.settings.ui.SettingsWidget + * @xtype zarafa.settingspasswdwidget + * + * The {@link Zarafa.settings.ui.SettingsWidget widget} for changing password + * in the {@link Zarafa.plugins.passwd.settings.SettingsPasswdCategory password category}. + */ +Zarafa.plugins.passwd.settings.SettingsPasswdWidget = Ext.extend(Zarafa.settings.ui.SettingsWidget, { + + /** + * @constructor + * @param {Object} config Configuration object + */ + constructor : function(config) + { + config = config || {}; + + Ext.applyIf(config, { + height : 175, + width : 400, + title : _('Change Password'), + xtype : 'zarafa.settingspasswdwidget', + layout : { + // override from SettingsWidget + type : 'fit' + }, + items : [{ + xtype : 'zarafa.passwdpanel', + ref : 'passwdPanel', + listeners : { + userchange : this.setModelDirty, + scope : this + } + }] + }); + + Zarafa.plugins.passwd.settings.SettingsPasswdWidget.superclass.constructor.call(this, config); + }, + + /** + * initialize events for the {@link Zarafa.plugins.passwd.settings.SettingsPasswdWidget SettingsPasswdWidget}. + * @private + */ + initEvents : function() + { + Zarafa.plugins.passwd.settings.SettingsPasswdWidget.superclass.initEvents.call(this); + + // listen to savesettings and discardsettings to save/discard delegation data + var contextModel = this.settingsContext.getModel(); + + this.mon(contextModel, 'savesettings', this.onSaveSettings, this); + this.mon(contextModel, 'discardsettings', this.onDiscardSettings, this); + }, + + /** + * Event handler will be called when {@link Zarafa.settings.SettingsContextModel#savesettings} event is fired. + * This will relay this event to {@link Zarafa.plugins.passwd.settings.PasswdPanel PasswdPanel} so it can + * save data. + * @private + */ + onSaveSettings : function() + { + this.passwdPanel.saveChanges(); + }, + + /** + * Event handler will be called when {@link Zarafa.settings.SettingsContextModel#discardsettings} event is fired. + * This will relay this event to {@link Zarafa.plugins.passwd.settings.PasswdPanel PasswdPanel} so it can + * discard current changes. + * @private + */ + onDiscardSettings : function() + { + this.passwdPanel.discardChanges(); + }, + + /** + * Function will be called when any field in {@link Zarafa.plugins.passwd.settings.PasswdPanel} + * is changed and we need to mark settings model as dirty. + * @private + */ + setModelDirty : function() + { + var model = this.settingsContext.getModel(); + + if(!model.hasChanges()) { + model.setDirty(); + } + } +}); + +Ext.reg('zarafa.settingspasswdwidget', Zarafa.plugins.passwd.settings.SettingsPasswdWidget); diff --git a/manifest.xml b/manifest.xml index bea5081..27513cc 100644 --- a/manifest.xml +++ b/manifest.xml @@ -2,7 +2,7 @@ - 0.1 + 0.2 Passwd Password Changer Plugin Saket Patel diff --git a/php/class.passwdmodule.php b/php/class.passwdmodule.php index 4815c19..ab1f434 100644 --- a/php/class.passwdmodule.php +++ b/php/class.passwdmodule.php @@ -203,7 +203,6 @@ class PasswdModule extends Module */ public function checkPasswordStrenth($password) { - return true; // @FIXME should be moved to client side if (preg_match("#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$#", $password)) { return true; diff --git a/php/plugin.passwd.php b/php/plugin.passwd.php index bec8323..ef8fe17 100644 --- a/php/plugin.passwd.php +++ b/php/plugin.passwd.php @@ -4,7 +4,7 @@ * * Allows to change user password from webapp. * - * Author: Saket patel + * Author: Saket patel */ class Pluginpasswd extends Plugin {