mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Изменён алгоритм авторизации на использование jwt токенов
This commit is contained in:
@@ -14,7 +14,7 @@ return [
|
||||
'components' => [
|
||||
'user' => [
|
||||
'identityClass' => \common\models\Account::class,
|
||||
'enableAutoLogin' => true,
|
||||
'enableSession' => false,
|
||||
'loginUrl' => null,
|
||||
],
|
||||
'log' => [
|
||||
|
@@ -31,7 +31,7 @@ class AuthenticationController extends Controller {
|
||||
public function actionLogin() {
|
||||
$model = new LoginForm();
|
||||
$model->load(Yii::$app->request->post());
|
||||
if (!$model->login()) {
|
||||
if (($jwt = $model->login()) === false) {
|
||||
return [
|
||||
'success' => false,
|
||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||
@@ -40,6 +40,7 @@ class AuthenticationController extends Controller {
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'jwt' => $jwt,
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -44,16 +44,14 @@ class LoginForm extends BaseApiForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user using the provided username and password.
|
||||
*
|
||||
* @return boolean whether the user is logged in successfully
|
||||
* @return bool|string JWT с информацией об аккаунте
|
||||
*/
|
||||
public function login() {
|
||||
if (!$this->validate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Yii::$app->user->login($this->getAccount(), $this->rememberMe ? 3600 * 24 * 30 : 0);
|
||||
return $this->getAccount()->getJWT();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user