Answer the question
In order to leave comments, you need to log in
Why is there an error in Postman response when authorizing using YII2 token?
Good afternoon! Given the API on YII2, you will need to implement the frontend, but when you try to get responses in Posman, an error is displayed. For example, when logging in. Set {'login':'user15335551863','password':'pass'} and the corresponding url. The error is displayed:
In the User model:
public function login()
{
if($this->validate()) {
$user = self::findOne(['login' => $this->login]);
$user->token = Yii::$app->security->generateRandomString();
$user->save();
return [
'token' => $user->token
];
} else {
return [
'errors' => $this->errors
];
}
public function actionLogin()
{
$user = new User();
$user->load(Yii::$app->request->post(),'');
$user->scenario = 'login';
return $user->login();
}
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'POST /api/login' => 'user/login',
[
'class' => 'yii\rest\UrlRule',
'controller' => ['user'],
],
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question