領収証発行サービス
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

57 lines
1.2KB

  1. <?php
  2. namespace App\Http\Controllers\Web\Auth;
  3. use App\Http\Controllers\Web\WebController;
  4. use App\Models\User;
  5. use Illuminate\Http\JsonResponse;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Auth;
  8. class LoginController extends WebController
  9. {
  10. use Me;
  11. public function name(): string
  12. {
  13. return "ログイン";
  14. }
  15. public function description(): string
  16. {
  17. return "ログインを行う";
  18. }
  19. public function __construct(protected LoginParam $param)
  20. {
  21. }
  22. protected function run(Request $request): JsonResponse
  23. {
  24. // 取得したユーザ情報を登録しログインを行う
  25. $param = $this->param;
  26. $user = User::whereEmail($param->email)->first();
  27. if ($user === null) {
  28. return $this->failedResponse();
  29. }
  30. if (Auth::attempt([
  31. 'email' => $param->email,
  32. 'password' => $param->password,
  33. ])) {
  34. $this->loginUser()->setCurrentContractId(null);
  35. $me = $this->me();
  36. if ($me !== null) {
  37. return $this->successResponse($me);
  38. }
  39. }
  40. return $this->failedResponse([], '認証失敗');
  41. }
  42. }