Class frontend\models\VerifyEmailForm

Inheritancefrontend\models\VerifyEmailForm » yii\base\Model
Source Code https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/models/VerifyEmailForm.php

Public Properties

Hide inherited properties

Property Type Description Defined By
$token string frontend\models\VerifyEmailForm

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Creates a form model with given token. frontend\models\VerifyEmailForm
verifyEmail() Verify email frontend\models\VerifyEmailForm

Property Details

Hide inherited properties

$token public property
public string $token null

Method Details

Hide inherited methods

__construct() public method

Creates a form model with given token.

public void __construct ( $token, array $config = [] )
$token string
$config array

Name-value pairs that will be used to initialize the object properties

throws \yii\base\InvalidArgumentException

if token is empty or not valid

                public function __construct($token, array $config = [])
{
    if (empty($token) || !is_string($token)) {
        throw new InvalidArgumentException('Verify email token cannot be blank.');
    }
    $this->_user = User::findByVerificationToken($token);
    if (!$this->_user) {
        throw new InvalidArgumentException('Wrong verify email token.');
    }
    parent::__construct($config);
}

            
verifyEmail() public method

Verify email

public common\models\User|null verifyEmail ( )
return common\models\User|null

The saved model or null if saving fails

                public function verifyEmail()
{
    $user = $this->_user;
    $user->status = User::STATUS_ACTIVE;
    return $user->save(false) ? $user : null;
}