From 61a47fb46645d259b42bcb4e96ae472a5f9ca3d5 Mon Sep 17 00:00:00 2001 From: antoniojrmota Date: Mon, 29 Jul 2024 17:24:41 -0300 Subject: [PATCH] refactor: change code for improved readability and maintainability --- ANSWER.md | 27 ++ LICENSE | 0 README.md | 0 app/Console/Kernel.php | 0 app/Exceptions/Handler.php | 0 .../Controllers/Auth/CpfLoginController.php | 152 ++++++++ app/Http/Controllers/Controller.php | 1 + app/Http/Controllers/UserController.php | 244 +++++++++++- app/Http/Kernel.php | 0 app/Http/Middleware/Authenticate.php | 14 + app/Http/Middleware/EncryptCookies.php | 0 .../PreventRequestsDuringMaintenance.php | 0 .../Middleware/RedirectIfAuthenticated.php | 0 app/Http/Middleware/TrimStrings.php | 0 app/Http/Middleware/TrustHosts.php | 0 app/Http/Middleware/TrustProxies.php | 0 app/Http/Middleware/ValidateSignature.php | 0 app/Http/Middleware/VerifyCsrfToken.php | 0 app/Http/Requests/LoginRequest.php | 44 +++ app/Http/Requests/UserCreateRequest.php | 51 +++ app/Http/Requests/UserUpdateRequest.php | 51 +++ app/Models/User.php | 2 + app/Providers/AppServiceProvider.php | 0 app/Providers/AuthServiceProvider.php | 0 app/Providers/BroadcastServiceProvider.php | 0 app/Providers/EventServiceProvider.php | 0 app/Providers/RouteServiceProvider.php | 0 bootstrap/app.php | 0 bootstrap/cache/.gitignore | 0 composer.json | 2 +- composer.lock | 42 +- config/app.php | 0 config/auth.php | 6 + config/broadcasting.php | 0 config/cache.php | 0 config/cors.php | 0 config/database.php | 0 config/filesystems.php | 0 config/hashing.php | 0 config/l5-swagger.php | 0 config/logging.php | 0 config/mail.php | 0 config/passport.php | 75 ++++ config/queue.php | 0 config/sanctum.php | 0 config/services.php | 0 config/session.php | 0 config/view.php | 0 database/.gitignore | 0 database/factories/UserFactory.php | 3 +- .../2014_10_12_000000_create_users_table.php | 0 ...000_create_password_reset_tokens_table.php | 0 ...1_000001_create_oauth_auth_codes_table.php | 31 ++ ...00002_create_oauth_access_tokens_table.php | 33 ++ ...0003_create_oauth_refresh_tokens_table.php | 29 ++ ...6_01_000004_create_oauth_clients_table.php | 35 ++ ...te_oauth_personal_access_clients_table.php | 28 ++ ..._08_19_000000_create_failed_jobs_table.php | 0 ...01_create_personal_access_tokens_table.php | 0 ...24_07_28_222942_add_cpf_to_users_table.php | 28 ++ ...23334_change_cpf_column_in_users_table.php | 28 ++ database/seeders/DatabaseSeeder.php | 0 database/seeders/UserTableSeeder.php | 7 +- docker-compose.yml | 0 e exec api php artisan tinker | 149 ++++++++ makefile | 0 package.json | 0 phpunit.xml | 0 public/.htaccess | 0 public/favicon.ico | 0 public/index.php | 0 public/robots.txt | 0 resources/css/app.css | 0 resources/js/app.js | 0 resources/js/bootstrap.js | 0 resources/views/vendor/l5-swagger/.gitkeep | 0 .../views/vendor/l5-swagger/index.blade.php | 0 .../views/vendor/passport/authorize.blade.php | 93 +++++ resources/views/welcome.blade.php | 0 routes/api.php | 19 + routes/channels.php | 0 routes/console.php | 0 routes/web.php | 0 storage/api-docs/api-docs.json | 359 +++++++++++++++++- storage/app/.gitignore | 0 storage/app/public/.gitignore | 0 storage/framework/.gitignore | 0 storage/framework/cache/.gitignore | 0 storage/framework/cache/data/.gitignore | 0 storage/framework/sessions/.gitignore | 0 storage/framework/testing/.gitignore | 0 storage/framework/views/.gitignore | 0 storage/logs/.gitignore | 0 tests/CreatesApplication.php | 0 tests/Feature/ExampleTest.php | 0 tests/TestCase.php | 0 tests/Unit/ExampleTest.php | 0 97 files changed, 1499 insertions(+), 54 deletions(-) create mode 100644 ANSWER.md mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 app/Console/Kernel.php mode change 100644 => 100755 app/Exceptions/Handler.php create mode 100644 app/Http/Controllers/Auth/CpfLoginController.php mode change 100644 => 100755 app/Http/Controllers/Controller.php mode change 100644 => 100755 app/Http/Controllers/UserController.php mode change 100644 => 100755 app/Http/Kernel.php mode change 100644 => 100755 app/Http/Middleware/Authenticate.php mode change 100644 => 100755 app/Http/Middleware/EncryptCookies.php mode change 100644 => 100755 app/Http/Middleware/PreventRequestsDuringMaintenance.php mode change 100644 => 100755 app/Http/Middleware/RedirectIfAuthenticated.php mode change 100644 => 100755 app/Http/Middleware/TrimStrings.php mode change 100644 => 100755 app/Http/Middleware/TrustHosts.php mode change 100644 => 100755 app/Http/Middleware/TrustProxies.php mode change 100644 => 100755 app/Http/Middleware/ValidateSignature.php mode change 100644 => 100755 app/Http/Middleware/VerifyCsrfToken.php create mode 100644 app/Http/Requests/LoginRequest.php create mode 100755 app/Http/Requests/UserCreateRequest.php create mode 100755 app/Http/Requests/UserUpdateRequest.php mode change 100644 => 100755 app/Models/User.php mode change 100644 => 100755 app/Providers/AppServiceProvider.php mode change 100644 => 100755 app/Providers/AuthServiceProvider.php mode change 100644 => 100755 app/Providers/BroadcastServiceProvider.php mode change 100644 => 100755 app/Providers/EventServiceProvider.php mode change 100644 => 100755 app/Providers/RouteServiceProvider.php mode change 100644 => 100755 bootstrap/app.php mode change 100644 => 100755 bootstrap/cache/.gitignore mode change 100644 => 100755 composer.json mode change 100644 => 100755 composer.lock mode change 100644 => 100755 config/app.php mode change 100644 => 100755 config/auth.php mode change 100644 => 100755 config/broadcasting.php mode change 100644 => 100755 config/cache.php mode change 100644 => 100755 config/cors.php mode change 100644 => 100755 config/database.php mode change 100644 => 100755 config/filesystems.php mode change 100644 => 100755 config/hashing.php mode change 100644 => 100755 config/l5-swagger.php mode change 100644 => 100755 config/logging.php mode change 100644 => 100755 config/mail.php create mode 100644 config/passport.php mode change 100644 => 100755 config/queue.php mode change 100644 => 100755 config/sanctum.php mode change 100644 => 100755 config/services.php mode change 100644 => 100755 config/session.php mode change 100644 => 100755 config/view.php mode change 100644 => 100755 database/.gitignore mode change 100644 => 100755 database/factories/UserFactory.php mode change 100644 => 100755 database/migrations/2014_10_12_000000_create_users_table.php mode change 100644 => 100755 database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php create mode 100644 database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php create mode 100644 database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php create mode 100644 database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php create mode 100644 database/migrations/2016_06_01_000004_create_oauth_clients_table.php create mode 100644 database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php mode change 100644 => 100755 database/migrations/2019_08_19_000000_create_failed_jobs_table.php mode change 100644 => 100755 database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php create mode 100755 database/migrations/2024_07_28_222942_add_cpf_to_users_table.php create mode 100755 database/migrations/2024_07_28_223334_change_cpf_column_in_users_table.php mode change 100644 => 100755 database/seeders/DatabaseSeeder.php mode change 100644 => 100755 database/seeders/UserTableSeeder.php mode change 100644 => 100755 docker-compose.yml create mode 100755 e exec api php artisan tinker mode change 100644 => 100755 makefile mode change 100644 => 100755 package.json mode change 100644 => 100755 phpunit.xml mode change 100644 => 100755 public/.htaccess mode change 100644 => 100755 public/favicon.ico mode change 100644 => 100755 public/index.php mode change 100644 => 100755 public/robots.txt mode change 100644 => 100755 resources/css/app.css mode change 100644 => 100755 resources/js/app.js mode change 100644 => 100755 resources/js/bootstrap.js mode change 100644 => 100755 resources/views/vendor/l5-swagger/.gitkeep mode change 100644 => 100755 resources/views/vendor/l5-swagger/index.blade.php create mode 100644 resources/views/vendor/passport/authorize.blade.php mode change 100644 => 100755 resources/views/welcome.blade.php mode change 100644 => 100755 routes/api.php mode change 100644 => 100755 routes/channels.php mode change 100644 => 100755 routes/console.php mode change 100644 => 100755 routes/web.php mode change 100644 => 100755 storage/api-docs/api-docs.json mode change 100644 => 100755 storage/app/.gitignore mode change 100644 => 100755 storage/app/public/.gitignore mode change 100644 => 100755 storage/framework/.gitignore mode change 100644 => 100755 storage/framework/cache/.gitignore mode change 100644 => 100755 storage/framework/cache/data/.gitignore mode change 100644 => 100755 storage/framework/sessions/.gitignore mode change 100644 => 100755 storage/framework/testing/.gitignore mode change 100644 => 100755 storage/framework/views/.gitignore mode change 100644 => 100755 storage/logs/.gitignore mode change 100644 => 100755 tests/CreatesApplication.php mode change 100644 => 100755 tests/Feature/ExampleTest.php mode change 100644 => 100755 tests/TestCase.php mode change 100644 => 100755 tests/Unit/ExampleTest.php diff --git a/ANSWER.md b/ANSWER.md new file mode 100644 index 0000000..6f3230b --- /dev/null +++ b/ANSWER.md @@ -0,0 +1,27 @@ +## Breve apresentação + +Olá, meu nome é Antônio, tenho 34 anos, atuei como Oficial Técnico Temporário no Exército Brasileiro nos últimos 7 anos, na função de Adjunto da Seção de Informática. + +@Autor: Antônio Júnior +@Linkedin: https://www.linkedin.com/in/antoniojrmota/ + +## refactoring details + + - Correção da porta local para 8080 + - Utilização de try-catch para tratamento da exceções + - Criação de campos como cpf + - Criptografia da senha dos usuários + - Criação da autenticação via cpf e senha + - Adicionado novas anotações nas rotas e métodos da Api + - Criação dos métodos Login e Logout e alteração de senha + - Configurações de segurança e token via passport + - Inclusão de validações e tratamento de mensagens + - Use de Seeds para popular o banco. + - Criação de novas migrations + - Atualização de tamanhos, formatos e definições de chave primária, chave única e relacionamentos, além do conhecimento prático em SQL. + - Criação do schema Authentication na api + - Crud criado tendo como parâmetro o cpf + - Criação dos Requests para tratar os campos + + Essas foram as principais modificações realizadas. + Agradeço a oportunidade e sucesso a todos. \ No newline at end of file diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php old mode 100644 new mode 100755 diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php old mode 100644 new mode 100755 diff --git a/app/Http/Controllers/Auth/CpfLoginController.php b/app/Http/Controllers/Auth/CpfLoginController.php new file mode 100644 index 0000000..7da6fb1 --- /dev/null +++ b/app/Http/Controllers/Auth/CpfLoginController.php @@ -0,0 +1,152 @@ +only('cpf', 'password'); + + if (Auth::attempt($credentials)) { + $user = Auth::user(); + $token = $user->createToken('elevensoft')->plainTextToken; + return response()->json(['token' => $token]); + } + + return response()->json(['error' => 'Credenciais inválidas.'], 401); + } + + /** + * @OA\Post( + * path="/logout", + * summary="Logout", + * description="Revoke the token.", + * tags={"Authentication"}, + * security={{"bearerAuth": {}}}, + * @OA\Response( + * response=200, + * description="Logout completed successfully.", + * @OA\JsonContent( + * @OA\Property(property="message", type="string", example="Logout completed successfully.") + * ) + * ), + * @OA\Response( + * response=401, + * description="Unauthenticated user.", + * @OA\JsonContent( + * @OA\Property(property="error", type="string", example="Unauthenticated user.") + * ) + * ) + * ) + */ + public function logout(Request $request) + { + $user = $request->user(); + + if (!$user) { + return response()->json(['error' => 'Usuário não autenticado.'], 401); + } + + $user->tokens()->delete(); + + return response()->json(['message' => 'Logout realizado com sucesso.']); + } + + /** + * @OA\Put( + * path="/login/{id}/password", + * summary="Atualizar senha do usuário", + * description="Altera a senha de um usuário específico.", + * tags={"Authentication"}, + * @OA\Parameter( + * name="id", + * in="path", + * required=true, + * @OA\Schema(type="integer"), + * description="ID do usuário" + * ), + * @OA\RequestBody( + * required=true, + * @OA\JsonContent( + * required={"password"}, + * @OA\Property(property="password", type="string", example="novaSenha123") + * ) + * ), + * @OA\Response( + * response=200, + * description="Senha atualizada com sucesso.", + * @OA\JsonContent( + * @OA\Property(property="message", type="string", example="Senha atualizada com sucesso.") + * ) + * ), + * @OA\Response( + * response=404, + * description="Usuário não encontrado.", + * @OA\JsonContent( + * @OA\Property(property="error", type="string", example="Usuário não encontrado.") + * ) + * ) + * ) + */ + public function updatePassword(Request $request, $id) + { + $request->validate([ + 'password' => 'required|string|min:8', + ]); + + $user = User::find($id); + if (!$user) { + return response()->json(['error' => 'Usuário não encontrado.'], 404); + } + + $user->password = Hash::make($request->input('password')); + $user->save(); + + return response()->json(['message' => 'Senha atualizada com sucesso.']); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php old mode 100644 new mode 100755 index 1870336..e64629f --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; + use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php old mode 100644 new mode 100755 index f4a5826..8958878 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -1,10 +1,18 @@ only([ - 'name', - 'email', - 'password', - ]); + try { + $validatedData = $request->validated(); + + $user = User::create([ + 'name' => $validatedData['name'], + 'email' => $validatedData['email'], + 'password' => bcrypt($validatedData['password']), + 'cpf' => $validatedData['cpf'], + ]); - return $this->user->create($data); + return response()->json(['message' => 'Usuário cadastrado com sucesso.','user' => $user], Response::HTTP_CREATED); + } catch (QueryException $e) { + return response()->json(['error' => 'Erro ao criar usuário.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } catch (Exception $e) { + return response()->json(['error' => 'Erro inesperado.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } } /** @@ -143,7 +160,7 @@ public function store(Request $request) * @return User * * @OA\Put( - * path="/users/{id}", + * path="/api/v1/users/{id}", * operationId="updateUser", * summary="Update a specific user", * tags={"Users"}, @@ -176,17 +193,25 @@ public function store(Request $request) * ) * ) */ - public function update(Request $request, User $user) + public function update(UserUpdateRequest $request, User $user) { - $data = $request->only([ - 'name', - 'email', - 'password', - ]); + try { + + $validatedData = $request->validated(); - $user->update($data); + if (isset($validatedData['password']) && !empty($validatedData['password'])) { + $validatedData['password'] = bcrypt($validatedData['password']); + } + + $user->update($validatedData); + $user->refresh(); - return $user; + return response()->json(['message' => 'Usuário atualizado com sucesso.', 'user' => $user], Response::HTTP_OK); + } catch (QueryException $e) { + return response()->json(['error' => 'Erro ao atualizar usuário.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } catch (Exception $e) { + return response()->json(['error' => 'Erro inesperado.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } } /** @@ -226,9 +251,192 @@ public function update(Request $request, User $user) */ public function destroy(User $user) { - $user->delete(); + try { + $user->delete(); + return response()->json(['message' => 'Usuário excluído com sucesso.'], Response::HTTP_OK); + } catch (ModelNotFoundException $e) { + return response()->json(['error' => 'Usuário não encontrado.'], Response::HTTP_NOT_FOUND); + } catch (QueryException $e) { + return response()->json(['error' => 'Erro ao excluir usuário.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } catch (Exception $e) { + return response()->json(['error' => 'Erro inesperado.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Show a specific user resource by CPF + * + * @return User + * + * @OA\Get( + * path="/users/cpf/{cpf}", + * operationId="showUserByCpf", + * summary="Show a specific user by CPF", + * tags={"Users"}, + * description="Returns a specific user by CPF", + * security={ + * {"bearerAuth": {}} + * }, + * @OA\Parameter( + * name="cpf", + * description="User CPF", + * required=true, + * in="path", + * @OA\Schema(type="string") + * ), + * @OA\Response( + * response=200, + * description="Successful operation", + * @OA\JsonContent(ref="#/components/schemas/User") + * ), + * @OA\Response( + * response=404, + * description="User not found" + * ), + * @OA\Response( + * response=401, + * description="Unauthenticated", + * ), + * @OA\Response( + * response=403, + * description="Forbidden" + * ) + * ) + */ + public function showByCpf(string $cpf) + { + try { + $user = User::where('cpf', $cpf)->firstOrFail(); + return response()->json($user, Response::HTTP_OK); + } catch (ModelNotFoundException $e) { + return response()->json(['error' => 'Usuário não encontrado.'], Response::HTTP_NOT_FOUND); + } catch (Exception $e) { + return response()->json(['error' => 'Erro inesperado.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } - return $user; + /** + * Update a specific user resource by CPF + * + * @return User + * + * @OA\Put( + * path="/users/cpf/{cpf}", + * operationId="updateUserByCpf", + * summary="Update a specific user by CPF", + * tags={"Users"}, + * description="Updates a specific user by CPF", + * security={ + * {"bearerAuth": {}} + * }, + * @OA\Parameter( + * name="cpf", + * description="User CPF", + * required=true, + * in="path", + * @OA\Schema(type="string") + * ), + * @OA\RequestBody( + * required=true, + * @OA\JsonContent(ref="#/components/schemas/User") + * ), + * @OA\Response( + * response=200, + * description="Successful operation", + * @OA\JsonContent(ref="#/components/schemas/User") + * ), + * @OA\Response( + * response=404, + * description="User not found" + * ), + * @OA\Response( + * response=401, + * description="Unauthenticated", + * ), + * @OA\Response( + * response=403, + * description="Forbidden" + * ) + * ) + */ + public function updateByCpf(UserUpdateRequest $request, string $cpf) + { + try { + $validatedData = $request->validated(); + + if (isset($validatedData['password']) && !empty($validatedData['password'])) { + $validatedData['password'] = bcrypt($validatedData['password']); + } + + $user = User::where('cpf', $cpf)->firstOrFail(); + $user->update($validatedData); + $user->refresh(); + + return response()->json($user, Response::HTTP_OK); + } catch (ModelNotFoundException $e) { + return response()->json(['error' => 'Usuário não encontrado.'], Response::HTTP_NOT_FOUND); + } catch (QueryException $e) { + return response()->json(['error' => 'Erro ao atualizar usuário.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } catch (Exception $e) { + return response()->json(['error' => 'Erro inesperado.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Remove a specific user resource by CPF + * + * @return Response + * + * @OA\Delete( + * path="/users/cpf/{cpf}", + * operationId="deleteUserByCpf", + * summary="Delete a specific user by CPF", + * tags={"Users"}, + * description="Deletes a specific user by CPF", + * security={ + * {"bearerAuth": {}} + * }, + * @OA\Parameter( + * name="cpf", + * description="User CPF", + * required=true, + * in="path", + * @OA\Schema(type="string") + * ), + * @OA\Response( + * response=200, + * description="Successful operation", + * @OA\JsonContent( + * @OA\Property(property="message", type="string") + * ) + * ), + * @OA\Response( + * response=404, + * description="User not found" + * ), + * @OA\Response( + * response=401, + * description="Unauthenticated", + * ), + * @OA\Response( + * response=403, + * description="Forbidden" + * ) + * ) + */ + public function destroyByCpf(string $cpf) + { + try { + $user = User::where('cpf', $cpf)->firstOrFail(); + $user->delete(); + return response()->json(['message' => 'Usuário excluído com sucesso.'], Response::HTTP_OK); + } catch (ModelNotFoundException $e) { + return response()->json(['error' => 'Usuário não encontrado.'], Response::HTTP_NOT_FOUND); + } catch (QueryException $e) { + return response()->json(['error' => 'Erro ao excluir usuário.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } catch (Exception $e) { + return response()->json(['error' => 'Erro inesperado.'], Response::HTTP_INTERNAL_SERVER_ERROR); + } } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php old mode 100644 new mode 100755 index d4ef644..aa054fb --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -4,9 +4,23 @@ use Illuminate\Auth\Middleware\Authenticate as Middleware; use Illuminate\Http\Request; +use Closure; +use Illuminate\Support\Facades\Auth; class Authenticate extends Middleware { + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @param string|null ...$guards + * @return mixed + */ + public function handle($request, Closure $next, ...$guards) + { + return parent::handle($request, $next, ...$guards); + } /** * Get the path the user should be redirected to when they are not authenticated. */ diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/TrimStrings.php b/app/Http/Middleware/TrimStrings.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/TrustHosts.php b/app/Http/Middleware/TrustHosts.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/ValidateSignature.php b/app/Http/Middleware/ValidateSignature.php old mode 100644 new mode 100755 diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php old mode 100644 new mode 100755 diff --git a/app/Http/Requests/LoginRequest.php b/app/Http/Requests/LoginRequest.php new file mode 100644 index 0000000..14a1053 --- /dev/null +++ b/app/Http/Requests/LoginRequest.php @@ -0,0 +1,44 @@ +|string> + */ + public function rules(): array + { + return [ + 'cpf' => 'required', 'string', + 'password' => 'required|string', + ]; + } + + /** + * Get the custom messages for the validation rules. + * + * @return array + */ + public function messages() + { + return [ + 'cpf.required' => 'O CPF é obrigatório.', + 'cpf.string' => 'O CPF deve ser uma string.', + 'password.required' => 'A senha é obrigatória.', + 'password.string' => 'A senha deve ser uma string.', + ]; + } +} diff --git a/app/Http/Requests/UserCreateRequest.php b/app/Http/Requests/UserCreateRequest.php new file mode 100755 index 0000000..f3b137c --- /dev/null +++ b/app/Http/Requests/UserCreateRequest.php @@ -0,0 +1,51 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|max:255', + 'email' => 'required|email|unique:users,email', + 'password' => 'required|string|min:8|confirmed', + 'cpf' => 'required|string|size:11|unique:users,cpf', + ]; + } + /** + * Get custom error messages for validation rules. + * + * @return array + */ + public function messages() + { + return [ + 'name.required' => 'O nome é obrigatório.', + 'email.required' => 'O e-mail é obrigatório.', + 'email.email' => 'O e-mail deve ser um endereço de e-mail válido.', + 'email.unique' => 'Este e-mail já está em uso.', + 'password.required' => 'A senha é obrigatória.', + 'password.min' => 'A senha deve ter pelo menos 8 caracteres.', + 'password.confirmed' => 'A confirmação da senha não corresponde.', + 'cpf.required' => 'O CPF é obrigatório.', + 'cpf.size' => 'O CPF deve ter exatamente 11 dígitos.', + 'cpf.unique' => 'Este CPF já está em uso.', + ]; + } +} diff --git a/app/Http/Requests/UserUpdateRequest.php b/app/Http/Requests/UserUpdateRequest.php new file mode 100755 index 0000000..d07d512 --- /dev/null +++ b/app/Http/Requests/UserUpdateRequest.php @@ -0,0 +1,51 @@ +|string> + */ + public function rules(): array + { + $userId = $this->route('user'); + + return [ + 'name' => 'sometimes|required|string|max:255', + 'email' => 'sometimes|required|email|unique:users,email,' . $userId, + 'password' => 'nullable|string|min:8|confirmed', + ]; + } + + /** + * Get custom error messages for validation rules. + * + * @return array + */ + public function messages() + { + return [ + 'name.required' => 'O nome é obrigatório.', + 'name.string' => 'O nome deve ser uma string.', + 'name.max' => 'O nome não pode ter mais de 255 caracteres.', + 'email.required' => 'O e-mail é obrigatório.', + 'email.email' => 'O e-mail deve ser um endereço de e-mail válido.', + 'email.unique' => 'Este e-mail já está em uso.', + 'password.min' => 'A senha deve ter pelo menos 8 caracteres.', + 'password.confirmed' => 'A confirmação da senha não corresponde.', + ]; + } +} diff --git a/app/Models/User.php b/app/Models/User.php old mode 100644 new mode 100755 index 8ceeafd..2f316f4 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -28,8 +28,10 @@ class User extends Authenticatable */ protected $fillable = [ 'name', + 'cpf', 'email', 'password', + 'status', ]; /** diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php old mode 100644 new mode 100755 diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php old mode 100644 new mode 100755 diff --git a/app/Providers/BroadcastServiceProvider.php b/app/Providers/BroadcastServiceProvider.php old mode 100644 new mode 100755 diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php old mode 100644 new mode 100755 diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php old mode 100644 new mode 100755 diff --git a/bootstrap/app.php b/bootstrap/app.php old mode 100644 new mode 100755 diff --git a/bootstrap/cache/.gitignore b/bootstrap/cache/.gitignore old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 69f367d..e4f009a --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "darkaonline/l5-swagger": "^8.5", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.10", - "laravel/passport": "^11.10", + "laravel/passport": "^12.2", "laravel/sanctum": "^3.3", "laravel/tinker": "^2.8" }, diff --git a/composer.lock b/composer.lock old mode 100644 new mode 100755 index 60d118a..d5b31ac --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67440c672c599347adcdf498832467fd", + "content-hash": "7358cddcd08d6b80b8eb472057d4b418", "packages": [ { "name": "brick/math", @@ -1539,48 +1539,46 @@ }, { "name": "laravel/passport", - "version": "v11.10.5", + "version": "v12.2.1", "source": { "type": "git", "url": "https://github.com/laravel/passport.git", - "reference": "4d81207941d6efc198857847d9e4c17520f28d75" + "reference": "795bbb406c8f10167df6062032de803bd7d686f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/passport/zipball/4d81207941d6efc198857847d9e4c17520f28d75", - "reference": "4d81207941d6efc198857847d9e4c17520f28d75", + "url": "https://api.github.com/repos/laravel/passport/zipball/795bbb406c8f10167df6062032de803bd7d686f2", + "reference": "795bbb406c8f10167df6062032de803bd7d686f2", "shasum": "" }, "require": { "ext-json": "*", "firebase/php-jwt": "^6.4", - "illuminate/auth": "^9.0|^10.0", - "illuminate/console": "^9.0|^10.0", - "illuminate/container": "^9.0|^10.0", - "illuminate/contracts": "^9.0|^10.0", - "illuminate/cookie": "^9.0|^10.0", - "illuminate/database": "^9.0|^10.0", - "illuminate/encryption": "^9.0|^10.0", - "illuminate/http": "^9.0|^10.0", - "illuminate/support": "^9.0|^10.0", + "illuminate/auth": "^9.21|^10.0|^11.0", + "illuminate/console": "^9.21|^10.0|^11.0", + "illuminate/container": "^9.21|^10.0|^11.0", + "illuminate/contracts": "^9.21|^10.0|^11.0", + "illuminate/cookie": "^9.21|^10.0|^11.0", + "illuminate/database": "^9.21|^10.0|^11.0", + "illuminate/encryption": "^9.21|^10.0|^11.0", + "illuminate/http": "^9.21|^10.0|^11.0", + "illuminate/support": "^9.21|^10.0|^11.0", "lcobucci/jwt": "^4.3|^5.0", "league/oauth2-server": "^8.5.3", "nyholm/psr7": "^1.5", "php": "^8.0", "phpseclib/phpseclib": "^2.0|^3.0", - "symfony/psr-http-message-bridge": "^2.1" + "symfony/console": "^6.0|^7.0", + "symfony/psr-http-message-bridge": "^2.1|^6.0|^7.0" }, "require-dev": { "mockery/mockery": "^1.0", - "orchestra/testbench": "^7.31|^8.11", + "orchestra/testbench": "^7.35|^8.14|^9.0", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.3|^10.5" }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "11.x-dev" - }, "laravel": { "providers": [ "Laravel\\Passport\\PassportServiceProvider" @@ -1613,7 +1611,7 @@ "issues": "https://github.com/laravel/passport/issues", "source": "https://github.com/laravel/passport" }, - "time": "2024-02-09T16:27:49+00:00" + "time": "2024-07-10T19:25:36+00:00" }, { "name": "laravel/prompts", @@ -9524,5 +9522,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/config/app.php b/config/app.php old mode 100644 new mode 100755 diff --git a/config/auth.php b/config/auth.php old mode 100644 new mode 100755 index 9548c15..9595b2e --- a/config/auth.php +++ b/config/auth.php @@ -41,6 +41,12 @@ 'provider' => 'users', ], ], + + 'api' => [ + 'driver' => 'token', + 'provider' => 'users', + 'hash' => false, + ], /* |-------------------------------------------------------------------------- diff --git a/config/broadcasting.php b/config/broadcasting.php old mode 100644 new mode 100755 diff --git a/config/cache.php b/config/cache.php old mode 100644 new mode 100755 diff --git a/config/cors.php b/config/cors.php old mode 100644 new mode 100755 diff --git a/config/database.php b/config/database.php old mode 100644 new mode 100755 diff --git a/config/filesystems.php b/config/filesystems.php old mode 100644 new mode 100755 diff --git a/config/hashing.php b/config/hashing.php old mode 100644 new mode 100755 diff --git a/config/l5-swagger.php b/config/l5-swagger.php old mode 100644 new mode 100755 diff --git a/config/logging.php b/config/logging.php old mode 100644 new mode 100755 diff --git a/config/mail.php b/config/mail.php old mode 100644 new mode 100755 diff --git a/config/passport.php b/config/passport.php new file mode 100644 index 0000000..ae902d8 --- /dev/null +++ b/config/passport.php @@ -0,0 +1,75 @@ + 'web', + + /* + |-------------------------------------------------------------------------- + | Encryption Keys + |-------------------------------------------------------------------------- + | + | Passport uses encryption keys while generating secure access tokens for + | your application. By default, the keys are stored as local files but + | can be set via environment variables when that is more convenient. + | + */ + + 'private_key' => env('PASSPORT_PRIVATE_KEY'), + + 'public_key' => env('PASSPORT_PUBLIC_KEY'), + + /* + |-------------------------------------------------------------------------- + | Passport Database Connection + |-------------------------------------------------------------------------- + | + | By default, Passport's models will utilize your application's default + | database connection. If you wish to use a different connection you + | may specify the configured name of the database connection here. + | + */ + + 'connection' => env('PASSPORT_CONNECTION'), + + /* + |-------------------------------------------------------------------------- + | Client UUIDs + |-------------------------------------------------------------------------- + | + | By default, Passport uses auto-incrementing primary keys when assigning + | IDs to clients. However, if Passport is installed using the provided + | --uuids switch, this will be set to "true" and UUIDs will be used. + | + */ + + 'client_uuids' => false, + + /* + |-------------------------------------------------------------------------- + | Personal Access Client + |-------------------------------------------------------------------------- + | + | If you enable client hashing, you should set the personal access client + | ID and unhashed secret within your environment file. The values will + | get used while issuing fresh personal access tokens to your users. + | + */ + + 'personal_access_client' => [ + 'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'), + 'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'), + ], + +]; diff --git a/config/queue.php b/config/queue.php old mode 100644 new mode 100755 diff --git a/config/sanctum.php b/config/sanctum.php old mode 100644 new mode 100755 diff --git a/config/services.php b/config/services.php old mode 100644 new mode 100755 diff --git a/config/session.php b/config/session.php old mode 100644 new mode 100755 diff --git a/config/view.php b/config/view.php old mode 100644 new mode 100755 diff --git a/database/.gitignore b/database/.gitignore old mode 100644 new mode 100755 diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php old mode 100644 new mode 100755 index 584104c..f69e6ab --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -27,8 +27,9 @@ public function definition(): array 'name' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), - 'password' => static::$password ??= Hash::make('password'), + 'password' => Hash::make('password123'), 'remember_token' => Str::random(10), + 'cpf' => $this->faker->unique()->numerify('###########'), ]; } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php old mode 100644 new mode 100755 diff --git a/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php old mode 100644 new mode 100755 diff --git a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php new file mode 100644 index 0000000..7b93b40 --- /dev/null +++ b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php @@ -0,0 +1,31 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->index(); + $table->unsignedBigInteger('client_id'); + $table->text('scopes')->nullable(); + $table->boolean('revoked'); + $table->dateTime('expires_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_auth_codes'); + } +}; diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php new file mode 100644 index 0000000..598798e --- /dev/null +++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -0,0 +1,33 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->unsignedBigInteger('client_id'); + $table->string('name')->nullable(); + $table->text('scopes')->nullable(); + $table->boolean('revoked'); + $table->timestamps(); + $table->dateTime('expires_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_access_tokens'); + } +}; diff --git a/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php new file mode 100644 index 0000000..b007904 --- /dev/null +++ b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php @@ -0,0 +1,29 @@ +string('id', 100)->primary(); + $table->string('access_token_id', 100)->index(); + $table->boolean('revoked'); + $table->dateTime('expires_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_refresh_tokens'); + } +}; diff --git a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php new file mode 100644 index 0000000..776ccfa --- /dev/null +++ b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->string('name'); + $table->string('secret', 100)->nullable(); + $table->string('provider')->nullable(); + $table->text('redirect'); + $table->boolean('personal_access_client'); + $table->boolean('password_client'); + $table->boolean('revoked'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_clients'); + } +}; diff --git a/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php new file mode 100644 index 0000000..7c9d1e8 --- /dev/null +++ b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php @@ -0,0 +1,28 @@ +bigIncrements('id'); + $table->unsignedBigInteger('client_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_personal_access_clients'); + } +}; diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php old mode 100644 new mode 100755 diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php old mode 100644 new mode 100755 diff --git a/database/migrations/2024_07_28_222942_add_cpf_to_users_table.php b/database/migrations/2024_07_28_222942_add_cpf_to_users_table.php new file mode 100755 index 0000000..422af08 --- /dev/null +++ b/database/migrations/2024_07_28_222942_add_cpf_to_users_table.php @@ -0,0 +1,28 @@ +string('cpf')->unique()->after('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('cpf'); + }); + } +}; diff --git a/database/migrations/2024_07_28_223334_change_cpf_column_in_users_table.php b/database/migrations/2024_07_28_223334_change_cpf_column_in_users_table.php new file mode 100755 index 0000000..fc449f0 --- /dev/null +++ b/database/migrations/2024_07_28_223334_change_cpf_column_in_users_table.php @@ -0,0 +1,28 @@ +char('cpf', 11)->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->string('cpf')->change(); + }); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php old mode 100644 new mode 100755 diff --git a/database/seeders/UserTableSeeder.php b/database/seeders/UserTableSeeder.php old mode 100644 new mode 100755 index 00fec09..84ce77d --- a/database/seeders/UserTableSeeder.php +++ b/database/seeders/UserTableSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use Illuminate\Database\Seeder; +use App\Models\User; class UserTableSeeder extends Seeder { @@ -11,10 +12,6 @@ class UserTableSeeder extends Seeder */ public function run(): void { - \App\Models\User::factory()->create([ - 'name' => 'example', - 'email' => 'example@elevensoft.dev', - 'password' => bcrypt('password') - ]); + User::factory()->count(50)->create(); } } diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 diff --git a/e exec api php artisan tinker b/e exec api php artisan tinker new file mode 100755 index 0000000..4e44f5f --- /dev/null +++ b/e exec api php artisan tinker @@ -0,0 +1,149 @@ += Illuminate\Database\Eloquent\Collection {#6113 + all: [ + App\Models\User {#6115 + id: 1, + name: "Nyasia Renner V", + cpf: "17278197815", + email: "meta.pollich@example.com", + email_verified_at: "2024-07-28 23:14:08", + #password: "$2y$12$gMMQoKZjtLCw2CCp9xvAreqXe7gWiR1FNbI33EZwMauK5q1goR7PS", + #remember_token: "rDQlOBDd5Z", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6116 + id: 2, + name: "Mr. Lincoln Hagenes", + cpf: "51247502616", + email: "jbruen@example.com", + email_verified_at: "2024-07-28 23:14:09", + #password: "$2y$12$0Hiz8J35m0D5x4XbPOetleDrMSbMYTVbn6/SNpuzmItLKODJb01Zu", + #remember_token: "u0DmYsRuxG", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6117 + id: 3, + name: "Miss Rachel Corkery", + cpf: "65503278063", + email: "cecile.collins@example.org", + email_verified_at: "2024-07-28 23:14:09", + #password: "$2y$12$uFzDFkrfzXxQoDxYbLD4.u3OOpXnsik1XoCT/vGJ2Pd0gRC8aQX6y", + #remember_token: "7TyHZNDkO7", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6118 + id: 4, + name: "Mr. Oscar Ankunding", + cpf: "74559584861", + email: "eichmann.karina@example.org", + email_verified_at: "2024-07-28 23:14:10", + #password: "$2y$12$6J4xENPWVeW/QdUwtzdSWOD9uA9X/EpYvkMrryFX60co5xRqeamy2", + #remember_token: "6qfHBWDGXp", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6119 + id: 5, + name: "Micaela Rutherford", + cpf: "63031328396", + email: "destiney49@example.org", + email_verified_at: "2024-07-28 23:14:10", + #password: "$2y$12$7gu7iPKRNnnXY.CdVJp2DOuL9P4CfWH67Wyj8HA/CcK5awU3j85Fu", + #remember_token: "hsd066YtA9", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6120 + id: 6, + name: "Jeanne Glover Sr.", + cpf: "09696951778", + email: "hal28@example.net", + email_verified_at: "2024-07-28 23:14:10", + #password: "$2y$12$iI2DC8xi9doJLe.x5X/Ah.aICKPtJckKjdnp7ijpQdzB1V0NF.KdC", + #remember_token: "hzH7wF50Jf", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6121 + id: 7, + name: "Favian Christiansen", + cpf: "15772191457", + email: "nona.oconner@example.com", + email_verified_at: "2024-07-28 23:14:11", + #password: "$2y$12$Z4sohoJBi2UnDkJEH/nFy.Q3c2Cf5cHdaLNfvJ3HUcVEMF8Cark5q", + #remember_token: "XvefYjV6ss", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6122 + id: 8, + name: "Mitchel Mraz", + cpf: "87876179067", + email: "schulist.harvey@example.net", + email_verified_at: "2024-07-28 23:14:11", + #password: "$2y$12$3G/KPp8sL1ciTNaWkyfBKe8u3vRLiT/6M6wWItizSMRYKwKUyuZme", + #remember_token: "WtovEYawpq", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6123 + id: 9, + name: "Heath Waters", + cpf: "95784347150", + email: "harry.marvin@example.com", + email_verified_at: "2024-07-28 23:14:12", + #password: "$2y$12$VIMsaekbNeYbyClkJLA/aeFDKLZJlBKurrgXECYmHpqg34oCKeKtW", + #remember_token: "p6ZulNubRv", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6124 + id: 10, + name: "Minnie Kerluke DDS", + cpf: "51456161170", + email: "schmeler.lindsay@example.com", + email_verified_at: "2024-07-28 23:14:12", + #password: "$2y$12$uL9XiEzkQ9T6yDedxvIJdeUGsOxF3bXyeDZDgIcoutGJU7ayCXakG", + #remember_token: "DLLSLHBG65", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6125 + id: 11, + name: "Alexa Reichert", + cpf: "23961943836", + email: "npollich@example.net", + email_verified_at: "2024-07-28 23:14:12", + #password: "$2y$12$J3Zf8voWsrufH1aYDAywO..0c/ol.sIXvwBILFurs8tgVAYTzI9vC", + #remember_token: "mPmCQki7Pj", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6126 + id: 12, + name: "Dr. Gabriel Windler III", + cpf: "55128163643", + email: "gaylord.viola@example.com", + email_verified_at: "2024-07-28 23:14:13", + #password: "$2y$12$VVbbUafAPbokyFx8GQLHQ.62bfat25Tt1sEJrBeQjQ5wjtRwJdGNK", + #remember_token: "cz9AqdIJtq", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6127 + id: 13, + name: "Miss June Schmeler", + cpf: "27527360484", + email: "djast@example.com", + email_verified_at: "2024-07-28 23:14:13", + #password: "$2y$12$1kWMznc3nPXCn.JjLsmpUet/JscGwj6tj8lyt7wAr3azzD1vTNjfO", + #remember_token: "pJ655GC5hW", + created_at: "2024-07-28 23:14:28", + updated_at: "2024-07-28 23:14:28", + }, + App\Models\User {#6128 + id: 14, + name: "Hans Wolff", + cpf[39 \ No newline at end of file diff --git a/makefile b/makefile old mode 100644 new mode 100755 diff --git a/package.json b/package.json old mode 100644 new mode 100755 diff --git a/phpunit.xml b/phpunit.xml old mode 100644 new mode 100755 diff --git a/public/.htaccess b/public/.htaccess old mode 100644 new mode 100755 diff --git a/public/favicon.ico b/public/favicon.ico old mode 100644 new mode 100755 diff --git a/public/index.php b/public/index.php old mode 100644 new mode 100755 diff --git a/public/robots.txt b/public/robots.txt old mode 100644 new mode 100755 diff --git a/resources/css/app.css b/resources/css/app.css old mode 100644 new mode 100755 diff --git a/resources/js/app.js b/resources/js/app.js old mode 100644 new mode 100755 diff --git a/resources/js/bootstrap.js b/resources/js/bootstrap.js old mode 100644 new mode 100755 diff --git a/resources/views/vendor/l5-swagger/.gitkeep b/resources/views/vendor/l5-swagger/.gitkeep old mode 100644 new mode 100755 diff --git a/resources/views/vendor/l5-swagger/index.blade.php b/resources/views/vendor/l5-swagger/index.blade.php old mode 100644 new mode 100755 diff --git a/resources/views/vendor/passport/authorize.blade.php b/resources/views/vendor/passport/authorize.blade.php new file mode 100644 index 0000000..d0a4a99 --- /dev/null +++ b/resources/views/vendor/passport/authorize.blade.php @@ -0,0 +1,93 @@ + + + + + + + + {{ config('app.name') }} - Authorization + + + + + + + +
+
+
+
+
+ Authorization Request +
+
+ +

