diff --git a/models/LoginForm.php b/models/LoginForm.php index 0b053ee..cfa6236 100644 --- a/models/LoginForm.php +++ b/models/LoginForm.php @@ -46,11 +46,6 @@ public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { $user = $this->getUser(); - if($user){ - echo $user->id; - }else{ - echo 'no user'; - } if (!$user || !$user->validatePassword($this->password)) { $this->addError($attribute, '用户名或密码错误'); } @@ -79,7 +74,6 @@ public function getUser() if ($this->_user === false) { $this->_user = User::findIdentity($this->username); } - return $this->_user; } } diff --git a/models/SignupForm.php b/models/SignupForm.php index 3273140..778e8ab 100644 --- a/models/SignupForm.php +++ b/models/SignupForm.php @@ -8,7 +8,7 @@ class SignupForm extends Model { - public $username; + public $id; public $pwd; public $pwd2; public $real_name; @@ -16,9 +16,7 @@ class SignupForm extends Model public $passport; public $avatar; public $add; - - private $_user = false; - + public $_user; /** * @return array the validation rules. @@ -26,8 +24,9 @@ class SignupForm extends Model public function rules() { return [ - [['username', 'password','passport','add','id_card','real_name' ], 'required','message'=>'请输入完整的信息'], - ['username','email','用户名必须是邮箱格式'], + [['id', 'password','passport','add','id_card','real_name' ], 'required','message'=>'请输入完整的信息'], + ['id','email','用户名必须是邮箱格式'], + ['id','validateId','message'=>'该用户已存在'], ['pwd','string','length','min'=>6,'max'=>18,'message'=>'密码长度不合适'], ['pwd2','compare','compareAttribute'=>'pwd','message'=>'两次输入密码不一样'], ['real_name','string','length','min'=>2,'max'=>4,'message'=>'请输入正确姓名'], @@ -38,48 +37,22 @@ public function rules() ]; } - /** - * Validates the password. - * This method serves as the inline validation for password. - * - * @param string $attribute the attribute currently being validated - * @param array $params the additional name-value pairs given in the rule - */ - - public function validatePassword($attribute, $params) - { - if (!$this->hasErrors()) { - $user = $this->getUser(); - - if (!$user || !$user->validatePassword($this->password)) { - $this->addError($attribute, 'Incorrect username or password.'); + public function validateId(){ + if(!$this->hasErrors()){ + if(isset($id)){ + if($this->getUser() != false){ + $this->addError($id,'该邮箱已注册'); + } } } } - /** - * Logs in a user using the provided username and password. - * @return boolean whether the user is logged in successfully - */ - public function login() - { - if ($this->validate()) { - return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); - } - return false; - } - - /** - * Finds user by [[username]] - * - * @return User|null - */ public function getUser() { if ($this->_user === false) { - $this->_user = User::findByUsername($this->username); + $this->_user = User::findIdentity($this->id); } - return $this->_user; } + } diff --git a/models/User.php b/models/User.php index 5274b8e..e18e2b7 100644 --- a/models/User.php +++ b/models/User.php @@ -7,12 +7,6 @@ class User extends ActiveRecord implements IdentityInterface { - public $id; - public $name; - public $pwd; - public $authKey; - public $token; - public static function tableName() { return 'store'; @@ -24,10 +18,9 @@ public static function tableName() public static function findIdentity($id)//在当前表中寻找当前$id 默认在主键 { $user = static::findOne($id); - if($user != null) { - echo $user->token."ddddd".$user->name."nnnnn"; + if($user === null) { + }else{ - echo 'user is null'; } return $user; } @@ -85,9 +78,6 @@ public function validateAuthKey($authKey) public function validatePassword($password) { $user = $this->find(); - foreach ($user->all() as $u){ - echo $u->id.'ccccc'; - } return $this->pwd === $password; } }