Skip to content

Commit

Permalink
Complete tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
juancorax committed Nov 17, 2024
1 parent f0cc8fb commit d0742ed
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 96 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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([
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down
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
37 changes: 12 additions & 25 deletions resources/views/auth/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">

<x-validation-errors class="mb-4" :errors="$errors"/>
<x-validation-errors class="mb-4" :errors="$errors" />

<x-alert.success></x-alert.success>

Expand All @@ -22,44 +22,31 @@
<em><b>Task:</b> replace ??? for name/email with logged in user's name/email</em>
<br /><br />

<x-label for="name" :value="__('Name')"/>
<x-label for="name" :value="__('Name')" />

{{-- Task: replace ??? for name/email with logged in user's name/email --}}
<x-input id="name"
class="block mt-1 w-full"
type="text"
name="name"
value="???"
required />
<x-input id="name" class="block mt-1 w-full" type="text" name="name"
value="{{ Auth::user()->name }}" required />
</div>

<div class="mt-4">
<x-label for="email" :value="__('Email')"/>
<x-label for="email" :value="__('Email')" />

<x-input id="email"
class="block mt-1 w-full"
type="email"
name="email"
value="???"
required />
<x-input id="email" class="block mt-1 w-full" type="email" name="email"
value="{{ Auth::user()->email }}" required />
</div>

<div class="mt-4">
<x-label for="password" :value="__('New password (if you want to change it)')"/>
<x-label for="password" :value="__('New password (if you want to change it)')" />

<x-input id="password"
class="block mt-1 w-full"
type="password"
name="password" />
<x-input id="password" class="block mt-1 w-full" type="password" name="password" />
</div>

<div class="mt-4">
<x-label for="password_confirmation" :value="__('New password confirmation')"/>
<x-label for="password_confirmation" :value="__('New password confirmation')" />

<x-input id="password_confirmation"
class="block mt-1 w-full"
type="password"
name="password_confirmation" />
<x-input id="password_confirmation" class="block mt-1 w-full" type="password"
name="password_confirmation" />
</div>

<x-button class="mt-4">
Expand Down
129 changes: 67 additions & 62 deletions resources/views/layouts/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Logo -->
<div class="flex flex-shrink-0 items-center">
<a href="{{ route('home') }}">
<x-application-logo class="block w-auto h-10 text-gray-600 fill-current"/>
<x-application-logo class="block w-auto h-10 text-gray-600 fill-current" />
</a>
</div>

Expand All @@ -16,102 +16,107 @@
{{ __('Users') }}
</x-nav-link>
{{-- Task: this "Profile" link should be visible only to logged-in users --}}
<x-nav-link href="/profile" :active="request()->routeIs('profile.show')">
{{ __('Profile') }}
</x-nav-link>
@auth
<x-nav-link href="/profile" :active="request()->routeIs('profile.show')">
{{ __('Profile') }}
</x-nav-link>
@endauth
</div>
</div>

<!-- Settings Dropdown -->
<div class="hidden sm:flex sm:items-center sm:ml-6">
@auth
<x-dropdown align="right" width="48">
<x-slot name="trigger">
<button
class="flex items-center text-sm font-medium text-gray-500 transition duration-150 ease-in-out hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300">
<div>{{ Auth::user()->name }}</div>
<x-dropdown align="right" width="48">
<x-slot name="trigger">
<button
class="flex items-center text-sm font-medium text-gray-500 transition duration-150 ease-in-out hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300">
<div>{{ Auth::user()->name }}</div>

<div class="ml-1">
<svg class="w-4 h-4 fill-current" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20">
<path fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd"/>
</svg>
</div>
</button>
</x-slot>
<div class="ml-1">
<svg class="w-4 h-4 fill-current" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20">
<path fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd" />
</svg>
</div>
</button>
</x-slot>

<x-slot name="content">
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
@csrf
<x-slot name="content">
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
@csrf

<x-dropdown-link :href="route('logout')" onclick="event.preventDefault();
<x-dropdown-link :href="route('logout')"
onclick="event.preventDefault();
this.closest('form').submit();">
{{ __('Log Out') }}
</x-dropdown-link>
</form>
</x-slot>
</x-dropdown>
{{ __('Log Out') }}
</x-dropdown-link>
</form>
</x-slot>
</x-dropdown>
@else
<a href="{{ route('login') }}" class="text-sm text-gray-700 underline dark:text-gray-500">Log in</a>

@if (Route::has('register'))
<a href="{{ route('register') }}" class="ml-4 text-sm text-gray-700 underline dark:text-gray-500">Register</a>
<a href="{{ route('register') }}"
class="ml-4 text-sm text-gray-700 underline dark:text-gray-500">Register</a>
@endif
@endauth
</div>

<!-- Hamburger -->
<div class="flex items-center -mr-2 sm:hidden">
<button @click="open = ! open"
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">
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">
<svg class="w-6 h-6" stroke="currentColor" fill="none" viewBox="0 0 24 24">
<path :class="{'hidden': open, 'inline-flex': ! open }" class="inline-flex"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 6h16M4 12h16M4 18h16"/>
<path :class="{'hidden': ! open, 'inline-flex': open }" class="hidden"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
<path :class="{ 'hidden': open, 'inline-flex': !open }" class="inline-flex"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 6h16M4 12h16M4 18h16" />
<path :class="{ 'hidden': !open, 'inline-flex': open }" class="hidden" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</div>
</div>

<!-- Responsive Navigation Menu -->
<div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden">
<div :class="{ 'block': open, 'hidden': !open }" class="hidden sm:hidden">
<!-- Responsive Settings Options -->
<div class="pt-4 pb-1 border-t border-gray-200">
@auth
<div class="px-4">
<div class="text-base font-medium text-gray-800">{{ Auth::user()->name }}</div>
<div class="text-sm font-medium text-gray-500">{{ Auth::user()->email }}</div>
</div>
@auth
<div class="px-4">
<div class="text-base font-medium text-gray-800">{{ Auth::user()->name }}</div>
<div class="text-sm font-medium text-gray-500">{{ Auth::user()->email }}</div>
</div>

<div class="mt-3 space-y-1">
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
@csrf
<div class="mt-3 space-y-1">
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
@csrf

<x-responsive-nav-link :href="route('logout')" onclick="event.preventDefault();
<x-responsive-nav-link :href="route('logout')"
onclick="event.preventDefault();
this.closest('form').submit();">
{{ __('Log Out') }}
</x-responsive-nav-link>
</form>
</div>
@else
<div class="space-y-1">
<x-responsive-nav-link :href="route('login')">
{{ __('Login') }}
</x-responsive-nav-link>
@if (Route::has('register'))
<x-responsive-nav-link :href="route('register')">
{{ __('Register') }}
{{ __('Log Out') }}
</x-responsive-nav-link>
</form>
</div>
@else
<div class="space-y-1">
<x-responsive-nav-link :href="route('login')">
{{ __('Login') }}
</x-responsive-nav-link>
@endif
</div>
@endauth
@if (Route::has('register'))
<x-responsive-nav-link :href="route('register')">
{{ __('Register') }}
</x-responsive-nav-link>
@endif
</div>
@endauth
</div>
</div>
</nav>
10 changes: 4 additions & 6 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit d0742ed

Please sign in to comment.