diff --git a/module/user/js/common.ui.js b/module/user/js/common.ui.js index e916ef05ef..7ea5d3ae44 100644 --- a/module/user/js/common.ui.js +++ b/module/user/js/common.ui.js @@ -7,3 +7,42 @@ window.switchAccount = function(account) loadPage(link); }; + +function computePasswordStrength(password) +{ + if(password.length == 0) return 0; + + var strength = 0; + var length = password.length; + + var complexity = new Array(); + for(i = 0; i < length; i++) + { + letter = password.charAt(i); + var asc = letter.charCodeAt(); + if(asc >= 48 && asc <= 57) + { + complexity[0] = 1; + } + else if((asc >= 65 && asc <= 90)) + { + complexity[1] = 2; + } + else if(asc >= 97 && asc <= 122) + { + complexity[2] = 4; + } + else + { + complexity[3] = 8; + } + } + + var sumComplexity = 0; + for(i in complexity) sumComplexity += complexity[i]; + + if((sumComplexity == 7 || sumComplexity == 15) && password.length >= 6) strength = 1; + if(sumComplexity == 15 && password.length >= 10) strength = 2; + + return strength; +} diff --git a/module/user/js/create.ui.js b/module/user/js/create.ui.js index 0adf81d083..56a09873ba 100644 --- a/module/user/js/create.ui.js +++ b/module/user/js/create.ui.js @@ -2,6 +2,7 @@ $(function() { password1Encrypted = false; password2Encrypted = false; + verifyEncrypted = false; passwordStrength = 0; }) @@ -11,10 +12,14 @@ function changePassword(event) { password1Encrypted = false; } - else + if($(event.target).attr('id') == 'password2') { password2Encrypted = false; } + if($(event.target).attr('id') == 'verifyPassword') + { + verifyEncrypted = false; + } } function changeType(event) @@ -86,44 +91,12 @@ function clickSubmit() password1Encrypted = true; password2Encrypted = true; } -} -function computePasswordStrength(password) -{ - if(password.length == 0) return 0; - - var strength = 0; - var length = password.length; - - var complexity = new Array(); - for(i = 0; i < length; i++) + const password = $('input#verifyPassword').val().trim(); + if(!verifyEncrypted && password) { - letter = password.charAt(i); - var asc = letter.charCodeAt(); - if(asc >= 48 && asc <= 57) - { - complexity[0] = 1; - } - else if((asc >= 65 && asc <= 90)) - { - complexity[1] = 2; - } - else if(asc >= 97 && asc <= 122) - { - complexity[2] = 4; - } - else - { - complexity[3] = 8; - } + var rand = $('input#verifyRand').val(); + $('input#verifyPassword').val(md5(md5(password) + rand)); + verifyEncrypted = true; } - - var sumComplexity = 0; - for(i in complexity) sumComplexity += complexity[i]; - - if((sumComplexity == 7 || sumComplexity == 15) && password.length >= 6) strength = 1; - if(sumComplexity == 15 && password.length >= 10) strength = 2; - - return strength; } - diff --git a/module/user/model.php b/module/user/model.php index 05c9bf222c..3dde9c9ed6 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -321,7 +321,7 @@ class userModel extends model ->setIF($this->post->password1 == false, 'password', '') ->setIF($this->post->email != false, 'email', trim($this->post->email)) ->join('visions', ',') - ->remove('new, group, password1, password2, verifyPassword, passwordStrength,passwordLength') + ->remove('new, group, password1, password2, verifyPassword, passwordStrength,passwordLength, verifyRand') ->get(); $this->checkPassword(); @@ -362,30 +362,30 @@ class userModel extends model ->check('account', 'account') ->checkIF($this->post->email != '', 'email', 'email') ->exec(); - if(!dao::isError()) + + if(dao::isError()) return false; + + $userID = $this->dao->lastInsertID(); + + /* Set usergroup for account. */ + if(isset($_POST['group'])) { - $userID = $this->dao->lastInsertID(); - - /* Set usergroup for account. */ - if(isset($_POST['group'])) + foreach($this->post->group as $groupID) { - foreach($this->post->group as $groupID) - { - $data = new stdclass(); - $data->account = $this->post->account; - $data->group = $groupID; - $data->project = ''; - $this->dao->insert(TABLE_USERGROUP)->data($data)->exec(); - } + $data = new stdclass(); + $data->account = $this->post->account; + $data->group = $groupID; + $data->project = ''; + $this->dao->insert(TABLE_USERGROUP)->data($data)->exec(); } - - $this->computeUserView($user->account); - $this->loadModel('action')->create('user', $userID, 'Created'); - $this->loadModel('mail'); - if($this->config->mail->mta == 'sendcloud' and !empty($user->email)) $this->mail->syncSendCloud('sync', $user->email, $user->realname); - - return $userID; } + + $this->computeUserView($user->account); + $this->loadModel('action')->create('user', $userID, 'Created'); + $this->loadModel('mail'); + if($this->config->mail->mta == 'sendcloud' and !empty($user->email)) $this->mail->syncSendCloud('sync', $user->email, $user->realname); + + return $userID; } /** diff --git a/module/user/ui/create.html.php b/module/user/ui/create.html.php index bd4c54bb53..dfb3d56ca8 100644 --- a/module/user/ui/create.html.php +++ b/module/user/ui/create.html.php @@ -27,10 +27,11 @@ foreach($visionList as $key => $label) formPanel ( + import('/js/md5.js', 'js'), on::change('input[name=type]', 'changeType'), on::change('#addCompany', 'changeAddCompany'), on::change('input[name^=visions]', 'changeVision'), - on::change('#password1,#password2', 'changePassword'), + on::change('#password1,#password2,#verifyPassword', 'changePassword'), on::click('button[type=submit]', 'clickSubmit'), set::title($title), formRow @@ -71,6 +72,8 @@ formPanel checkbox ( set::id('addCompany'), + set::name('new[]'), + set::value('0'), set::text($lang->company->create), ) )