Adding a simpler form

This commit is contained in:
Chris Smith
2025-02-21 23:09:36 +01:00
parent 5f3d1359cf
commit d7341d02f5
2 changed files with 280 additions and 35 deletions

View File

@@ -7,6 +7,7 @@ use Firebase\JWT\JWT;
use Yii;
use yii\rest\Controller;
use yii\web\Response;
use yii\web\UnauthorizedHttpException;
class AuthController extends Controller
{
@@ -64,6 +65,7 @@ class AuthController extends Controller
$user = User::findOne(['email' => $data['email'] ?? null]);
if (!$user || !Yii::$app->security->validatePassword($data['password'], $user->password_hash)) {
throw new UnauthorizedHttpException();
return ['error' => 'Invalid credentials'];
}
// @todo not sure if it makes sense to generate an auth key each login via the API?
@@ -71,5 +73,5 @@ class AuthController extends Controller
$user->save();
return ['token' => $this->generateJwt($user)];
}
}e
}