]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Unify user validation
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 1 Jan 2016 11:32:21 +0000 (12:32 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Fri, 1 Jan 2016 11:39:18 +0000 (12:39 +0100)
gui/baculum/protected/JavaScript/misc.js
gui/baculum/protected/Pages/Home.page
gui/baculum/protected/Pages/Home.php

index 6bd86a28da5e219ed4a01432551f51ce82d61902..4c1f6d044d4519f9c7e3a929037f99506d4d3bd0 100644 (file)
@@ -239,6 +239,9 @@ var Users = {
                        rel_chpwd_btn: 'chpwd_btn'
                }
        },
+       validators: {
+               user_pattern: null
+       },
        init: function() {
                this.setEvents();
        },
@@ -250,7 +253,7 @@ var Users = {
                document.getElementById(this.ids.create_user.newuser).addEventListener('keydown', function(e) {
                        var target = e.target || e.srcElement;
                        if (e.keyCode == 13) {
-                               $(target.nextElementSibling).click();
+                               $(target.parentNode.getElementsByTagName('A')[0]).click();
                        } else if (e.keyCode == 27) {
                                this.cancelAddUser();
                        }
@@ -268,30 +271,37 @@ var Users = {
        },
        userValidator: function(user) {
                user = user.replace(/\s/g, '');
-               var valid =  user != '';
-               return valid;
+               if (user == '') {
+                       alert(this.txt.enter_login);
+                       return false;
+               }
+               var valid =  this.validators.user_pattern.test(user);
+               if (valid === false) {
+                       alert(this.txt.invalid_login);
+                       return false;
+               }
+               return true;
        },
        pwdValidator: function(pwd) {
                var valid = pwd.length > 4;
+               if (valid === false) {
+                       alert(this.txt.invalid_pwd);
+               }
                return valid;
        },
        addUser: function() {
-               var valid = true;
                var user = document.getElementById(this.ids.create_user.newuser).value;
                var pwd = document.getElementById(this.ids.create_user.newpwd).value;
                if (this.userValidator(user) === false) {
-                       alert(this.txt.enter_login);
-                       valid = false;
+                       return false;
                }
                if (this.pwdValidator(pwd) === false) {
-                       alert(this.txt.invalid_pwd);
-                       valid = false;
-               }
-               if (valid === true) {
-                       $(this.ids.create_user.add_user).hide();
-                       this.action_callback('newuser', user, pwd);
+                       return false;
                }
-               return valid;
+
+               $(this.ids.create_user.add_user).hide();
+               this.action_callback('newuser', user, pwd);
+               return true;
        },
        rmUser: function(user) {
                this.action_callback('rmuser', user);
@@ -304,18 +314,16 @@ var Users = {
                $(el.nextElementSibling).select('input')[0].focus();
        },
        changePwd: function(el, user) {
-               var valid = true;
                var pwd = el.value;
 
                if (this.pwdValidator(pwd) === false) {
-                       alert(this.txt.invalid_pwd);
-                       valid = false;
-               }
-               if (valid === true) {
-                       $(el.parentNode).hide();
-                       $(el.parentNode.previousElementSibling).show();
-                       this.action_callback('chpwd', user, pwd);
+                       return false;
                }
+
+               $(el.parentNode).hide();
+               $(el.parentNode.previousElementSibling).show();
+               this.action_callback('chpwd', user, pwd);
+               return true;
        },
        cancelAddUser: function() {
                $(this.ids.create_user.add_user).hide();
index 0dd34c3df9043504c31dc7dc15696a5b83490cce..7d4808b0594a51939c95cbe3f79a30d4c4e80f13 100644 (file)
                                };
                                Users.txt = {
                                        enter_login: '<%[ Please enter login. ]%>',
+                                       invalid_login: '<%[ Invalid login value. Login may contain a-z A-Z 0-9 characters. ]%>',
                                        invalid_pwd: '<%[ Password must be longer than 4 chars. ]%>'
                                };
                                Users.action_callback = send_user_action;
+                               Users.validators = { user_pattern: new RegExp('^<%=$this->userPattern%>$') };
                                Users.init();
                        </script>
                </div>
index 24fd24d07cd94917ced815dd4a06fbe64baf5504..c727933085a242c5a43608ba5e26345b712a1c5f 100644 (file)
@@ -42,6 +42,8 @@ class Home extends BaculumPage
 
        public $windowIds = array('Storage', 'Client', 'Volume', 'Pool', 'Job', 'JobRun');
 
+       public $userPattern;
+
        public function onPreInit($param) {
                parent::onPreInit($param);
                if (!$this->IsPostBack && !$this->IsCallBack) {
@@ -72,6 +74,7 @@ class Home extends BaculumPage
                        $this->goToPage('ConfigurationWizard');
                }
 
+               $this->userPattern = $this->getModule('configuration')->getUserPattern();
                $appConfig = $this->getModule('configuration')->getApplicationConfig();
 
                $this->Users->Visible = $this->User->getIsAdmin();