public function actionActivate($token) { try { $token = Token::findByToken($token, Token::TYPE_REG); } catch (InvalidParamException $e) { return $this->render('opResult', ['title' => '帐号激活失败', 'status' => 'warning', 'msg' => $e->getMessage()]); } $user = $token->user; $token->status = Token::STATUS_USED; $token->save(false); if (!empty($token->ext) && $user->email !== $token->ext && User::findOne(['email' => $token->ext])) { return $this->render('opResult', ['title' => '帐号激活失败', 'status' => 'warning', 'msg' => '申请绑定邮箱[' . $token->ext . ']已被注册使用']); } if (intval($this->settings['admin_verify']) === 1) { $user->status = User::STATUS_ADMIN_VERIFY; $result = ['title' => '注册邮箱确认成功', 'status' => 'success', 'msg' => '注册邮箱确认成功,请等待管理员验证。']; } else { $user->status = User::STATUS_ACTIVE; $result = ['title' => '帐号激活成功', 'status' => 'success', 'msg' => '帐号激活成功,现在可以 ' . \yii\helpers\Html::a('登录', ['site/login']) . ' 发贴和回帖了。']; } $user->email = $token->ext; $user->save(false); return $this->render('opResult', $result); }
/** * Creates a form model given a token. * * @param string $token * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if token is empty or not valid */ public function __construct($token, $config = []) { $this->_token = Token::findByToken($token); parent::__construct($config); }