File manager - Edit - /var/www/html/ciosp/api/app/Http/Controllers/AuthController.php
Back
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Http\Services\AuthService; use Exception; use Illuminate\Support\Facades\Validator; class AuthController extends Controller { private AuthService $authService; public function __construct() { $this->authService = new AuthService(); } public function login(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'cpf' => 'required|string|max:255', 'password' => 'required|string' ]); if ($validator->fails()) { return response()->json( ['errors' => $validator->errors()], JsonResponse::HTTP_UNPROCESSABLE_ENTITY ); } try { $response = $this->authService->login($request); return response()->json($response->json(), $response->status()); } catch (Exception $e) { return response()->json([ $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } public function logout(Request $request): JsonResponse { $response = $this->authService->logout($request); return response()->json(null, $response->status()); } public function session(Request $request): JsonResponse { return response()->json($request->user, JsonResponse::HTTP_OK); } public function sendEmail(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'cpf' => 'required|string|max:255', 'email' => 'required|string|email|max:255' ]); if ($validator->fails()) { return response()->json( ['errors' => $validator->errors()], JsonResponse::HTTP_UNPROCESSABLE_ENTITY ); } try { $response = $this->authService->sendEmail($request); return response()->json($response->json(), $response->status()); } catch (Exception $e) { return response()->json([ $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } public function tokenValidator(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'code' => 'required|string|max:6', ]); if ($validator->fails()) { return response()->json( ['errors' => $validator->errors()], JsonResponse::HTTP_UNPROCESSABLE_ENTITY ); } try { $response = $this->authService->tokenValidator($request); return response($response->json(), $response->status()); } catch (Exception $e) { return response()->json([ $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } public function resetPassword(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'new_password' => [ 'required', 'string', 'min:6', 'regex:/^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]+$/', 'not_regex:/[áàãâäéèêëíìîïóòõôöúùûüçÇ;,.]/u', 'confirmed' ], 'code' => 'required|string|max:6', ]); if ($validator->fails()) { return response()->json( ['errors' => $validator->errors()], JsonResponse::HTTP_UNPROCESSABLE_ENTITY ); } try { $response = $this->authService->tokenValidator($request); return response($response->json(), $response->status()); } catch (Exception $e) { return response()->json([ $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings