PHP8
[Pman.BAdmin] / Pman.Dialog.BAdminPassword.js
index 26a00fe..2d099ce 100644 (file)
@@ -136,18 +136,24 @@ Roo.apply(Pman.Dialog.BAdminPassword.prototype, {
          actioncomplete : function (_self, action)
           {
               if(action.type == 'setdata'){
-                 
-                 _this.form.findField('_enable_oath_key').setChecked(false, true);
+                  
+                  _this.form.reset();
+                  
+                  _this.form.clearInvalid();
+                  
+                  _this.form.findField('_enable_oath_key').setChecked(false,false);
                  
                   new Pman.Request({
-                      url : baseURL + '/Login.php',
-                      method : 'POST',
-                      params : {
+                      url: baseURL + '/Login.php',
+                      method: 'POST',
+                      params: {
                           getAuthUser: true
                       }, 
-                      success : function(res) {
-                          Roo.log(res);
-                          _this.form.clearInvalid();
+                      success: function(res) {
+                          
+                          if(res.data.oath_key_enable) {
+                              _this.form.findField('_enable_oath_key').setChecked(true,false);
+                          }
                       }
                   });
               }
@@ -158,7 +164,7 @@ Roo.apply(Pman.Dialog.BAdminPassword.prototype, {
               }
               
               if (action.type =='submit') {
-              
+                  
                   if (_this.callback) {
                       _this.callback.call(_this, action.result);
                   }
@@ -185,7 +191,7 @@ Roo.apply(Pman.Dialog.BAdminPassword.prototype, {
           },
          render : function (_self)
           {
-              _this.form = _self;
+              _this.form = this;
           }
         },
         xns : Roo.bootstrap,
@@ -254,18 +260,64 @@ Roo.apply(Pman.Dialog.BAdminPassword.prototype, {
               listeners : {
                check : function (_self, checked)
                 {
-                    
                     if(checked) {
-                        
-                        Pman.Dialog.BAdminStaffTwoFactorQRCode.show({});
-                        
                         this.setBoxLabel('Untick to disable Two Factor authentication');
-                        
                         return;
                     }
                     
                     this.setBoxLabel('Enable Two Factor Authentication');
+                },
+               click : function (_self, e)
+                {
+                    if(!Pman.Login.authUser) {
+                        Roo.bootstrap.MessageBox.alert('Error', 'Please login again');
+                        return;
+                    }
+                    
+                    e.preventDefault();
                     
+                    if(!this.checked) {
+                        Pman.Dialog.BAdminStaffTwoFactorQRCode.show({
+                            id: Pman.Login.authUser.id,
+                            allow_close: false,
+                            allow_cancel : true
+                        }, function(valid){
+                                if(valid) {
+                                    _this.dialog.hide({});
+                                    return;
+                                }
+                                
+                                _this.form.findField('_enable_oath_key').setChecked(false,false);
+                            }
+                        );
+                        return;
+                    }
+                    
+                    new Pman.Request({
+                        url : baseURL + '/Roo/Core_person',
+                        method :'GET',
+                        params : {
+                            oath_key_disable: 1,
+                            id: Pman.Login.authUser.id
+                        },
+                        
+                        success : function(res)
+                        {
+                            switch(res.data) {
+                                case 'DONE':
+                                    Roo.bootstrap.MessageBox.alert('Success', 'The two factor authentication has been disabled');
+                                    break;
+                                default:
+                                    Roo.log('invalid usage');
+                                    break;
+                            }
+                        },
+                        
+                        failure : function(res)
+                        {
+                            Roo.bootstrap.MessageBox.alert('Error', res);
+                        }
+                    });
                 }
               },
               xns : Roo.bootstrap,