Commit 0f9ec8f67735792787f8ce9d3c13ce1a8ccba498

Authored by Benjamin Renard
1 parent 2185f5f5

Add reset password module

js/app/AmdaApp.js
... ... @@ -163,7 +163,14 @@ Ext.define('amdaApp.AmdaApp', {
163 163 title : 'Astronomical Images',
164 164 source : 'amdaDesktop.AstroImagesModule',
165 165 useLauncher : false
166   - }
  166 + },
  167 + resetpwd : {
  168 + id : 'resetpwd-win',
  169 + icon : 'icon-resetpwd',
  170 + title : 'Reset Password',
  171 + source : 'amdaDesktop.ResetPwdModule',
  172 + useLauncher : false
  173 + },
167 174 },
168 175 functionList : [],
169 176 constantList : [],
... ... @@ -429,6 +436,19 @@ Ext.define('amdaApp.AmdaApp', {
429 436 },
430 437 scope : this
431 438 },
  439 + {
  440 + text : 'Reset password',
  441 + iconCls : 'icon-resetpwd',
  442 + id : 'resetpwd-win-tool',
  443 + handler : function(obj, e) {
  444 + e.stopEvent();
  445 + var moduleId = obj.el.id;
  446 + this.getLoadedModule(moduleId.replace('-tool', ''), true, function(module) {
  447 + module.createWindow();
  448 + });
  449 + },
  450 + scope : this
  451 + },
