ResetPwdUI.js 4.25 KB
/**
  * Project      :  AMDA-NG
  * Name         : ResetPwdUI.js
  * @plugin 	  amdaUI.ResetPwdUI
  * @extends 	  Ext.panel.Panel
  * @brief		 Reset password view
  * @author Benjamin
  * @version $Id: ResetPwdUI.js 2031 2024-09-19 11:28:34Z benjamin $      
  */

Ext.define('amdaUI.ResetPwdUI', {
	extend: 'Ext.form.Panel',
	alias: 'widget.panelResetPwd',

	constructor: function(config) {			
		this.init(config);
		this.callParent(arguments);
	},
    
	getInfoMsg : function()
	{
		return '' +
			'To make the change, type your current password in the appropriate box, followed by a new one, which you will then confirm.<br>'+
			'Please note that passwords are encrypted in our database and we are unable to retrieve them for you.<br>'+
			'If you have any problems, please contact the CDPP/AMDA team.';
	},
    
	getUser : function()
	{
		return sessionID;
	},

	onSendFinish : function(result, e){	
		var t = e.getTransaction();
		if (e.status) 
		{	
			if (result && result.success)
			{
				// SUCCESS  
				var win = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.resetpwd.id);
				Ext.MessageBox.show({
					title: 'New password set successfully',
					msg: 'For your next AMDA session, you will need to enter your new password',
					buttons: Ext.MessageBox.OK,
					icon: Ext.MessageBox.INFO,
					fn: function (btn){
						win.close();
					}
				});
				return;
			}

			//ERROR
			var msgErr = 'Unknown error';
			if (result.message)
			{
				msgErr = result.message;
			}
			Ext.Msg.show({title:'Error', msg: msgErr, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
		}
		else
		{
			// FAILURE
			Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
		}   
	},
    
	onResetPwd : function(b,e){
		//get links to components
		var fieldset = this.getComponent('resetpwd_fieldset');
		var crtPwd = fieldset.getComponent('crtpwd_field');
		var newPwd = fieldset.getComponent('newpwd_field');
		var newPwd2 = fieldset.getComponent('newpwd2_field');

		if (!crtPwd.isValid() && !newPwd.isValid() || !newPwd2.isValid())
		{
			Ext.Msg.show({title:'Error', msg: 'Some field values are invalid', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
			return;
		}

		if (newPwd.getValue() != newPwd2.getValue()) {
			Ext.Msg.show({title: 'Error', msg: 'Password does not match Confirmation', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
			return;
		}

		//make the object to send
		var reset = {
			crtpwd : crtPwd.getValue(), 
			newpwd : newPwd.getValue()
		};
		
		//call action
		AmdaAction.resetPwd(reset,this.onSendFinish,this);
	},
    
	
	init : function(config)	
	{
		var myConf = {
			layout: 'fit',
			bodyStyle: { background: '#ddecfe'},
			items : [{
				xtype: 'fieldset',
				itemId: 'resetpwd_fieldset',
				layout: 'anchor',
				anchor: '100%',
				items : [
					{
						xtype: 'displayfield',
						name: 'information',
						height : 80,
						fieldLabel: '',
						anchor: '100%',
						value: this.getInfoMsg()
					},
					{
						xtype: 'textfield',
						itemId: 'crtpwd_field',
						anchor: '100%',
						name: 'crtpwd',
						fieldLabel: 'Current Password',
						inputType: 'password',
						allowBlank: false,
						regex: /^[a-zA-Z0-9./]+$/,
						regexText: 'Only alphanumeric, . and / characters allowed'
					},
					{
						xtype: 'textfield',
						itemId: 'newpwd_field',
						anchor: '100%',
						name: 'newpwd',
						fieldLabel: 'New Password',
						inputType: 'password',
						allowBlank: false,
						regex: /^[a-zA-Z0-9./]+$/,
						regexText: 'Only alphanumeric, . and / characters allowed',
						minLength: 4,
						maxLength: 20
					},
					{
						xtype: 'textfield',
						itemId: 'newpwd2_field',
						anchor: '100%',
						name: 'newpwd2',
						fieldLabel: 'Confirm New Password',
						inputType: 'password',
						allowBlank: false,
						regex: /^[a-zA-Z0-9./]+$/,
						regexText: 'Only alphanumeric, . and / characters allowed',
						minLength: 4,
						maxLength: 20
					}
				]
			}],
			dockedItems: [{
				xtype: 'toolbar', 
				dock: 'bottom',
				items: [
					'->',
					{
						iconCls: 'icon-resetpwd',
						text: 'Reset',
						scope: this,
						tooltip: 'Reset password',
						handler: this.onResetPwd
					}					
				]	          
			}]
		}
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});