PHP8
[Pman.BAdmin] / Pman.Dialog.Login.js
index 5f34919..03c5c2e 100644 (file)
@@ -15,7 +15,6 @@ Roo.apply(Pman.Dialog.Login.prototype, {
   'dc647eb65e6711e155375218212b3964' :"Password",
   '06cf692a8d2bb0ab8318dc6c839ae931' :"Two-Factor Authentication Number (if relevant)",
   '11163ed17ad9afc7680bb9e92f15d6fd' :"We have sent you a link to reset your password",
-  '5047040b025ce0295b58d42250014417' :"<div id=\"login-err\" class=\"dialog-err\" style=\"color:red\"></div>",
   '24efa7ee4511563b16144f39706d594f' :"Notice",
   '643a860f992333b8600ea264aca7c4fc' :"Email Address"
  },
@@ -63,13 +62,13 @@ Roo.apply(Pman.Dialog.Login.prototype, {
               _this.dialog.hide();
               return;
           }
-          
+          _this.alert.hide();
           _this.dialog.el.select('.modal-content', true).first().mask('Sending...');
           _this.form.doAction('submit');
       },
      render : function (_self) {
       
-          Roo.get('login-err').dom.innerHTML = "";
+       
           _this.dialog.el.select('.modal-content', true).first().unmask();
           
           if(Roo.isTouch){
@@ -80,17 +79,7 @@ Roo.apply(Pman.Dialog.Login.prototype, {
       {
           this.setTitle( _this.dialog._dialog_title_login );
           
-          if (!Roo.state.Manager.getProvider().expires) {
-              Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
-          }
-          
-          _this.lastLogin = Roo.state.Manager.get('Pman.Login', {});
-          _this.form.findField('username').focus();
-          
-          if(
-              Pman.Login.authUser &&
-              Pman.Login.authUser.disable_oath
-          )
+        
       }
     },
     xns : Roo.bootstrap,
@@ -107,6 +96,7 @@ Roo.apply(Pman.Dialog.Login.prototype, {
      },
      {
       xtype : 'Button',
+      cls : 'login-forgot-pass-btn',
       _forgot_passwd_success_body : _this._strings['11163ed17ad9afc7680bb9e92f15d6fd'] /* We have sent you a link to reset your password */,
       _forgot_passwd_success_title : _this._strings['24efa7ee4511563b16144f39706d594f'] /* Notice */,
       href : '#',
@@ -125,7 +115,10 @@ Roo.apply(Pman.Dialog.Login.prototype, {
             var _self = this;
             
             Pman.Dialog.BAdminForgotPassword.show({email : email}, function(){
-                Roo.bootstrap.MessageBox.alert(_self._forgot_passwd_success_title, _self._forgot_passwd_success_body);
+                Roo.bootstrap.MessageBox.alert(_self._forgot_passwd_success_title, _self._forgot_passwd_success_body, function() {
+                        _this.dialog.show();
+                });
+        
             });
         }
       },
@@ -172,20 +165,34 @@ Roo.apply(Pman.Dialog.Login.prototype, {
               url : baseURL + '/Login',
               listeners : {
                actioncomplete : function (_self, action) {
+                   
+                   
+                     if (!Roo.state.Manager.getProvider().expires) {
+                        Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
+                    }
+                    
+                    _this.lastLogin = Roo.state.Manager.get('Pman.Login', {});
+                    _this.form.findField('username').focus();
+                    
                     
                     if(action.type == 'setdata'){
                 
+                        this.findField('username').show();
+                        this.findField('password').show();
+                        this.findField('oath_password').hide();
+                
+                
+                        _this.errorRow.hide();
+                        _this.dialog.el.select('.modal-content', true).first().unmask();
+                        this.clearInvalid();
                         if(
                             _this.lastLogin && 
-                            _this.lastLogin.login_provider == ''
+                            _this.lastLogin.username != ''
                         ){
-                            _this.form.findField('username').setValue(_this.lastLogin.email);
+                            
+                            _this.form.findField('username').setValue(_this.lastLogin.username);
+                             _this.form.findField('password').focus();
                         }
-                        
-                        Roo.get('login-err').dom.innerHTML = "";
-                        _this.errorRow.hide();
-                        _this.dialog.el.select('.modal-content', true).first().unmask();
-                        this.clearInvalid();
                         return;
                     }
                      
@@ -195,16 +202,47 @@ Roo.apply(Pman.Dialog.Login.prototype, {
                     }
                     
                     if (action.type =='submit') {
-                    
+                        
                         _this.dialog.hide();
-                    
-                        if (_this.callback) {
-                            _this.callback.call(_this, action.result);
-                         }
-                         
-                         _this.form.reset();
-                         
-                         return;
+                        
+                        var cb = function(){
+                            if (_this.callback) {
+                                _this.callback.call(_this, action.result);
+                            }
+                            
+                            _this.form.reset();
+                            
+                            return;
+                        }
+                        
+                        if(
+                            !action.result.data.oath_key_enable &&
+                            action.result.data.require_oath * 1 == 1
+                        ) {
+                            Roo.bootstrap.MessageBox.show({
+                                title : "Two Factor Authentication is required",
+                                closable : false,
+                                msg : "This system requires that you use Google Two Factor Authentication.",
+                                buttons : {yes:'Setup Two Factor Authentication'},
+                                fn : function(ret){
+                                    if(ret != 'yes'){
+                                         return;
+                                     }
+                                    
+                                    Pman.Dialog.BAdminStaffTwoFactorQRCode.show(
+                                        {id: action.result.data.id, allow_close : true },
+                                        cb
+                                    );
+                                }
+                            });
+                            
+                            return;
+                        }
+                        // store only username
+                        Roo.state.Manager.set('Pman.Login', {
+                              username : this.findField('username').getValue() 
+                        });
+                        cb();
                     }
                 },
                actionfailed : function (_self, action) {
@@ -212,19 +250,16 @@ Roo.apply(Pman.Dialog.Login.prototype, {
                     Roo.log(action);
                     
                     _this.dialog.el.select('.modal-content', true).first().unmask();
-                    
+                    _this.alert.show();
                     if (typeof(action) != 'undefined' && action.failureType == 'server') {
                         
-                        switch (action.result.errorMsg) {
+                        switch (action.result.code) {
                                     
                             case 'Authenticated' :
                                 
-                                var data = Roo.apply(action.result.errors);
-                                
-                                data.target = _this.form.findField('username').getValue();
-                                
-                                Roo.bootstrap.MessageBox.alert("Error", "odd error messages");
-                                
+                                 
+                                Roo.bootstrap.MessageBox.alert("Error",action.result.errorMsg);
+                                _this.alert.setHtml(action.result.errorMsg);
                                 break;
                                 
                             case 'NEW-IP-ADDRESS' :
@@ -233,24 +268,29 @@ Roo.apply(Pman.Dialog.Login.prototype, {
                             case 'BLOCKED-IP-ADDRESS' :
                                 
                                 _this.dialog.hide();
-                                
-                                Pman.Dialog.LoginNotice.show({
-                                    status : action.result.errorMsg,
-                                    ip : action.result.errors.ip
-                                });
+                                Roo.bootstrap.MessageBox.alert("Error", action.result.errorMsg);
+                                //Pman.Dialog.LoginNotice.show({
+                                  //  status : action.result.errorMsg,
+                                  //  ip : action.result.errors.ip
+                                //});
                                 
                                 break;
-                                
+                             case 'LOGIN-2FA':
+                                this.findField('username').hide();
+                                this.findField('password').hide();
+                                this.findField('oath_password').show();
+                                return; // no way back from here..
+                             
                             default:
                                _this.errorRow.show();
-                                Roo.get('login-err').dom.innerHTML = action.result.errorMsg;
+                                _this.alert.setHtml(action.result.errorMsg);
                                 break;
                         }
                         
                         return;
                     }
                     
-                    Roo.get('login-err').dom.innerHTML = "Fill in all the required fields";
+                    _this.alert.setHtml( "Fill in all the required fields");
                 },
                render : function (_self) {
                     _this.form = _self;
@@ -310,6 +350,7 @@ Roo.apply(Pman.Dialog.Login.prototype, {
                   allowNegative : false,
                   allowZero : true,
                   decimalPrecision : 0,
+                  hidden : true,
                   maxLength : 6,
                   name : 'oath_password',
                   placeholder : _this._strings['06cf692a8d2bb0ab8318dc6c839ae931'] /* Two-Factor Authentication Number (if relevant) */,
@@ -359,10 +400,14 @@ Roo.apply(Pman.Dialog.Login.prototype, {
             '|xns' : 'Roo.bootstrap',
             items  : [
              {
-              xtype : 'Container',
-              cls : 'bg-danger',
-              html : _this._strings['5047040b025ce0295b58d42250014417'] /* <div id="login-err" class="dialog-err" style="color:red"></div> */,
-              style : 'margin-bottom: 15px;\n    padding: 5px;',
+              xtype : 'Alert',
+              weight : 'danger',
+              listeners : {
+               render : function (_self)
+                {
+                _this.alert = this;
+                }
+              },
               xns : Roo.bootstrap,
               '|xns' : 'Roo.bootstrap'
              }