Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/trieyouth/basic into dcc
Browse files Browse the repository at this point in the history
# Conflicts:
#	controllers/LoginController.php
  • Loading branch information
cxqz520 committed Dec 13, 2015
1 parent fde3d6b commit dfd610f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 58 deletions.
6 changes: 0 additions & 6 deletions models/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '用户名或密码错误');
}
Expand Down Expand Up @@ -79,7 +74,6 @@ public function getUser()
if ($this->_user === false) {
$this->_user = User::findIdentity($this->username);
}

return $this->_user;
}
}
53 changes: 13 additions & 40 deletions models/SignupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@

class SignupForm extends Model
{
public $username;
public $id;
public $pwd;
public $pwd2;
public $real_name;
public $id_card;
public $passport;
public $avatar;
public $add;

private $_user = false;

public $_user;

/**
* @return array the validation rules.
*/
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'=>'请输入正确姓名'],
Expand All @@ -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;
}

}
14 changes: 2 additions & 12 deletions models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit dfd610f

Please sign in to comment.