From d0742edc1ddfe81f9ae5910faa19dd669f5f640f Mon Sep 17 00:00:00 2001
From: Juan Manuel Corigliano Giuliani
<126042007+juancorax@users.noreply.github.com>
Date: Sun, 17 Nov 2024 11:34:19 -0300
Subject: [PATCH] Complete tasks
---
.../Auth/RegisteredUserController.php | 3 +-
app/Http/Controllers/ProfileController.php | 10 ++
app/Models/User.php | 2 +-
resources/views/auth/profile.blade.php | 37 ++---
resources/views/layouts/navigation.blade.php | 129 +++++++++---------
routes/web.php | 10 +-
6 files changed, 95 insertions(+), 96 deletions(-)
diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php
index d8d29eb5..45b1bad4 100644
--- a/app/Http/Controllers/Auth/RegisteredUserController.php
+++ b/app/Http/Controllers/Auth/RegisteredUserController.php
@@ -26,7 +26,6 @@ public function create()
/**
* Handle an incoming registration request.
*
- * @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Validation\ValidationException
@@ -37,7 +36,7 @@ public function store(Request $request)
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
- 'password' => ['required', 'confirmed', Rules\Password::defaults()],
+ 'password' => ['required', 'confirmed', Rules\Password::letters()],
]);
$user = User::create([
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index e0093a49..99f8dc40 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -14,7 +14,17 @@ public function show()
public function update(ProfileUpdateRequest $request)
{
// Task: fill in the code here to update name and email
+ $user = $request->user();
+
+ $user->name = $request->input('name');
+ $user->email = $request->input('email');
+
// Also, update the password if it is set
+ if ($user->password) {
+ $user->password = $request->input('password');
+ }
+
+ $user->save();
return redirect()->route('profile.show')->with('success', 'Profile updated.');
}
diff --git a/app/Models/User.php b/app/Models/User.php
index e23e0905..12a2354b 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -8,7 +8,7 @@
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
-class User extends Authenticatable
+class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable;
diff --git a/resources/views/auth/profile.blade.php b/resources/views/auth/profile.blade.php
index 70e8a8e1..cbb3cd50 100644
--- a/resources/views/auth/profile.blade.php
+++ b/resources/views/auth/profile.blade.php
@@ -10,7 +10,7 @@
-
+
@@ -22,44 +22,31 @@
Task: replace ??? for name/email with logged in user's name/email
-
+
{{-- Task: replace ??? for name/email with logged in user's name/email --}}
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php
index 785936e7..99014ca4 100644
--- a/resources/views/layouts/navigation.blade.php
+++ b/resources/views/layouts/navigation.blade.php
@@ -6,7 +6,7 @@
@@ -16,49 +16,53 @@
{{ __('Users') }}
{{-- Task: this "Profile" link should be visible only to logged-in users --}}
-
- {{ __('Profile') }}
-
+ @auth
+
+ {{ __('Profile') }}
+
+ @endauth
@auth
-
-
-
- {{ Auth::user()->name }}
+
+
+
+ {{ Auth::user()->name }}
-
-
-
+
+
+
-
-
-
+ {{ __('Log Out') }}
+
+
+
+
@else
Log in
@if (Route::has('register'))
-
Register
+
Register
@endif
@endauth
@@ -66,13 +70,13 @@ class="flex items-center text-sm font-medium text-gray-500 transition duration-1
+ class="inline-flex justify-center items-center p-2 text-gray-400 rounded-md transition duration-150 ease-in-out hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-500">
-
-
+
+
@@ -80,38 +84,39 @@ class="inline-flex justify-center items-center p-2 text-gray-400 rounded-md tran
-
+
- @auth
-
-
{{ Auth::user()->name }}
-
{{ Auth::user()->email }}
-
+ @auth
+
+
{{ Auth::user()->name }}
+
{{ Auth::user()->email }}
+
-
-
-
- @csrf
+
+
+
+ @csrf
-
- {{ __('Log Out') }}
-
-
-
- @else
-
-
- {{ __('Login') }}
-
- @if (Route::has('register'))
-
- {{ __('Register') }}
+ {{ __('Log Out') }}
+
+
+
+ @else
+
+
+ {{ __('Login') }}
- @endif
-
- @endauth
+ @if (Route::has('register'))
+
+ {{ __('Register') }}
+
+ @endif
+
+ @endauth
diff --git a/routes/web.php b/routes/web.php
index 71d04297..e60c8f68 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -20,17 +20,15 @@
Route::get('users', [\App\Http\Controllers\UserController::class, 'index'])->name('users.index');
// Task: profile functionality should be available only for logged-in users
-Route::get('profile', [\App\Http\Controllers\ProfileController::class, 'show'])->name('profile.show');
-Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update');
+Route::get('profile', [\App\Http\Controllers\ProfileController::class, 'show'])->middleware('auth')->name('profile.show');
+Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->middleware('auth')->name('profile.update');
// Task: this "/secretpage" URL should be visible only for those who VERIFIED their email
// Add some middleware here, and change some code in app/Models/User.php to enable this
-Route::view('/secretpage', 'secretpage')
- ->name('secretpage');
+Route::view('/secretpage', 'secretpage')->middleware(['auth', 'verified'])->name('secretpage');
// Task: this "/verysecretpage" URL should ask user for verifying their password once again
// You need to add some middleware here
-Route::view('/verysecretpage', 'verysecretpage')
- ->name('verysecretpage');
+Route::view('/verysecretpage', 'verysecretpage')->middleware('password.confirm')->name('verysecretpage');
require __DIR__.'/auth.php';