Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 #477

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

1 #477

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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','string', 'min:8', 'regex:/[a-zA-Z]/', 'confirmed'],
]);

$user = User::create([
Expand Down
27 changes: 24 additions & 3 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Hash;

use App\Http\Requests\ProfileUpdateRequest;

Expand All @@ -13,9 +14,29 @@ public function show()

public function update(ProfileUpdateRequest $request)
{
// Task: fill in the code here to update name and email
// Also, update the password if it is set

// Validate the request data
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255',
'password' => 'nullable|string|min:8|confirmed',
]);

// Get the authenticated user
$user = auth()->user();

// Update the user's name and email
$user->name = $request->name;
$user->email = $request->email;

// Update the password if it is set
if ($request->password) {
$user->password = Hash::make($request->password);
}

// Save the updated user data
$user->save();

// Redirect back to the profile page with a success message
return redirect()->route('profile.show')->with('success', 'Profile updated.');
}
}
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions resources/views/auth/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class="block mt-1 w-full"
type="text"
name="name"
value="???"
value="{{ auth()->user()->name }}"
required />
</div>

Expand All @@ -40,7 +40,7 @@ class="block mt-1 w-full"
class="block mt-1 w-full"
type="email"
name="email"
value="???"
value="{{ auth()->user()->email }}"
required />
</div>

Expand Down
2 changes: 2 additions & 0 deletions resources/views/layouts/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
{{ __('Users') }}
</x-nav-link>
{{-- Task: this "Profile" link should be visible only to logged-in users --}}
@auth
<x-nav-link href="/profile" :active="request()->routeIs('profile.show')">
{{ __('Profile') }}
</x-nav-link>
@endauth
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@
Route::get('users', [\App\Http\Controllers\UserController::class, 'index'])->name('users.index');

// Task: profile functionality should be available only for logged-in users
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')
->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')
->middleware(['auth', 'password.confirm'])
->name('verysecretpage');

require __DIR__.'/auth.php';
Loading