Skip to content

Commit 98b8f3b

Browse files
committed
first attempt
1 parent f0cc8fb commit 98b8f3b

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

app/Http/Controllers/Auth/RegisteredUserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function store(Request $request)
3737
$request->validate([
3838
'name' => ['required', 'string', 'max:255'],
3939
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
40-
'password' => ['required', 'confirmed', Rules\Password::defaults()],
40+
'password' => ['required', 'confirmed', Rules\Password::defaults(), 'min:8', 'regex:/[a-zA-Z]/'],
4141
]);
4242

4343
$user = User::create([

app/Http/Controllers/ProfileController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public function update(ProfileUpdateRequest $request)
1515
{
1616
// Task: fill in the code here to update name and email
1717
// Also, update the password if it is set
18+
$user = Auth::user();
19+
20+
$user->email = $request->email;
21+
$user->name = $request->name;
22+
23+
if ($request->password) {
24+
$user->password = $request->password;
25+
}
26+
27+
$user->save();
1828

1929
return redirect()->route('profile.show')->with('success', 'Profile updated.');
2030
}

app/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Notifications\Notifiable;
99
use Laravel\Sanctum\HasApiTokens;
1010

11-
class User extends Authenticatable
11+
class User extends Authenticatable implements MustVerifyEmail
1212
{
1313
use HasApiTokens, HasFactory, Notifiable;
1414

resources/views/auth/profile.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
class="block mt-1 w-full"
3030
type="text"
3131
name="name"
32-
value="???"
32+
value="{{ auth()->user()->name }}"
3333
required />
3434
</div>
3535

@@ -40,7 +40,7 @@ class="block mt-1 w-full"
4040
class="block mt-1 w-full"
4141
type="email"
4242
name="email"
43-
value="???"
43+
value="{{ auth()->user()->email }}"
4444
required />
4545
</div>
4646

resources/views/layouts/navigation.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
{{ __('Users') }}
1717
</x-nav-link>
1818
{{-- Task: this "Profile" link should be visible only to logged-in users --}}
19-
<x-nav-link href="/profile" :active="request()->routeIs('profile.show')">
20-
{{ __('Profile') }}
21-
</x-nav-link>
19+
@auth
20+
<x-nav-link href="/profile" :active="request()->routeIs('profile.show')">
21+
{{ __('Profile') }}
22+
</x-nav-link>
23+
@endauth
24+
2225
</div>
2326
</div>
2427

routes/web.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
Route::get('users', [\App\Http\Controllers\UserController::class, 'index'])->name('users.index');
2121

2222
// Task: profile functionality should be available only for logged-in users
23-
Route::get('profile', [\App\Http\Controllers\ProfileController::class, 'show'])->name('profile.show');
24-
Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update');
23+
Route:group([middleware => 'auth'], function() {
24+
Route::get('profile', [\App\Http\Controllers\ProfileController::class, 'show'])->name('profile.show');
25+
Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update');
26+
});
27+
2528

2629
// Task: this "/secretpage" URL should be visible only for those who VERIFIED their email
2730
// Add some middleware here, and change some code in app/Models/User.php to enable this
2831
Route::view('/secretpage', 'secretpage')
29-
->name('secretpage');
32+
->name('secretpage')->middleware('verified');
3033

3134
// Task: this "/verysecretpage" URL should ask user for verifying their password once again
3235
// You need to add some middleware here
3336
Route::view('/verysecretpage', 'verysecretpage')
34-
->name('verysecretpage');
37+
->name('verysecretpage')->middleware('password.confirm');
3538

3639
require __DIR__.'/auth.php';

0 commit comments

Comments
 (0)