for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Http\Form;
use App\Model\User;
use yii\base\InvalidArgumentException;
use yii\base\Model;
class VerifyEmailForm extends Model
{
/**
* @var string
*/
public $token;
* @var User
private $user;
* Creates a form model with given token.
*
* @param string $token
* @param array $config name-value pairs that will be used to initialize the object properties
* @throws 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);
* Verify email
* @return 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;