領収証発行サービス
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

58 行
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. parent::__construct();
  22. }
  23. protected function run(Request $request): JsonResponse
  24. {
  25. // 取得したユーザ情報を登録しログインを行う
  26. $param = $this->param;
  27. $user = User::whereEmail($param->email)->first();
  28. if ($user === null) {
  29. return $this->failedResponse();
  30. }
  31. if (Auth::attempt([
  32. 'email' => $param->email,
  33. 'password' => $param->password,
  34. ])) {
  35. $this->loginUser()->setCurrentContractId(null);
  36. $me = $this->me();
  37. if ($me !== null) {
  38. return $this->successResponse($me);
  39. }
  40. }
  41. return $this->failedResponse([], '認証失敗');
  42. }
  43. }