diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index d8d29eb5..fcee3d67 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -13,20 +13,10 @@ class RegisteredUserController extends Controller { - /** - * Display the registration view. - * - * @return \Illuminate\View\View - */ - public function create() - { - return view('auth.register'); - } - /** * Handle an incoming registration request. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse * * @throws \Illuminate\Validation\ValidationException @@ -37,7 +27,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::defaults()->letters()], ]); $user = User::create([ @@ -52,4 +42,14 @@ public function store(Request $request) return redirect(RouteServiceProvider::HOME); } + + /** + * Display the registration view. + * + * @return \Illuminate\View\View + */ + public function create() + { + return view('auth.register'); + } } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index e0093a49..e28c1c4c 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -15,6 +15,17 @@ public function update(ProfileUpdateRequest $request) { // Task: fill in the code here to update name and email // Also, update the password if it is set + auth()->user()->update([ + 'name' => $request->name, + 'email' => $request->email, + ]); + + if ($request->password) { + auth()->user()->fill([ + 'password' => bcrypt($request->password) + ]); + } + auth()->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..67305f3b 100644 --- a/resources/views/auth/profile.blade.php +++ b/resources/views/auth/profile.blade.php @@ -20,7 +20,7 @@
Task: replace ??? for name/email with logged in user's name/email -

+

@@ -29,8 +29,8 @@ class="block mt-1 w-full" type="text" name="name" - value="???" - required /> + value="{{ auth()->user()->name }}" + required/>
@@ -40,8 +40,8 @@ class="block mt-1 w-full" class="block mt-1 w-full" type="email" name="email" - value="???" - required /> + value="{{ auth()->user()->email }}" + required/>
@@ -50,7 +50,7 @@ class="block mt-1 w-full" + name="password"/>
@@ -59,7 +59,7 @@ class="block mt-1 w-full" + name="password_confirmation"/>
diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 785936e7..787ae881 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -16,49 +16,52 @@ {{ __('Users') }} {{-- Task: this "Profile" link should be visible only to logged-in users --}} - - {{ __('Profile') }} - + @auth + + {{ __('Profile') }} + + @endauth @@ -83,35 +86,35 @@ class="inline-flex justify-center items-center p-2 text-gray-400 rounded-md tran diff --git a/routes/web.php b/routes/web.php index 71d04297..92691ee3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,17 +20,23 @@ 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::middleware(['auth'])->group(function () { + Route::get('profile', [\App\Http\Controllers\ProfileController::class, 'show'])->name('profile.show'); + Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->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::middleware(['auth', 'verified'])->group(function () { + Route::view('/secretpage', 'secretpage') + ->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::middleware(['auth', 'password.confirm'])->group(function () { + Route::view('/verysecretpage', 'verysecretpage') + ->name('verysecretpage'); +}); -require __DIR__.'/auth.php'; +require __DIR__ . '/auth.php';