PHP8
[Pman.BAdmin] / Pman.Dialog.BAdminPassword.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.BAdminPassword= function() {}
8 Roo.apply(Pman.Dialog.BAdminPassword.prototype, {
9
10  _strings : {
11   '9182ecb4943f2724adde82c820702555' :"Retype New Password",
12   '8f1e77e0d2be21da93cd4d9a939148f7' :"Change Password",
13   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
14   'ae3bb2a1ac61750150b606298091d38a' :"New Password",
15   '51eea3dc60ae3a0b1bb8188bc6337dc2' :"enter password",
16   'bb78dd7992509064b8044b7afe6ec9ed' :"Update Password",
17   '828e70f83623b262e14187c039df99c0' :"Enable Two-Factor Authentication"
18  },
19  _named_strings : {
20   'changePassword_placeholder' : '51eea3dc60ae3a0b1bb8188bc6337dc2' /* enter password */ ,
21   'passwd2_fieldLabel' : '9182ecb4943f2724adde82c820702555' /* Retype New Password */ ,
22   'passwd1_fieldLabel' : 'ae3bb2a1ac61750150b606298091d38a' /* New Password */ ,
23   '_enable_oath_key_boxLabel' : '828e70f83623b262e14187c039df99c0' /* Enable Two-Factor Authentication */ 
24  },
25
26  dialog : false,
27  callback:  false,
28
29  show : function(data, cb)
30  {
31   if (!this.dialog) {
32    this.create();
33   }
34
35   this.callback = cb;
36   this.data = data;
37   this.dialog.show(this.data._el);
38   if (this.form) {
39    this.form.reset();
40    this.form.setValues(data);
41    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
42   }
43
44  },
45
46  create : function()
47  {
48   var _this = this;
49   this.dialog = Roo.factory({
50     xtype : 'Modal',
51     cls : 'enable-overflow',
52     title : _this._strings['8f1e77e0d2be21da93cd4d9a939148f7'] /* Change Password */,
53     xns : Roo.bootstrap,
54     '|xns' : 'Roo.bootstrap',
55     buttons : [
56      {
57       xtype : 'Button',
58       html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
59       listeners : {
60        click : function (_self, e)
61         {
62             _this.dialog.hide({});
63         },
64        render : function (_self)
65         {
66             _this.cancel_btn = this;
67         }
68       },
69       xns : Roo.bootstrap,
70       '|xns' : 'Roo.bootstrap'
71      },
72      {
73       xtype : 'Button',
74       changeStatus : function(status)
75       {
76           switch(status) {
77               
78               case 'submit':
79                   this.disable();
80                   this.setText('sending...');
81                   break;
82                   
83               case 'loaded':
84                   this.enable();
85                   this.setText('OK');
86                   break;
87               
88               default:
89                   break;
90           }
91       },
92       html : _this._strings['bb78dd7992509064b8044b7afe6ec9ed'] /* Update Password */,
93       weight : 'primary',
94       listeners : {
95        click : function (_self, e)
96         {
97             var p1 = _this.form.findField('passwd1').getValue();
98             var p2 = _this.form.findField('passwd2').getValue();
99             
100             if(
101                 !p1.length ||
102                 !p2.length ||
103                 p1 !== p2
104             ) {
105                 Roo.bootstrap.MessageBox.alert("Error", "Passwords do not match");
106                 return;
107             }
108             
109             _this.form.findField('changePassword').setValue(1);
110             
111             this.changeStatus('submit');
112             
113             _this.form.doAction('submit');
114         },
115        render : function (_self)
116         {
117             _this.submit_button = this;
118         }
119       },
120       xns : Roo.bootstrap,
121       '|xns' : 'Roo.bootstrap'
122      }
123     ],
124     items  : [
125      {
126       xtype : 'Container',
127       style : 'width: 100%',
128       xns : Roo.bootstrap,
129       '|xns' : 'Roo.bootstrap',
130       items  : [
131        {
132         xtype : 'Form',
133         method : 'POST',
134         url : baseURL+'/Login',
135         listeners : {
136          actioncomplete : function (_self, action)
137           {
138               if(action.type == 'setdata'){
139                   
140                   _this.form.reset();
141                   
142                   _this.form.clearInvalid();
143                   
144                   _this.form.findField('_enable_oath_key').setChecked(false,false);
145                  
146                   new Pman.Request({
147                       url: baseURL + '/Login.php',
148                       method: 'POST',
149                       params: {
150                           getAuthUser: true
151                       }, 
152                       success: function(res) {
153                           
154                           if(res.data.oath_key_enable) {
155                               _this.form.findField('_enable_oath_key').setChecked(true,false);
156                           }
157                       }
158                   });
159               }
160               
161               if (action.type == 'load') {
162                   
163                   Roo.log('invalid usage');
164               }
165               
166               if (action.type =='submit') {
167                   
168                   if (_this.callback) {
169                       _this.callback.call(_this, action.result);
170                   }
171                   
172                   _this.form.reset();
173                   
174                   _this.submit_button.changeStatus('loaded');
175                   
176                   _this.dialog.hide({});
177                   
178                   return;
179               }
180           },
181          actionfailed : function (_self, action)
182           {
183               if (action.type =='submit') {
184                   
185                   _this.submit_button.changeStatus('loaded');
186                   
187                   if (_this.callback) {
188                       _this.callback.call(_this, action.result);
189                   }
190               }
191           },
192          render : function (_self)
193           {
194               _this.form = this;
195           }
196         },
197         xns : Roo.bootstrap,
198         '|xns' : 'Roo.bootstrap',
199         items  : [
200          {
201           xtype : 'Row',
202           xns : Roo.bootstrap,
203           '|xns' : 'Roo.bootstrap',
204           items  : [
205            {
206             xtype : 'Column',
207             xs : 12,
208             xns : Roo.bootstrap,
209             '|xns' : 'Roo.bootstrap',
210             items  : [
211              {
212               xtype : 'Input',
213               allowBlank : false,
214               fieldLabel : _this._strings['ae3bb2a1ac61750150b606298091d38a'] /* New Password */,
215               inputType : 'password',
216               labelAlign : 'top',
217               name : 'passwd1',
218               listeners : {
219                change : function (_self, newValue, oldValue)
220                 {
221                     _this.form.findField('passwd2').markInvalid();
222                 }
223               },
224               xns : Roo.bootstrap,
225               '|xns' : 'Roo.bootstrap'
226              },
227              {
228               xtype : 'Input',
229               allowBlank : false,
230               fieldLabel : _this._strings['9182ecb4943f2724adde82c820702555'] /* Retype New Password */,
231               inputType : 'password',
232               labelAlign : 'top',
233               name : 'passwd2',
234               listeners : {
235                valid : function (_self)
236                 {
237                     if (_this.form.findField('passwd1').getValue() !== _this.form.findField('passwd2').getValue()){
238                         _this.form.findField('passwd2').markInvalid();
239                     }
240                 }
241               },
242               xns : Roo.bootstrap,
243               '|xns' : 'Roo.bootstrap'
244              },
245              {
246               xtype : 'Input',
247               allowBlank : false,
248               inputType : 'hidden',
249               labelAlign : 'top',
250               name : 'changePassword',
251               placeholder : _this._strings['51eea3dc60ae3a0b1bb8188bc6337dc2'] /* enter password */,
252               xns : Roo.bootstrap,
253               '|xns' : 'Roo.bootstrap'
254              },
255              {
256               xtype : 'CheckBox',
257               boxLabel : _this._strings['828e70f83623b262e14187c039df99c0'] /* Enable Two-Factor Authentication */,
258               checked : false,
259               name : '_enable_oath_key',
260               listeners : {
261                check : function (_self, checked)
262                 {
263                     if(checked) {
264                         this.setBoxLabel('Untick to disable Two Factor authentication');
265                         return;
266                     }
267                     
268                     this.setBoxLabel('Enable Two Factor Authentication');
269                 },
270                click : function (_self, e)
271                 {
272                     if(!Pman.Login.authUser) {
273                         Roo.bootstrap.MessageBox.alert('Error', 'Please login again');
274                         return;
275                     }
276                     
277                     e.preventDefault();
278                     
279                     if(!this.checked) {
280                         Pman.Dialog.BAdminStaffTwoFactorQRCode.show({
281                             id: Pman.Login.authUser.id,
282                             allow_close: false,
283                             allow_cancel : true
284                         }, function(valid){
285                                 if(valid) {
286                                     _this.dialog.hide({});
287                                     return;
288                                 }
289                                 
290                                 _this.form.findField('_enable_oath_key').setChecked(false,false);
291                             }
292                         );
293                         return;
294                     }
295                     
296                     new Pman.Request({
297                         url : baseURL + '/Roo/Core_person',
298                         method :'GET',
299                         params : {
300                             oath_key_disable: 1,
301                             id: Pman.Login.authUser.id
302                         },
303                         
304                         success : function(res)
305                         {
306                             switch(res.data) {
307                                 case 'DONE':
308                                     Roo.bootstrap.MessageBox.alert('Success', 'The two factor authentication has been disabled');
309                                     break;
310                                 default:
311                                     Roo.log('invalid usage');
312                                     break;
313                             }
314                         },
315                         
316                         failure : function(res)
317                         {
318                             Roo.bootstrap.MessageBox.alert('Error', res);
319                         }
320                     });
321                 }
322               },
323               xns : Roo.bootstrap,
324               '|xns' : 'Roo.bootstrap'
325              }
326             ]
327            }
328           ]
329          }
330         ]
331        }
332       ]
333      }
334     ]
335    }  );
336  }
337 });
338 Roo.apply(Pman.Dialog.BAdminPassword, Pman.Dialog.BAdminPassword.prototype);