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

Task Completed #445

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .env.example → .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_KEY=base64:+MCoyq1Yb/Ui8oz6FXhRlnp3KLw8QlJuA4BAUSgdJvc=
APP_DEBUG=true
APP_URL=http://localhost

Expand All @@ -10,7 +10,7 @@ LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_DATABASE=laravel-test-auth
DB_USERNAME=root
DB_PASSWORD=

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules;
use Illuminate\Validation\Rules\Password;

class RegisteredUserController extends Controller
{
Expand Down Expand Up @@ -37,7 +38,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::min(8)->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 @@ -3,6 +3,9 @@
namespace App\Http\Controllers;

use App\Http\Requests\ProfileUpdateRequest;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class ProfileController extends Controller
{
Expand All @@ -15,6 +18,13 @@ public function update(ProfileUpdateRequest $request)
{
// Task: fill in the code here to update name and email
// Also, update the password if it is set
$user =Auth()->user();
$user->name = $request->name;
$user->email = $request->email;
if ($request->filled('password') && $request->password === $request->password_confirmation) {
$user->password = Hash::make($request->password);
}
$user->save();

return redirect()->route('profile.show')->with('success', 'Profile updated.');
}
Expand Down
4 changes: 3 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
class User extends Authenticatable implements MustVerifyEmailContract
{
use HasApiTokens, HasFactory, Notifiable;

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
4 changes: 3 additions & 1 deletion 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>
</x-nav-link>
@endauth
</div>
</div>

Expand Down
22 changes: 5 additions & 17 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,23 @@

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('home');
})->name('home');

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'])->name('profile.show')->middleware('auth');
Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update')->middleware('auth');

// 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');
->name('secretpage')->middleware('verified');

// 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');

require __DIR__.'/auth.php';
->name('verysecretpage')->middleware('password.confirm');;
require __DIR__.'/auth.php';
Loading