| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 | 
							- <?php
 
- /**
 
-  * FecShop file.
 
-  *
 
-  * @link http://www.fecshop.com/
 
-  * @copyright Copyright (c) 2016 FecShop Software LLC
 
-  * @license http://www.fecshop.com/license/
 
-  */
 
- namespace fecadmin\models\AdminUser;
 
- use fecadmin\models\AdminUser;
 
- /**
 
-  * @author Terry Zhao <2358269014@qq.com>
 
-  * @since 1.0
 
-  */
 
- class AdminUserForm extends AdminUser {
 
- 	private $_admin_user;
 
- 	public function rules()
 
-     {
 
-        
 
- 		
 
- 		$parent_rules  = parent::rules();
 
- 		$current_rules = [
 
- 			['username', 'filter', 'filter' => 'trim'],
 
-             ['username', 'required'],
 
-             ['username', 'validateUsername'],
 
-             ['username', 'string', 'min' => 2, 'max' => 20],
 
- 			
 
- 			['email', 'filter', 'filter' => 'trim'],
 
-         //    ['email', 'required'],
 
-         //    ['email', 'email'],
 
-         //    ['email', 'string', 'max' => 255],
 
- 		//	['email', 'validateEmail'],
 
- 			
 
- 			['code', 'required'],
 
- 			['code', 'filter', 'filter' => 'trim'],
 
- 			['code', 'validateCode'],
 
- 		//	['code', 'string', 'min' => 5, 'max' => 5],
 
- 			
 
- 		//	['role', 'required'],
 
- 			
 
- 			['person', 'filter', 'filter' => 'trim'],
 
- 		//	['person', 'required'],
 
- 			
 
-         //    ['email', 'unique', 'targetClass' => '\fecadmin\models\AdminUser', 'message' => 'This email address has already been taken.'],
 
- 		//	['password', 'required'],
 
-          //   ['password', 'string', 'min' => 6],
 
- 			['password', 'validatePasswordFormat'],
 
- 		
 
- 		];
 
- 		
 
- 		
 
- 		return array_merge($parent_rules,$current_rules) ;
 
- 		
 
- 		
 
-     }
 
- 	
 
- 	
 
- 	
 
- 	
 
- 	public function validateUsername($attribute, $params){
 
- 		//$user = User::findByUsername($this->username)
 
- 		if($this->id){
 
- 			$one = AdminUser::find()->where(" id != ".$this->id." AND username = '".$this->username."' ")
 
- 						->one();
 
- 			if($one['id']){
 
- 				$this->addError($attribute,"this username is exist!");
 
- 			}
 
- 		}else{
 
- 			$one = AdminUser::find()->where(" username = '".$this->username."' ")
 
- 						->one();
 
- 			if($one['id']){
 
- 				$this->addError($attribute,"this username is exist!");
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	
 
- 	public function validateCode($attribute, $params){
 
- 		//$user = User::findByUsername($this->username)
 
- 		if($this->id){
 
- 			$one = AdminUser::find()->where(" id != ".$this->id." AND code = '".$this->code."' ")
 
- 						->one();
 
- 			if($one['id']){
 
- 				$this->addError($attribute,"this code is exist!");
 
- 			}
 
- 		}else{
 
- 			$one = AdminUser::find()->where(" code = '".$this->code."' ")
 
- 						->one();
 
- 			if($one['id']){
 
- 				$this->addError($attribute,"this code is exist!");
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	
 
- 	public function validateEmail($attribute, $params){
 
- 		//$user = User::findByUsername($this->username)
 
- 		if($this->id){
 
- 			$one = AdminUser::find()->where(" id != ".$this->id." AND email = '".$this->email."' ")
 
- 						->one();
 
- 			if($one['id']){
 
- 				$this->addError($attribute,"this email is exist!");
 
- 			}
 
- 		}else{
 
- 			$one = AdminUser::find()->where(" email = '".$this->email."' ")
 
- 						->one();
 
- 			if($one['id']){
 
- 				$this->addError($attribute,"this email is exist!");
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	public function validatePasswordFormat($attribute, $params){
 
- 		if($this->id){
 
- 			if($this->password && strlen($this->password) <= 6){
 
- 				$this->addError($attribute,"password must >=6");
 
- 			}
 
- 		}else{
 
- 			if($this->password && strlen($this->password) >= 6){
 
- 				
 
- 			}else{
 
- 				$this->addError($attribute,"password must >=6");
 
- 			}	
 
- 		}
 
- 	}
 
- 	
 
- 	
 
- 	public function setPassword($password)
 
-     {
 
- 		if($this->password){
 
- 			$this->password_hash = \Yii::$app->security->generatePasswordHash($password);
 
- 			$this->password = '';
 
- 		}
 
-     }
 
- 	
 
- 	# 重写保存方法
 
- 	public function save($runValidation = true, $attributeNames = NULL){
 
- 		
 
- 		if($this->id){
 
- 			$this->updated_at_datetime = date("Y-m-d H:i:s");
 
- 		}else{
 
- 			$this->created_at_datetime = date("Y-m-d H:i:s");
 
- 			$this->updated_at_datetime = date("Y-m-d H:i:s");
 
- 		}
 
- 		# 如果auth_key为空,则重置
 
- 		if(!$this->auth_key){
 
- 			$this->generateAuthKey();
 
- 		}
 
- 		# 如果access_token为空,则重置
 
- 		if(!$this->access_token){
 
- 			$this->generateAccessToken();
 
- 		}
 
- 		# 设置password
 
- 		$this->setPassword($this->password);
 
- 		parent::save($runValidation,$attributeNames);
 
- 	}
 
- }
 
 
  |