Pman.Dialog.BAdminStaffTwoFactorQRCode.bjs
[Pman.BAdmin] / Pman.Dialog.BAdminStaffTwoFactorQRCode.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.BAdminStaffTwoFactorQRCode= function() {}
8 Roo.apply(Pman.Dialog.BAdminStaffTwoFactorQRCode.prototype, {
9
10  _strings : {
11   'dc7b0c7f9d3941532bda06cd58eec7bd' :"<ol class='qr-list' start=\"1\">\n    <li>Open Google Authenticator in your phone, and scan this QR code.</li>\n</ol>",
12   '2194867d6c27ce97cd1f0a5db8d5c95e' :"Setup 2-Factor Authentication",
13   '5d412a3d8de0189df31c8f331e2e6630' :"<ol class='qr-list' start=\"2\">\n    <li>After adding this to Google Authenticator, type in the generated number below to confirm.</li>\n</ol>",
14   '131e3875e777f6c9a8e510f96a4d20d2' :"Skip for now",
15   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
16   'ee468f72ab7fe4937fb014d6fcea540b' :"Enter Two factor Authentication code",
17   '70d9be9b139893aa6c69b5e77e614311' :"Confirm"
18  },
19  _named_strings : {
20   'two_factor_auth_code_fieldLabel' : 'ee468f72ab7fe4937fb014d6fcea540b' /* Enter Two factor Authentication code */ 
21  },
22
23  dialog : false,
24  callback:  false,
25
26  show : function(data, cb)
27  {
28   if (!this.dialog) {
29    this.create();
30   }
31
32   this.callback = cb;
33   this.data = data;
34   this.dialog.show(this.data._el);
35   if (this.form) {
36    this.form.reset();
37    this.form.setValues(data);
38    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
39   }
40
41  },
42
43  create : function()
44  {
45   var _this = this;
46   this.dialog = Roo.factory({
47     xtype : 'Modal',
48     allow_close : true,
49     animate : false,
50     cls : 'enable-overflow coba-qr-dialog',
51     title : _this._strings['2194867d6c27ce97cd1f0a5db8d5c95e'] /* Setup 2-Factor Authentication */,
52     listeners : {
53      hide : function (_self)
54       {
55           if(_this.callback){
56               _this.callback.call(_this, false);
57           }
58           
59       },
60      show : function (_self)
61       {
62           if(!Pman.Login.authUser) {
63               Roo.bootstrap.MessageBox.alert('Error', 'Please login again');
64               return;
65           }
66           
67           if(
68               !_this.data.id ||
69               _this.data.id.length == 0
70           ) {
71               Roo.bootstrap.MessageBox.alert('Error', 'Please select a person again');
72               return;
73           }
74           
75           _this.dialog.closeEl.hide();
76           _this.skipBtn.hide();
77           _this.cancelBtn.hide();
78           
79           if(_this.data.allow_close) {
80               _this.dialog.closeEl.show();
81               _this.skipBtn.show();
82           }
83           
84           if(_this.data.allow_cancel) {
85               _this.cancelBtn.show();
86           }
87           
88           new Pman.Request({
89               url: baseURL + '/Roo/Core_person.php',
90               method : 'GET',
91               mask : 'Loading...',
92               params : {
93                   _to_qr_code : 1,
94                   id: _this.data.id
95               },
96               
97               success : function(res) {
98                   _this.qrcode_image.setSrc(res.data.image);
99                   _this.secret.setValue(res.data.secret);
100               },
101               
102               failure : function(res) {
103                   Roo.log(res);
104               }
105           });
106       }
107     },
108     xns : Roo.bootstrap,
109     '|xns' : 'Roo.bootstrap',
110     buttons : [
111      {
112       xtype : 'Button',
113       html : _this._strings['131e3875e777f6c9a8e510f96a4d20d2'] /* Skip for now */,
114       weight : 'default',
115       listeners : {
116        click : function (_self, e)
117         {
118             _this.dialog.hide();
119             
120             return;
121         },
122        render : function (_self)
123         {
124             _this.skipBtn = this;
125         }
126       },
127       xns : Roo.bootstrap,
128       '|xns' : 'Roo.bootstrap'
129      },
130      {
131       xtype : 'Button',
132       html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
133       weight : 'default',
134       listeners : {
135        click : function (_self, e)
136         {
137             _this.dialog.hide();
138             
139             return;
140         },
141        render : function (_self)
142         {
143             _this.cancelBtn = this;
144         }
145       },
146       xns : Roo.bootstrap,
147       '|xns' : 'Roo.bootstrap'
148      },
149      {
150       xtype : 'Button',
151       html : _this._strings['70d9be9b139893aa6c69b5e77e614311'] /* Confirm */,
152       weight : 'primary',
153       listeners : {
154        click : function (_self, e)
155         {
156             _this.form.doAction('submit');
157         }
158       },
159       xns : Roo.bootstrap,
160       '|xns' : 'Roo.bootstrap'
161      }
162     ],
163     items  : [
164      {
165       xtype : 'Row',
166       xns : Roo.bootstrap,
167       '|xns' : 'Roo.bootstrap',
168       items  : [
169        {
170         xtype : 'Column',
171         xs : 12,
172         xns : Roo.bootstrap,
173         '|xns' : 'Roo.bootstrap',
174         items  : [
175          {
176           xtype : 'Row',
177           xns : Roo.bootstrap,
178           '|xns' : 'Roo.bootstrap',
179           items  : [
180            {
181             xtype : 'Column',
182             xs : 12,
183             xns : Roo.bootstrap,
184             '|xns' : 'Roo.bootstrap',
185             items  : [
186              {
187               xtype : 'Container',
188               html : _this._strings['dc7b0c7f9d3941532bda06cd58eec7bd'] /* 
189               <ol class='qr-list' start="1">              
190     <li>Open Google Authenticator in your phone, and scan this QR code.</li>              
191 </ol>
192               */ ,
193               well : 'sm',
194               xns : Roo.bootstrap,
195               '|xns' : 'Roo.bootstrap'
196              }
197             ]
198            }
199           ]
200          },
201          {
202           xtype : 'Row',
203           xns : Roo.bootstrap,
204           '|xns' : 'Roo.bootstrap',
205           items  : [
206            {
207             xtype : 'Column',
208             cls : 'text-center',
209             xs : 12,
210             xns : Roo.bootstrap,
211             '|xns' : 'Roo.bootstrap',
212             items  : [
213              {
214               xtype : 'Img',
215               cls : 'qr-code',
216               imgResponsive : false,
217               src : 'about:blank',
218               listeners : {
219                render : function (_self)
220                 {
221                     _this.qrcode_image = this;
222                     
223                     this.el.setVisibilityMode(Roo.Element.DISPLAY);
224                     
225                 }
226               },
227               xns : Roo.bootstrap,
228               '|xns' : 'Roo.bootstrap'
229              }
230             ]
231            }
232           ]
233          },
234          {
235           xtype : 'Row',
236           xns : Roo.bootstrap,
237           '|xns' : 'Roo.bootstrap',
238           items  : [
239            {
240             xtype : 'Column',
241             xs : 12,
242             xns : Roo.bootstrap,
243             '|xns' : 'Roo.bootstrap',
244             items  : [
245              {
246               xtype : 'Container',
247               html : _this._strings['5d412a3d8de0189df31c8f331e2e6630'] /* 
248               <ol class='qr-list' start="2">              
249     <li>After adding this to Google Authenticator, type in the generated number below to confirm.</li>              
250 </ol>
251               */ ,
252               well : 'sm',
253               xns : Roo.bootstrap,
254               '|xns' : 'Roo.bootstrap'
255              }
256             ]
257            }
258           ]
259          }
260         ]
261        }
262       ]
263      },
264      {
265       xtype : 'Row',
266       xns : Roo.bootstrap,
267       '|xns' : 'Roo.bootstrap',
268       items  : [
269        {
270         xtype : 'Column',
271         xs : 12,
272         xns : Roo.bootstrap,
273         '|xns' : 'Roo.bootstrap',
274         items  : [
275          {
276           xtype : 'Row',
277           xns : Roo.bootstrap,
278           '|xns' : 'Roo.bootstrap',
279           items  : [
280            {
281             xtype : 'Column',
282             xs : 12,
283             xns : Roo.bootstrap,
284             '|xns' : 'Roo.bootstrap',
285             items  : [
286              {
287               xtype : 'Container',
288               html : _this._strings['dc7b0c7f9d3941532bda06cd58eec7bd'] /* 
289               <ol class='qr-list' start="1">              
290     <li>Open Google Authenticator in your phone, and scan this QR code.</li>              
291 </ol>
292               */ ,
293               well : 'sm',
294               xns : Roo.bootstrap,
295               '|xns' : 'Roo.bootstrap'
296              }
297             ]
298            }
299           ]
300          },
301          {
302           xtype : 'Row',
303           xns : Roo.bootstrap,
304           '|xns' : 'Roo.bootstrap',
305           items  : [
306            {
307             xtype : 'Column',
308             cls : 'text-center',
309             xs : 12,
310             xns : Roo.bootstrap,
311             '|xns' : 'Roo.bootstrap',
312             items  : [
313              {
314               xtype : 'Img',
315               cls : 'qr-code',
316               imgResponsive : false,
317               src : 'about:blank',
318               listeners : {
319                render : function (_self)
320                 {
321                     _this.qrcode_image = this;
322                     
323                     this.el.setVisibilityMode(Roo.Element.DISPLAY);
324                     
325                 }
326               },
327               xns : Roo.bootstrap,
328               '|xns' : 'Roo.bootstrap'
329              }
330             ]
331            }
332           ]
333          },
334          {
335           xtype : 'Row',
336           xns : Roo.bootstrap,
337           '|xns' : 'Roo.bootstrap',
338           items  : [
339            {
340             xtype : 'Column',
341             xs : 12,
342             xns : Roo.bootstrap,
343             '|xns' : 'Roo.bootstrap',
344             items  : [
345              {
346               xtype : 'Container',
347               html : _this._strings['5d412a3d8de0189df31c8f331e2e6630'] /* 
348               <ol class='qr-list' start="2">              
349     <li>After adding this to Google Authenticator, type in the generated number below to confirm.</li>              
350 </ol>
351               */ ,
352               well : 'sm',
353               xns : Roo.bootstrap,
354               '|xns' : 'Roo.bootstrap'
355              }
356             ]
357            }
358           ]
359          }
360         ]
361        }
362       ]
363      },
364      {
365       xtype : 'Row',
366       xns : Roo.bootstrap,
367       '|xns' : 'Roo.bootstrap',
368       items  : [
369        {
370         xtype : 'Column',
371         xs : 12,
372         xns : Roo.bootstrap,
373         '|xns' : 'Roo.bootstrap',
374         items  : [
375          {
376           xtype : 'Form',
377           method : 'GET',
378           url : baseURL + '/Roo/Core_person.php',
379           listeners : {
380            actioncomplete : function (_self, action)
381             {
382                 if(action.type == 'setdata') {
383                     
384                     this.clearInvalid();
385                 }
386                 
387                 if(action.type == 'submit') {
388                     
389                     switch(action.result.data) {
390                         
391                         case 'DONE':
392                             var cb = function() {
393                                 _this.dialog.hide();
394                             };
395                             
396                             Roo.bootstrap.MessageBox.alert('Success', 'Two Factor authentication has been enabled', cb);
397                             return;
398                             
399                         default:
400                             Roo.log('invalid usage');
401                             break;
402                     }
403                 }
404             },
405            actionfailed : function (_self, action)
406             {
407                 if(action.type == 'submit') {
408                     
409                     switch(action.result.errorMsg) {
410                         case '_invalid_auth_code':
411                             Roo.bootstrap.MessageBox.alert(
412                                 'Invalid authentication code',
413                                 'Please re-enter the latest authentication code.'
414                             );
415                             break;
416                         default:
417                             Roo.log('invalid usage');
418                             break;
419                     }
420                 }
421             },
422            render : function (_self)
423             {
424                 _this.form = this;
425             }
426           },
427           xns : Roo.bootstrap,
428           '|xns' : 'Roo.bootstrap',
429           items  : [
430            {
431             xtype : 'NumberField',
432             allowBlank : false,
433             allowDecimals : false,
434             allowNegative : false,
435             allowZero : false,
436             decimalPrecision : 0,
437             fieldLabel : _this._strings['ee468f72ab7fe4937fb014d6fcea540b'] /* Enter Two factor Authentication code */,
438             indicatorpos : 'right',
439             labelAlign : 'top',
440             maxLength : 6,
441             name : 'two_factor_auth_code',
442             xs : 12,
443             xns : Roo.bootstrap,
444             '|xns' : 'Roo.bootstrap'
445            },
446            {
447             xtype : 'Input',
448             inputType : 'hidden',
449             name : 'id',
450             xns : Roo.bootstrap,
451             '|xns' : 'Roo.bootstrap'
452            }
453           ]
454          }
455         ]
456        }
457       ]
458      }
459     ]
460    }  );
461  }
462 });
463 Roo.apply(Pman.Dialog.BAdminStaffTwoFactorQRCode, Pman.Dialog.BAdminStaffTwoFactorQRCode.prototype);