You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
4 weeks ago
|
<?php
|
||
|
declare(strict_types = 1);
|
||
|
|
||
|
namespace App\Http\Controllers\Auth;
|
||
|
|
||
|
use App\Exceptions\GeneralException;
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use App\Http\Logics\Auth\AuthLogic;
|
||
|
use App\Http\Requests\Auth\LoginRequest;
|
||
|
use Illuminate\Auth\AuthenticationException;
|
||
|
use Illuminate\Http\JsonResponse;
|
||
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||
|
|
||
|
class AuthController extends Controller
|
||
|
{
|
||
|
protected AuthLogic $auth_logic;
|
||
|
|
||
|
/**
|
||
|
* AuthController constructor.
|
||
|
*/
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->auth_logic = new AuthLogic();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 登录接口
|
||
|
* @param LoginRequest $request
|
||
|
* @return JsonResponse
|
||
|
* @throws GeneralException
|
||
|
*/
|
||
|
public function login(LoginRequest $request): JsonResponse
|
||
|
{
|
||
|
$response = $this->auth_logic->login($request->code);
|
||
|
|
||
|
return jsonResponse(Response::HTTP_OK, 'success.', $response);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 未登录跳转
|
||
|
* @throws AuthenticationException
|
||
|
*/
|
||
|
public function unauthorized()
|
||
|
{
|
||
|
throw new AuthenticationException('Unauthorized.');
|
||
|
}
|
||
|
}
|