public function actionExchange() { /** @var User $user */ $user = \Yii::$app->user->identity; $token = AdminLoginToken::createToken($user->id); \Yii::$app->user->logout(); return [$user->id, $token->token]; }
public function actionLoginByToken($id, $token) { if (self::getAdminModule()->allowLoginViaToken == false) { throw new NotFoundHttpException(); } /** @var User $user */ $user = User::findOne($id); if ($user === null) { throw new NotFoundHttpException(); } $token = AdminLoginToken::compareToken($user->id, $token); if ($token === null) { throw new ForbiddenHttpException(); } $token->delete(); \Yii::$app->user->login($user); return $this->goHome(); }