432 452 {
433 453 text : 'Feedback',
434 454 iconCls : 'icon-feedback',
... ...
js/app/controllers/ResetPwdModule.js 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +/**
  2 + * Project  : AMDA-NG
  3 + * Name : ResetPwdModule.js
  4 + * @plugin amdaDesktop.ResetPwdModule
  5 + * @extends amdaDesktop.AmdaModule
  6 + * @brief Reset password controller
  7 + * @author Benjamin
  8 + * @version $Id: ResetPwdModule.js 965 2024-09-19 16:05:30Z benjamin $
  9 + */
  10 +
  11 +Ext.define('amdaDesktop.ResetPwdModule', {
  12 +
  13 + extend: 'amdaDesktop.AmdaModule',
  14 +
  15 + requires : [
  16 + 'amdaUI.ResetPwdUI'
  17 + ],
  18 +
  19 + contentId : 'resetpwdUI',
  20 + width : 600,
  21 + height : 280,
  22 +
  23 + createWindow : function(){
  24 + var desktop = this.app.getDesktop();
  25 + var win = desktop.getWindow(this.id);
  26 +
  27 + if(!win){
  28 + win = desktop.createWindow({
  29 + id: this.id,
  30 + title:this.title,
  31 + layout: 'fit',
  32 + width: this.width,
  33 + height: this.height,
  34 + minHeight: this.height,
  35 + modal: true,
  36 + iconCls: this.icon,
  37 + animCollapse:false,
  38 + constrainHeader:true,
  39 + bodyPadding : 5,
  40 + stateful : false,
  41 + items : [{
  42 + xtype: 'panelResetPwd'
  43 + }]
  44 + });
  45 + }
  46 + win.show();
  47 + return win;
  48 + }
  49 +});
... ...
js/app/views/ResetPwdUI.js 0 → 100644
... ... @@ -0,0 +1,172 @@
  1 +/**
  2 + * Project  : AMDA-NG
  3 + * Name : ResetPwdUI.js
  4 + * @plugin amdaUI.ResetPwdUI
  5 + * @extends Ext.panel.Panel
  6 + * @brief Reset password view
  7 + * @author Benjamin
  8 + * @version $Id: ResetPwdUI.js 2031 2024-09-19 11:28:34Z benjamin $
  9 + */
  10 +
  11 +Ext.define('amdaUI.ResetPwdUI', {
  12 + extend: 'Ext.form.Panel',
  13 + alias: 'widget.panelResetPwd',
  14 +
  15 + constructor: function(config) {
  16 + this.init(config);
  17 + this.callParent(arguments);
  18 + },
  19 +
  20 + getInfoMsg : function()
  21 + {
  22 + return '' +
  23 + 'To make the change, type your current password in the appropriate box, followed by a new one, which you will then confirm.<br>'+
  24 + 'Please note that passwords are encrypted in our database and we are unable to retrieve them for you.<br>'+
  25 + 'If you have any problems, please contact the CDPP/AMDA team.';
  26 + },
  27 +
  28 + getUser : function()
  29 + {
  30 + return sessionID;
  31 + },
  32 +
  33 + onSendFinish : function(result, e){
  34 + var t = e.getTransaction();
  35 + if (e.status)
  36 + {
  37 + if (result && result.success)
  38 + {
  39 + // SUCCESS
  40 + var win = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.resetpwd.id);
  41 + Ext.MessageBox.show({
  42 + title: 'New password set successfully',
  43 + msg: 'For your next AMDA session, you will need to enter your new password',
  44 + buttons: Ext.MessageBox.OK,
  45 + icon: Ext.MessageBox.INFO,
  46 + fn: function (btn){
  47 + win.close();
  48 + }
  49 + });
  50 + return;
  51 + }
  52 +
  53 + //ERROR
  54 + var msgErr = 'Unknown error';
  55 + if (result.message)
  56 + {
  57 + msgErr = result.message;
  58 + }
  59 + Ext.Msg.show({title:'Error', msg: msgErr, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
  60 + }
  61 + else
  62 + {
  63 + // FAILURE
  64 + Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
  65 + }
  66 + },
  67 +
  68 + onResetPwd : function(b,e){
  69 + //get links to components
  70 + var fieldset = this.getComponent('resetpwd_fieldset');
  71 + var crtPwd = fieldset.getComponent('crtpwd_field');
  72 + var newPwd = fieldset.getComponent('newpwd_field');
  73 + var newPwd2 = fieldset.getComponent('newpwd2_field');
  74 +
  75 + if (!crtPwd.isValid() && !newPwd.isValid() || !newPwd2.isValid())
  76 + {
  77 + Ext.Msg.show({title:'Error', msg: 'Some field values are invalid', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
  78 + return;
  79 + }
  80 +
  81 + if (newPwd.getValue() != newPwd2.getValue()) {
  82 + Ext.Msg.show({title: 'Error', msg: 'Password does not match Confirmation', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
  83 + return;
  84 + }
  85 +
  86 + //make the object to send
  87 + var reset = {
  88 + crtpwd : crtPwd.getValue(),
  89 + newpwd : newPwd.getValue()
  90 + };
  91 +
  92 + //call action
  93 + AmdaAction.resetPwd(reset,this.onSendFinish,this);
  94 + },
  95 +
  96 +
  97 + init : function(config)
  98 + {
  99 + var myConf = {
  100 + layout: 'fit',
  101 + bodyStyle: { background: '#ddecfe'},
  102 + items : [{
  103 + xtype: 'fieldset',
  104 + itemId: 'resetpwd_fieldset',
  105 + layout: 'anchor',
  106 + anchor: '100%',
  107 + items : [
  108 + {
  109 + xtype: 'displayfield',
  110 + name: 'information',
  111 + height : 80,
  112 + fieldLabel: '',
  113 + anchor: '100%',
  114 + value: this.getInfoMsg()
  115 + },
  116 + {
  117 + xtype: 'textfield',
  118 + itemId: 'crtpwd_field',
  119 + anchor: '100%',
  120 + name: 'crtpwd',
  121 + fieldLabel: 'Current Password',
  122 + inputType: 'password',
  123 + allowBlank: false,
  124 + regex: /^[a-zA-Z0-9./]+$/,
  125 + regexText: 'Only alphanumeric, . and / characters allowed'
  126 + },
  127 + {
  128 + xtype: 'textfield',
  129 + itemId: 'newpwd_field',
  130 + anchor: '100%',
  131 + name: 'newpwd',
  132 + fieldLabel: 'New Password',
  133 + inputType: 'password',
  134 + allowBlank: false,
  135 + regex: /^[a-zA-Z0-9./]+$/,
  136 + regexText: 'Only alphanumeric, . and / characters allowed',
  137 + minLength: 4,
  138 + maxLength: 20
  139 + },
  140 + {
  141 + xtype: 'textfield',
  142 + itemId: 'newpwd2_field',
  143 + anchor: '100%',
  144 + name: 'newpwd2',
  145 + fieldLabel: 'Confirm New Password',
  146 + inputType: 'password',
  147 + allowBlank: false,
  148 + regex: /^[a-zA-Z0-9./]+$/,
  149 + regexText: 'Only alphanumeric, . and / characters allowed',
  150 + minLength: 4,
  151 + maxLength: 20
  152 + }
  153 + ]
  154 + }],
  155 + dockedItems: [{
  156 + xtype: 'toolbar',
  157 + dock: 'bottom',
  158 + items: [
  159 + '->',
  160 + {
  161 + iconCls: 'icon-resetpwd',
  162 + text: 'Reset',
  163 + scope: this,
  164 + tooltip: 'Reset password',
  165 + handler: this.onResetPwd
  166 + }
  167 + ]
  168 + }]
  169 + }
  170 + Ext.apply (this , Ext.apply (arguments, myConf));
  171 + }
  172 +});
... ...
js/resources/css/amda.css
... ... @@ -72,6 +72,8 @@
72 72  
73 73 .icon-user { background-image:url(../images/16x16/user.png) !important; }
74 74  
  75 +.icon-resetpwd { background-image:url(../images/16x16/reset_pwd.png) !important; }
  76 +
75 77 .icon-elements {
76 78 background-image:url( ../images/16x16/view_tree.png ) !important;
77 79 }
... ...
js/resources/images/16x16/reset_pwd.png 0 → 100644

494 Bytes

php/classes/AmdaAction.php
... ... @@ -1431,6 +1431,14 @@ class AmdaAction
1431 1431 return $dd->getUserInfo();
1432 1432 }
1433 1433  
  1434 + public function resetPwd($obj)
  1435 + {
  1436 + $dd = new UserMgr();
  1437 + $crt_pwd = $obj->crtpwd;
  1438 + $new_pwd = $obj->newpwd;
  1439 + return $dd->resetPwd($crt_pwd, $new_pwd);
  1440 + }
  1441 +
1434 1442 // $obj ={"Object":"Earth","RunCount":"2",
1435 1443 // "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....}
1436 1444 public function getRun($obj)
... ...
php/classes/AmdaClient.php
... ... @@ -248,6 +248,27 @@ class AmdaClient {
248 248 return $info;
249 249 }
250 250  
  251 + public function resetUserPwd($login, $crt_pwd, $new_pwd) {
  252 + try {
  253 + $data_array = array(
  254 + "login" => $login,
  255 + "crtpwd" => $crt_pwd,
  256 + "newpwd" => $new_pwd,
  257 + "timestamp" => time(),
  258 + );
  259 + $data = $this->base64url_encode(json_encode($data_array));
  260 + $check = md5($data.DDSERVICE_PUBLICKEY.DDSERVICE_PRIVATEKEY);
  261 + $result = $this->client->resetUserPwd($data,DDSERVICE_PUBLICKEY,$check);
  262 + }
  263 + catch (SoapFault $exception) {
  264 + return array('success' => false, 'message' => $exception->faultstring);
  265 + }
  266 + if (!$result) {
  267 + return array('success' => false, 'message' => "Error during password modification");
  268 + }
  269 + return array('success' => true);
  270 + }
  271 +
251 272 /* Create a new user */
252 273 public function createUser($login, $pwd, $first_name, $last_name, $email) {
253 274 $result = FALSE;
... ...
php/classes/UserMgr.php
... ... @@ -37,7 +37,7 @@ class UserMgr
37 37 function __construct($username = NULL, $password = NULL, $sessionID = NULL)
38 38 {
39 39 // if magic quotes is on, stripslashes
40   - if(get_magic_quotes_gpc()) {
  40 + if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
41 41 $in = array(&$_GET, &$_POST, &$_COOKIE);
42 42 while(list($k,$v) = each($in)) {
43 43 foreach($v as $key => $val) {
... ... @@ -129,6 +129,11 @@ class UserMgr
129 129 return $info;
130 130 }
131 131  
  132 + public function resetPwd($crt_pwd, $new_pwd)
  133 + {
  134 + return $this->amdaClient->resetUserPwd($this->user, $crt_pwd, $new_pwd);
  135 + }
  136 +
132 137 public function createDir()
133 138 {
134 139 if (!mkdir($this->userdir, 0755, true)) return false;
... ...
php/config.php
... ... @@ -215,7 +215,9 @@ $API = array(
215 215 'getDefaultValueConfigs' => array('len' => 0),
216 216 'setUserDefaultValues' => array('len' => 1),
217 217 // Parameters list
218   - 'getParametersList' => array('len' => 0)
  218 + 'getParametersList' => array('len' => 0),
  219 + // Reset user password
  220 + 'resetPwd' => array('len' => 1),
219 221  
220 222 )
221 223 )
... ...