Email Yii2无需电子邮件确认,用户可以';t登录
当用户注册时,系统向用户发送一封确认电子邮件,确认其工作正常,但没有任何电子邮件确认系统自动登录或用户可以登录。我如何解决这个问题,用户应该在登录前确认电子邮件,如果用户未确认,则电子邮件用户不能登录 我正在使用 我的LoginForm模型代码Email Yii2无需电子邮件确认,用户可以';t登录,email,yii,yii2,yii2-advanced-app,yii2-user,Email,Yii,Yii2,Yii2 Advanced App,Yii2 User,当用户注册时,系统向用户发送一封确认电子邮件,确认其工作正常,但没有任何电子邮件确认系统自动登录或用户可以登录。我如何解决这个问题,用户应该在登录前确认电子邮件,如果用户未确认,则电子邮件用户不能登录 我正在使用 我的LoginForm模型代码 namespace common\models; use Yii; use yii\base\Model; /** * Login form */ class LoginForm extends Model { public $email; pu
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')
];
}
}
在common/models/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]);
}
希望这将帮助您在common/models/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]);
}
希望这将帮助您因为默认情况下电子邮件状态为非活动状态,要更改此状态,您可以转到 common/models/user.php 并将规则函数从
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_INACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_DELETED]],
];
}
到
祝你好运这是因为默认情况下电子邮件状态为非活动状态,要更改此状态,您可以转到 common/models/user.php 并将规则函数从
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_INACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_DELETED]],
];
}
到
祝你好运在数据库的用户表中使用sataus=10它对我有效。在数据库的用户表中使用sataus=10它对我有效。将后端(用户表)的状态更改为10非常有效更改后端(用户表)的状态到10个像魔咒一样工作更新
用户
设置状态
='10'其中用户
id=[输入用户id];更新用户
设置状态
='10'其中用户
id=[输入用户id];