From d155122019022806c5fbaaf8d423d57c8384cc9f Mon Sep 17 00:00:00 2001 From: Terry <2358269014@qq.com> Date: Sat, 16 Nov 2019 18:34:23 +0800 Subject: [PATCH] admin user password --- models/mysqldb/adminUser/AdminUserForm.php | 20 +++----------------- services/adminUser/AdminUser.php | 5 +++++ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/models/mysqldb/adminUser/AdminUserForm.php b/models/mysqldb/adminUser/AdminUserForm.php index 5d58003f..21ac01f7 100644 --- a/models/mysqldb/adminUser/AdminUserForm.php +++ b/models/mysqldb/adminUser/AdminUserForm.php @@ -27,7 +27,7 @@ class AdminUserForm extends AdminUser { ['code', 'filter', 'filter' => 'trim'], ['code', 'validateCode'], ['person', 'filter', 'filter' => 'trim'], - //['password', 'validatePasswordFormat'], + ['password', 'validatePasswordFormat'], ]; return array_merge($parent_rules,$current_rules) ; @@ -48,20 +48,6 @@ class AdminUserForm extends AdminUser { $this->addError($attribute,"this username is exist!"); } } - // password - if($this->id){ - if($this->password && strlen($this->password) <= 6){ - $this->addError($attribute,"password must >=6"); - } - }else{ - if(!$this->password){ - $this->addError($attribute,"password can not empty"); - } else if (strlen($this->password) < 6) { - $this->addError($attribute,"password must >=6"); - } else if (!strlen($this->password) >= 100) { - $this->addError($attribute,"password must <= 100"); - } - } } public function validateCode($attribute, $params){ @@ -95,7 +81,7 @@ class AdminUserForm extends AdminUser { } } } - /* + public function validatePasswordFormat($attribute, $params){ if($this->id){ if($this->password && strlen($this->password) <= 6){ @@ -111,7 +97,7 @@ class AdminUserForm extends AdminUser { } } } - */ + public function setPassword($password) { diff --git a/services/adminUser/AdminUser.php b/services/adminUser/AdminUser.php index 85f42202..ed5cee91 100644 --- a/services/adminUser/AdminUser.php +++ b/services/adminUser/AdminUser.php @@ -162,6 +162,11 @@ class AdminUser extends Service if (!$data['auth_key']) { $this->_userFormModel->auth_key = ''; } + if (!$data['password'] && !$data['id']) { + Yii::$service->helper->errors->add("password can not empty"); + + return null; + } if ($this->_userFormModel[$primaryKey]) { if ($this->_userFormModel->validate()) { -- GitLab