2016-03-28 10 views
-1

ユーザーがサインアップすると、システムは確認メールをユーザーに送信します。どのように私はこれを解決することができます、そのユーザーはログイン前に電子メールを確認する必要があり、ユーザーがログインできない電子メールユーザーを確認していない場合は?Yii2は電子メールの確認なしでユーザーにログインすることはできません

私はthis project: Yii 2 Advanced Template With Rbac User Managment

私LoginFormモデルコードに

namespace common\models; 
use Yii; 
use yii\base\Model; 

/** 
* Login form 
*/ 

class LoginForm extends Model 
{ 
public $email; 
public $password; 
public $rememberMe = true; 

protected $_user = false; 


/** 
* @inheritdoc 
*/ 
public function rules() 
{ 
    return [ 
     // username and password are both required 
     ['email', 'filter', 'filter' => 'trim'], 
     [['email','password'], 'required'], 
     ['email', 'email'], 
     // rememberMe must be a boolean value 
     ['rememberMe', 'boolean'], 
     // password is validated by validatePassword() 
     ['password', 'validatePassword','skipOnEmpty'=>false], 
    ]; 
} 

/** 
* 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->$attribute)) { 
      $this->addError('email', Yii::t('messages','Incorrect password or email.')); 
      $this->addError('password', Yii::t('messages','Incorrect password or email.')); 
     } 
    } 
} 

/** 
* 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); 
    } else { 
     return false; 
    } 
} 

/** 
* Finds user by [[username]] 
* 
* @return User|null 
*/ 
public function getUser() 
{ 
    if ($this->_user === false) { 
     $this->_user = User::findByEmail($this->email); 
    } 

    return $this->_user; 
} 

public function attributeLabels() 
{ 
    return [ 
     'email' => Yii::t('app','Email'), 
     'password' => Yii::t('app','Password') 
    ]; 
} 
} 

答えて

1

共通/モデル/ User.php

public static function findByEmail($email) 
    { 
     return static::findOne(['email'=>$email,'status'=>self::STATUS_ACTIVE]); 
    } 

内の関数の下に見つけて、

public static function findByEmail($email) 
{ 
    return static::findOne(['email'=>$email,'status'=>self::STATUS_ACTIVE,'email_verification_status'=>self::EMAIL_VERIFIED]); 
} 
を以下に置き換えるを使用しています

希望があなたを助けます

関連する問題