From 3d3ca28a673b12c224239f6441041be16e090749 Mon Sep 17 00:00:00 2001 From: DiegoAndresMejia Date: Tue, 12 Nov 2024 12:09:55 -0500 Subject: [PATCH] create: create the register form to organizators, and create the logout function an added it in the navbar --- app/Http/Controllers/UserController.php | 51 +++++ app/Models/User.php | 2 + ...add_document_image_path_to_users_table.php | 28 +++ resources/js/Components/Dashboard/NavBar.vue | 64 ++++-- .../js/Components/Sign-in/LoginComponent.vue | 8 +- resources/js/Pages/Auth/Register.vue | 8 +- resources/js/Pages/Auth/ResetPassword.vue | 8 +- .../js/Pages/Users/RegisterOrganizer.vue | 186 ++++++++++++++++++ routes/web.php | 3 + 9 files changed, 338 insertions(+), 20 deletions(-) create mode 100644 database/migrations/2024_11_12_151027_add_document_image_path_to_users_table.php create mode 100644 resources/js/Pages/Users/RegisterOrganizer.vue diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index c38efd0..7d73781 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -154,4 +154,55 @@ public function activeRaffles() 'raffles' => $activeRaffles, ]); } + +public function registerOrganizer(){ + return Inertia::render('Users/RegisterOrganizer'); +} + + +public function storeOrganizer(Request $request) +{ + // Validar los datos del formulario + $validated = $request->validate([ + 'document' => 'nullable|string', + 'document_type' => 'nullable|string', + 'document_image' => 'required|image|max:2048', + ]); + + // Obtener el usuario autenticado + $user = auth()->user(); + + // Manejar la subida de la imagen del documento + if ($request->hasFile('document_image')) { + // Eliminar la imagen anterior si existe + if ($user->document_image_path) { + Storage::disk('public')->delete($user->document_image_path); + } + + // Guardar la nueva imagen + $documentImagePath = $request->file('document_image')->store('documents', 'public'); + + // Actualizar los campos del usuario autenticado + $user->update([ + 'document' => $validated['document'] ?? $user->document, + 'document_type' => $validated['document_type'] ?? $user->document_type, + 'document_image_path' => $documentImagePath, + ]); + + if (!$user->hasRole('organizador')) { + $user->assignRole('organizador'); + } + + return response()->json([ + 'message' => 'Información del organizador actualizada exitosamente.', + 'document_image_url' => Storage::url($documentImagePath), + ], 200); + } + + return response()->json([ + 'error' => 'No se recibió la imagen del documento.', + ], 400); +} + + } diff --git a/app/Models/User.php b/app/Models/User.php index 3f702d8..7b14728 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -26,6 +26,8 @@ class User extends Authenticatable 'google_id', 'github_id', 'profile_photo_path', + 'document_image_path', + ]; protected $hidden = [ diff --git a/database/migrations/2024_11_12_151027_add_document_image_path_to_users_table.php b/database/migrations/2024_11_12_151027_add_document_image_path_to_users_table.php new file mode 100644 index 0000000..dc8f81b --- /dev/null +++ b/database/migrations/2024_11_12_151027_add_document_image_path_to_users_table.php @@ -0,0 +1,28 @@ +string('document_image_path')->nullable()->after('document_type'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('document_image_path'); + }); + } +}; diff --git a/resources/js/Components/Dashboard/NavBar.vue b/resources/js/Components/Dashboard/NavBar.vue index 8ae0423..78654f6 100644 --- a/resources/js/Components/Dashboard/NavBar.vue +++ b/resources/js/Components/Dashboard/NavBar.vue @@ -4,39 +4,44 @@
+ alt="Logo Gananza" class="h-8 logo" />
-