Skip to content

Commit

Permalink
Finish tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
TrisCC committed Oct 28, 2024
1 parent f0cc8fb commit 19ad350
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 81 deletions.
24 changes: 12 additions & 12 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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([
Expand All @@ -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');
}
}
11 changes: 11 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
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
14 changes: 7 additions & 7 deletions resources/views/auth/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<div>
<em><b>Task:</b> replace ??? for name/email with logged in user's name/email</em>
<br /><br />
<br/><br/>

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

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

<div class="mt-4">
Expand All @@ -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/>
</div>

<div class="mt-4">
Expand All @@ -50,7 +50,7 @@ class="block mt-1 w-full"
<x-input id="password"
class="block mt-1 w-full"
type="password"
name="password" />
name="password"/>
</div>

<div class="mt-4">
Expand All @@ -59,7 +59,7 @@ class="block mt-1 w-full"
<x-input id="password_confirmation"
class="block mt-1 w-full"
type="password"
name="password_confirmation" />
name="password_confirmation"/>
</div>

<x-button class="mt-4">
Expand Down
111 changes: 57 additions & 54 deletions resources/views/layouts/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,52 @@
{{ __('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>
Expand All @@ -83,35 +86,35 @@ class="inline-flex justify-center items-center p-2 text-gray-400 rounded-md tran
<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>
20 changes: 13 additions & 7 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 19ad350

Please sign in to comment.