Fix #6800 - Login Dialog Remember Username / 2FA + other fixes
authorAlan Knowles <alan@roojs.com>
Mon, 16 Aug 2021 07:45:57 +0000 (15:45 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 16 Aug 2021 07:45:57 +0000 (15:45 +0800)
Pman.Dialog.Login.bjs
Pman.Dialog.Login.js

index 4fd9263..d8dd619 100644 (file)
@@ -13,7 +13,6 @@
   "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"
  },
@@ -27,9 +26,9 @@
  "items" : [
   {
    "listeners" : {
-    "btnclick" : "function (e)\n{\n    if(e == 'cancel'){\n        _this.dialog.hide();\n        return;\n    }\n    \n    _this.dialog.el.select('.modal-content', true).first().mask('Sending...');\n    _this.form.doAction('submit');\n}",
-    "|render" : "function (_self) {\n\n    Roo.get('login-err').dom.innerHTML = \"\";\n    _this.dialog.el.select('.modal-content', true).first().unmask();\n    \n    if(Roo.isTouch){\n        this.animate = false;\n    }\n}\n    ",
-    "show" : "function (_self)\n{\n    this.setTitle( _this.dialog._dialog_title_login );\n    \n    if (!Roo.state.Manager.getProvider().expires) {\n        Roo.state.Manager.setProvider(new Roo.state.CookieProvider());\n    }\n    \n    _this.lastLogin = Roo.state.Manager.get('Pman.Login', {});\n    _this.form.findField('username').focus();\n}"
+    "btnclick" : "function (e)\n{\n    if(e == 'cancel'){\n        _this.dialog.hide();\n        return;\n    }\n    _this.alert.hide();\n    _this.dialog.el.select('.modal-content', true).first().mask('Sending...');\n    _this.form.doAction('submit');\n}",
+    "|render" : "function (_self) {\n\n \n    _this.dialog.el.select('.modal-content', true).first().unmask();\n    \n    if(Roo.isTouch){\n        this.animate = false;\n    }\n}\n    ",
+    "show" : "function (_self)\n{\n    this.setTitle( _this.dialog._dialog_title_login );\n    \n  \n}"
    },
    "String cls" : "enable-overflow login-dialog padding-bottom-trim",
    "Boolean allow_close" : false,
@@ -61,9 +60,9 @@
            "items" : [
             {
              "listeners" : {
-              "|actioncomplete" : "function (_self, action) {\n    \n    if(action.type == 'setdata'){\n\n        if(\n            _this.lastLogin && \n            _this.lastLogin.login_provider == ''\n        ){\n            _this.form.findField('username').setValue(_this.lastLogin.email);\n        }\n        \n        Roo.get('login-err').dom.innerHTML = \"\";\n        _this.errorRow.hide();\n        _this.dialog.el.select('.modal-content', true).first().unmask();\n        this.clearInvalid();\n        return;\n    }\n     \n    if(action.type == 'load'){\n        \n        return;\n    }\n    \n    if (action.type =='submit') {\n    \n        _this.dialog.hide();\n        \n        var cb = function(){\n            if (_this.callback) {\n                _this.callback.call(_this, action.result);\n            }\n            \n            _this.form.reset();\n            \n            return;\n        }\n        \n        if(\n            !action.result.data.oath_key_enable &&\n            action.result.data.require_oath * 1 == 1\n        ) {\n            Roo.bootstrap.MessageBox.show({\n                title : \"Two Factor Authentication is required\",\n                closable : false,\n                msg : \"This system requires that you use Google Two Factor Authentication.\",\n                buttons : {yes:'Setup Two Factor Authentication'},\n                fn : function(ret){\n                    if(ret != 'yes'){\n                         return;\n                     }\n                    \n                    Pman.Dialog.BAdminStaffTwoFactorQRCode.show(\n                        {id: action.result.data.id, allow_close : true },\n                        cb\n                    );\n                }\n            });\n            \n            return;\n        }\n        \n        cb();\n    }\n}",
-              "|render" : "function (_self) {\n    _this.form = _self;\n}",
-              "|actionfailed" : "function (_self, action) {\n    Roo.log('action failed?!');\n    Roo.log(action);\n    \n    _this.dialog.el.select('.modal-content', true).first().unmask();\n    \n    if (typeof(action) != 'undefined' && action.failureType == 'server') {\n        \n        switch (action.result.errorMsg) {\n                    \n            case 'Authenticated' :\n                \n                var data = Roo.apply(action.result.errors);\n                \n                data.target = _this.form.findField('username').getValue();\n                \n                Roo.bootstrap.MessageBox.alert(\"Error\", \"odd error messages\");\n                \n                break;\n                \n            case 'NEW-IP-ADDRESS' :\n            case 'PENDING-IP-ADDRESS' :\n            case 'BAD-IP-ADDRESS' :\n            case 'BLOCKED-IP-ADDRESS' :\n                \n                _this.dialog.hide();\n                \n                Pman.Dialog.LoginNotice.show({\n                    status : action.result.errorMsg,\n                    ip : action.result.errors.ip\n                });\n                \n                break;\n                \n            default:\n               _this.errorRow.show();\n                Roo.get('login-err').dom.innerHTML = action.result.errorMsg;\n                break;\n        }\n        \n        return;\n    }\n    \n    Roo.get('login-err').dom.innerHTML = \"Fill in all the required fields\";\n}"
+              "|actionfailed" : "function (_self, action) {\n    Roo.log('action failed?!');\n    Roo.log(action);\n    \n    _this.dialog.el.select('.modal-content', true).first().unmask();\n    _this.alert.show();\n    if (typeof(action) != 'undefined' && action.failureType == 'server') {\n        \n        switch (action.result.code) {\n                    \n            case 'Authenticated' :\n                \n                 \n                Roo.bootstrap.MessageBox.alert(\"Error\",action.result.errorMsg);\n                _this.alert.setHtml(action.result.errorMsg);\n                break;\n                \n            case 'NEW-IP-ADDRESS' :\n            case 'PENDING-IP-ADDRESS' :\n            case 'BAD-IP-ADDRESS' :\n            case 'BLOCKED-IP-ADDRESS' :\n                \n                _this.dialog.hide();\n                Roo.bootstrap.MessageBox.alert(\"Error\", action.result.errorMsg);\n                //Pman.Dialog.LoginNotice.show({\n                  //  status : action.result.errorMsg,\n                  //  ip : action.result.errors.ip\n                //});\n                \n                break;\n             case 'LOGIN-2FA':\n                this.findField('username').hide();\n                this.findField('password').hide();\n                this.findField('oath_password').show();\n                return; // no way back from here..\n             \n            default:\n               _this.errorRow.show();\n                _this.alert.setHtml(action.result.errorMsg);\n                break;\n        }\n        \n        return;\n    }\n    \n    _this.alert.setHtml( \"Fill in all the required fields\");\n}",
+              "|actioncomplete" : "function (_self, action) {\n   \n   \n     if (!Roo.state.Manager.getProvider().expires) {\n        Roo.state.Manager.setProvider(new Roo.state.CookieProvider());\n    }\n    \n    _this.lastLogin = Roo.state.Manager.get('Pman.Login', {});\n    _this.form.findField('username').focus();\n    \n    \n    if(action.type == 'setdata'){\n\n        this.findField('username').show();\n        this.findField('password').show();\n        this.findField('oath_password').hide();\n\n\n        _this.errorRow.hide();\n        _this.dialog.el.select('.modal-content', true).first().unmask();\n        this.clearInvalid();\n        if(\n            _this.lastLogin && \n            _this.lastLogin.username != ''\n        ){\n            \n            _this.form.findField('username').setValue(_this.lastLogin.username);\n             _this.form.findField('password').focus();\n        }\n        return;\n    }\n     \n    if(action.type == 'load'){\n        \n        return;\n    }\n    \n    if (action.type =='submit') {\n        \n        _this.dialog.hide();\n        \n        var cb = function(){\n            if (_this.callback) {\n                _this.callback.call(_this, action.result);\n            }\n            \n            _this.form.reset();\n            \n            return;\n        }\n        \n        if(\n            !action.result.data.oath_key_enable &&\n            action.result.data.require_oath * 1 == 1\n        ) {\n            Roo.bootstrap.MessageBox.show({\n                title : \"Two Factor Authentication is required\",\n                closable : false,\n                msg : \"This system requires that you use Google Two Factor Authentication.\",\n                buttons : {yes:'Setup Two Factor Authentication'},\n                fn : function(ret){\n                    if(ret != 'yes'){\n                         return;\n                     }\n                    \n                    Pman.Dialog.BAdminStaffTwoFactorQRCode.show(\n                        {id: action.result.data.id, allow_close : true },\n                        cb\n                    );\n                }\n            });\n            \n            return;\n        }\n        // store only username\n        Roo.state.Manager.set('Pman.Login', {\n              username : this.findField('username').getValue() \n        });\n        cb();\n    }\n}",
+              "|render" : "function (_self) {\n    _this.form = _self;\n}"
              },
              "$ url" : "baseURL + '/Login'",
              "labelAlign" : "left",
@@ -82,8 +81,8 @@
                   "specialkey" : "function (_self, e)\n{\n    if(e.getKey() == 13){\n        _this.dialog.el.select('.modal-content', true).first().mask('Sending...');\n        _this.form.doAction('submit');\n    }\n    \n}"
                  },
                  "inputType" : "email",
-                 "vtype" : "email",
                  "xtype" : "Input",
+                 "vtype" : "email",
                  "placeholder" : "Email Address",
                  "allowBlank" : false,
                  "$ xns" : "Roo.bootstrap",
@@ -94,8 +93,8 @@
                   "specialkey" : "function (_self, e)\n{\n    if(e.getKey() == 13){\n        _this.dialog.el.select('.modal-content', true).first().mask('Sending...');\n        _this.form.doAction('submit');\n    }\n}"
                  },
                  "inputType" : "password",
-                 "xtype" : "Input",
                  "placeholder" : "Password",
+                 "xtype" : "Input",
                  "allowBlank" : false,
                  "$ xns" : "Roo.bootstrap",
                  "name" : "password"
                  },
                  "Number maxLength" : 6,
                  "Boolean allowZero" : true,
+                 "bool hidden" : true,
                  "placeholder" : "Two-Factor Authentication Number (if relevant)",
                  "xtype" : "NumberField",
                  "Boolean allowDecimals" : false,
            "$ xns" : "Roo.bootstrap",
            "items" : [
             {
-             "xtype" : "Container",
-             "style" : "margin-bottom: 15px;\n    padding: 5px;",
-             "cls" : "bg-danger",
-             "html" : "<div id=\"login-err\" class=\"dialog-err\" style=\"color:red\"></div>",
+             "listeners" : {
+              "render" : "function (_self)\n{\n_this.alert = this;\n}"
+             },
+             "String weight" : "danger",
+             "xtype" : "Alert",
              "$ xns" : "Roo.bootstrap"
             }
            ]
     },
     {
      "xtype" : "Button",
-     "html" : "Login",
      "$ string weight" : "'primary'",
+     "html" : "Login",
      "$ xns" : "Roo.bootstrap",
      "String style" : "float: right",
      "* prop" : "buttons[]",
index dd76e85..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,12 +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();
+        
       }
     },
     xns : Roo.bootstrap,
@@ -171,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;
                     }
                      
@@ -194,7 +202,7 @@ Roo.apply(Pman.Dialog.Login.prototype, {
                     }
                     
                     if (action.type =='submit') {
-                    
+                        
                         _this.dialog.hide();
                         
                         var cb = function(){
@@ -230,7 +238,10 @@ Roo.apply(Pman.Dialog.Login.prototype, {
                             
                             return;
                         }
-                        
+                        // store only username
+                        Roo.state.Manager.set('Pman.Login', {
+                              username : this.findField('username').getValue() 
+                        });
                         cb();
                     }
                 },
@@ -239,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' :
@@ -260,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;
@@ -337,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) */,
@@ -386,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'
              }