/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->status = User::STATUS_NOTACTIVATED; $b = $user->save(); $activationToken = new UserTokens(); $activationToken->user_id = $user->id; $activationToken->token_type = ETokenType::ACCOUNT_ACTIVATION; $activationToken->token = sha1(mt_rand(10000, 99999) . time() . $user->email); $activationToken->save(); $auth = Yii::$app->authManager; $userRole = $auth->getRole('user'); $auth->assign($userRole, $user->id); if ($b) { $x = new UserInfo(); $x->user_id = $user->id; $x->save(); EventService::createEvent(EEvent::ACCOUNT_CREATE(), new UserId($user->id)); $this->sendActivationMail($user, $activationToken->token); return $user; } } return null; }
public static function revokeToken(Token $token) { $token = UserTokens::findOne(['token' => $token->getToken()]); if ($token != null) { return $token->delete(); } else { return null; } }