Skip to content

Commit

Permalink
feat: forgot password
Browse files Browse the repository at this point in the history
  • Loading branch information
WailanTirajoh committed Nov 25, 2023
1 parent 96772b9 commit 0152c6a
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
43 changes: 43 additions & 0 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace App\Http\Controllers;

use App\Http\Requests\PostLoginRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;

class AuthController extends Controller
{
Expand All @@ -22,4 +26,43 @@ public function logout()
Auth::logout();
return redirect('login')->with('success', 'Logout success, goodbye ' . $name);
}

public function forgotPassword(Request $request)
{
$request->validate(['email' => 'required|email']);

$status = Password::sendResetLink(
$request->only('email')
);

return $status === Password::RESET_LINK_SENT
? back()->with(['status' => __($status)])
: back()->withErrors(['email' => __($status)]);
}

public function resetPassword(Request $request)
{
$request->validate([
'token' => 'required',
'email' => 'required|email',
'password' => 'required|min:8|confirmed',
]);

$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function (User $user, string $password) {
$user->forceFill([
'password' => Hash::make($password)
])->setRememberToken(Str::random(60));

$user->save();

event(new PasswordReset($user));
}
);

return $status === Password::PASSWORD_RESET
? redirect()->route('login')->with('status', __($status))
: back()->withErrors(['email' => [__($status)]]);
}
}
2 changes: 1 addition & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class="form-control @error('password') is-invalid @enderror" placeholder="Passwo
</div>
</div>
<hr class="my-4">
{{-- <p class="text-center">Doesnt have any account? <a href="/register">register</a></p> --}}
<p class="text-center">Forgot Password? <a href="/forgot-password">go here</a></p>
</form>
</div>
</div>
Expand Down
19 changes: 18 additions & 1 deletion resources/views/auth/passwords/email.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
@extends('layouts.app')
@extends('template.auth')

@section('content')
<style>
#btn_submit {
width: 100%;
transition: all 0.5s ease-in-out;
}
#btn_submit.isLoading {
width: 50px;
border-radius: 100vw;
}
.hide {
display: none;
}
</style>
<link href="{{ asset('style/css/stylelogin.css') }}" rel="stylesheet">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
@extends('layouts.app')
@extends('template.auth')

@section('content')
<style>
#btn_submit {
width: 100%;
transition: all 0.5s ease-in-out;
}
#btn_submit.isLoading {
width: 50px;
border-radius: 100vw;
}
.hide {
display: none;
}
</style>
<link href="{{ asset('style/css/stylelogin.css') }}" rel="stylesheet">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
Expand Down
14 changes: 13 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@

Route::get('/mark-all-as-read', [NotificationsController::class, 'markAllAsRead'])->name('notification.markAllAsRead');

Route::get('/notification-to/{id}',[NotificationsController::class, 'routeTo'])->name('notification.routeTo');
Route::get('/notification-to/{id}', [NotificationsController::class, 'routeTo'])->name('notification.routeTo');
});

// Login routes
Route::view('/login', 'auth.login')->name('login');
Route::post('/postLogin', [AuthController::class, 'postLogin'])->name('postlogin');

// Forgot Password routes
Route::group(['middleware' => 'guest'], function () {
Route::get('/forgot-password', fn () => view('auth.passwords.email'))->name('password.request');
Route::post('/forgot-password', [AuthController::class, 'forgotPassword'])->name('password.email');

// Reset Password routes
Route::get('/reset-password/{token}', fn (string $token) => view('auth.reset-password', ['token' => $token]))
->name('password.reset');
Route::post('/reset-password', [AuthController::class, 'resetPassword'])->name('password.update');
});

Route::get('/', [HomeController::class, 'index'])->name('home');

Route::get('/sendEvent', function () {
Expand Down

0 comments on commit 0152c6a

Please sign in to comment.