{{ $client->name }} is requesting permission to access your account.

+ + + @if (count($scopes) > 0) +
+

This application will be able to:

+ +
    + @foreach ($scopes as $scope) +
  • {{ $scope->description }}
  • + @endforeach +
+
+ @endif + +
+ +
+ @csrf + + + + + +
+ + +
+ @csrf + @method('DELETE') + + + + + +
+
+
+
+
+
+
+ + diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php old mode 100644 new mode 100755 diff --git a/routes/api.php b/routes/api.php old mode 100644 new mode 100755 index 03a44e1..3386c90 --- a/routes/api.php +++ b/routes/api.php @@ -2,6 +2,9 @@ use App\Http\Controllers\UserController; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\Auth\CpfLoginController; +use Illuminate\Http\Request; + /* |-------------------------------------------------------------------------- @@ -13,4 +16,20 @@ | be assigned to the "api" middleware group. Make something great! | */ + +Route::middleware('auth:api')->get('/user', function (Request $request) { + return $request->user(); +}); + + +Route::post('/login', [CpfLoginController::class, 'login']); +Route::post('/logout', [CpfLoginController::class, 'logout'])->name('logout'); +Route::put('login/{id}/password', [CpfLoginController::class, 'updatePassword']); + Route::apiResource('users', UserController::class); + +// Rotas personalizadas para CPF +Route::get('users/cpf/{cpf}', [UserController::class, 'showByCpf']); +Route::put('users/cpf/{cpf}', [UserController::class, 'updateByCpf']); +Route::delete('users/cpf/{cpf}', [UserController::class, 'destroyByCpf']); + diff --git a/routes/channels.php b/routes/channels.php old mode 100644 new mode 100755 diff --git a/routes/console.php b/routes/console.php old mode 100644 new mode 100755 diff --git a/routes/web.php b/routes/web.php old mode 100644 new mode 100755 diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json old mode 100644 new mode 100755 index 244d983..9d14891 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -15,6 +15,197 @@ } ], "paths": { + "/login": { + "post": { + "tags": [ + "Authentication" + ], + "summary": "Login", + "description": "Authenticates a user using CPF and password.", + "operationId": "d2cf13f3995c837113eef1c8db5682a0", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "required": [ + "cpf", + "password" + ], + "properties": { + "cpf": { + "type": "string", + "example": "12345678900" + }, + "password": { + "type": "string", + "example": "password123" + } + }, + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "User successfully authenticated.", + "content": { + "application/json": { + "schema": { + "properties": { + "token": { + "type": "string", + "example": "your_jwt_token" + } + }, + "type": "object" + } + } + } + }, + "401": { + "description": "Invalid credentials.", + "content": { + "application/json": { + "schema": { + "properties": { + "error": { + "type": "string", + "example": "As credenciais fornecidas são inválidas." + } + }, + "type": "object" + } + } + } + } + } + } + }, + "/logout": { + "post": { + "tags": [ + "Authentication" + ], + "summary": "Logout", + "description": "Revoke the token.", + "operationId": "3e5c3236692494d2ae2efd0da477295d", + "responses": { + "200": { + "description": "Logout completed successfully.", + "content": { + "application/json": { + "schema": { + "properties": { + "message": { + "type": "string", + "example": "Logout completed successfully." + } + }, + "type": "object" + } + } + } + }, + "401": { + "description": "Unauthenticated user.", + "content": { + "application/json": { + "schema": { + "properties": { + "error": { + "type": "string", + "example": "Unauthenticated user." + } + }, + "type": "object" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, + "/login/{id}/password": { + "put": { + "tags": [ + "Authentication" + ], + "summary": "Atualizar senha do usuário", + "description": "Altera a senha de um usuário específico.", + "operationId": "980a8350c48272ed48f82176d1b04b2e", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID do usuário", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "required": [ + "password" + ], + "properties": { + "password": { + "type": "string", + "example": "novaSenha123" + } + }, + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "Senha atualizada com sucesso.", + "content": { + "application/json": { + "schema": { + "properties": { + "message": { + "type": "string", + "example": "Senha atualizada com sucesso." + } + }, + "type": "object" + } + } + } + }, + "404": { + "description": "Usuário não encontrado.", + "content": { + "application/json": { + "schema": { + "properties": { + "error": { + "type": "string", + "example": "Usuário não encontrado." + } + }, + "type": "object" + } + } + } + } + } + } + }, "/users": { "get": { "tags": [ @@ -132,6 +323,47 @@ } ] }, + "delete": { + "tags": [ + "Users" + ], + "summary": "Delete a specific user", + "description": "Deletes a specific user", + "operationId": "deleteUser", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "User ID", + "required": true + } + ], + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, + "401": { + "description": "Unauthenticated" + }, + "403": { + "description": "Forbidden" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, + "/api/v1/users/{id}": { "put": { "tags": [ "Users" @@ -180,22 +412,82 @@ "bearerAuth": [] } ] + } + }, + "/users/cpf/{cpf}": { + "get": { + "tags": [ + "Users" + ], + "summary": "Show a specific user by CPF", + "description": "Returns a specific user by CPF", + "operationId": "showUserByCpf", + "parameters": [ + { + "name": "cpf", + "in": "path", + "description": "User CPF", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, + "404": { + "description": "User not found" + }, + "401": { + "description": "Unauthenticated" + }, + "403": { + "description": "Forbidden" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] }, - "delete": { + "put": { "tags": [ "Users" ], - "summary": "Delete a specific user", - "description": "Deletes a specific user", - "operationId": "deleteUser", + "summary": "Update a specific user by CPF", + "description": "Updates a specific user by CPF", + "operationId": "updateUserByCpf", "parameters": [ { - "name": "id", + "name": "cpf", "in": "path", - "description": "User ID", - "required": true + "description": "User CPF", + "required": true, + "schema": { + "type": "string" + } } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, "responses": { "200": { "description": "Successful operation", @@ -207,6 +499,59 @@ } } }, + "404": { + "description": "User not found" + }, + "401": { + "description": "Unauthenticated" + }, + "403": { + "description": "Forbidden" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + }, + "delete": { + "tags": [ + "Users" + ], + "summary": "Delete a specific user by CPF", + "description": "Deletes a specific user by CPF", + "operationId": "deleteUserByCpf", + "parameters": [ + { + "name": "cpf", + "in": "path", + "description": "User CPF", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + } + } + } + }, + "404": { + "description": "User not found" + }, "401": { "description": "Unauthenticated" }, diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755 diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore old mode 100644 new mode 100755 diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php old mode 100644 new mode 100755 diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php old mode 100644 new mode 100755 diff --git a/tests/TestCase.php b/tests/TestCase.php old mode 100644 new mode 100755 diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php old mode 100644 new mode 100755