From: Marcin Haba Date: Fri, 1 Jan 2016 11:32:21 +0000 (+0100) Subject: baculum: Unify user validation X-Git-Tag: Release-7.4.0~49 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5a4a219872b0c274ebfea8ce73248fdfe67d390d;p=bacula%2Fbacula baculum: Unify user validation --- diff --git a/gui/baculum/protected/JavaScript/misc.js b/gui/baculum/protected/JavaScript/misc.js index 6bd86a28da..4c1f6d044d 100644 --- a/gui/baculum/protected/JavaScript/misc.js +++ b/gui/baculum/protected/JavaScript/misc.js @@ -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(); diff --git a/gui/baculum/protected/Pages/Home.page b/gui/baculum/protected/Pages/Home.page index 0dd34c3df9..7d4808b059 100644 --- a/gui/baculum/protected/Pages/Home.page +++ b/gui/baculum/protected/Pages/Home.page @@ -347,9 +347,11 @@ }; 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(); diff --git a/gui/baculum/protected/Pages/Home.php b/gui/baculum/protected/Pages/Home.php index 24fd24d07c..c727933085 100644 --- a/gui/baculum/protected/Pages/Home.php +++ b/gui/baculum/protected/Pages/Home.php @@ -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();