-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@extends('root::auth.layout') | ||
|
||
{{-- Title --}} | ||
@section('title', __('Forgot Password')) | ||
|
||
{{-- Content --}} | ||
@section('content') | ||
<form method="POST" action="{{ URL::route('root.auth.password.email') }}"> | ||
@csrf | ||
<div class="form-group-stack"> | ||
<div class="form-group"> | ||
<label class="form-label" for="email">{{ __('Email') }}</label> | ||
<input | ||
@class(['form-control', 'form-control--lg', 'form-control--invalid' => $errors->has('email')]) | ||
id="email" | ||
type="email" | ||
name="email" | ||
required | ||
value="{{ Request::old('email') }}" | ||
> | ||
@error('email') | ||
<span class="field-feedback field-feedback--invalid">{{ $message }}</span> | ||
@enderror | ||
</div> | ||
<div class="form-group"> | ||
<button class="btn btn--primary btn--lg btn--block btn--primary-shadow"> | ||
{{ __('Send Password Reset Email') }} | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
<?php | ||
|
||
use Cone\Root\Http\Controllers\Auth\ForgotPasswordController; | ||
use Cone\Root\Http\Controllers\Auth\LoginController; | ||
use Cone\Root\Http\Controllers\Auth\ResetPasswordController; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
// Login | ||
Route::get('login', [LoginController::class, 'show'])->name('login'); | ||
Route::post('login', [LoginController::class, 'login']); | ||
Route::post('logout', [LoginController::class, 'logout'])->name('logout'); | ||
|
||
// Reset | ||
Route::get('/password/reset', [ForgotPasswordController::class, 'show'])->name('password.request'); | ||
Route::post('/password/email', [ForgotPasswordController::class, 'send'])->name('password.email'); | ||
Route::get('/password/reset/{token}/{email}', [ResetPasswordController::class, 'show'])->name('password.reset'); | ||
Route::post('/password/reset', [ResetPasswordController::class, 'reset'])->name('password.update'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Http\Controllers\Auth; | ||
|
||
use Cone\Root\Http\Controllers\Controller; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Password; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\Support\Facades\Response as ResponseFactory; | ||
|
||
class ForgotPasswordController extends Controller | ||
{ | ||
/** | ||
* Display the form to request a password reset link. | ||
*/ | ||
public function show(): Response | ||
{ | ||
return ResponseFactory::view('root::auth.forgot-password'); | ||
} | ||
|
||
/** | ||
* Send a reset link to the given user. | ||
*/ | ||
public function send(Request $request): RedirectResponse | ||
{ | ||
$data = $request->validate(['email' => ['required', 'string', 'email']]); | ||
|
||
Password::broker()->sendResetLink($data); | ||
|
||
return Redirect::back()->with('status', __(Password::RESET_LINK_SENT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Http\Controllers\Auth; | ||
|
||
use App\Http\Requests\ResetPasswordRequest; | ||
use App\Models\User; | ||
use Cone\Root\Http\Controllers\Controller; | ||
use Illuminate\Auth\Events\PasswordReset; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Password; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\Support\Facades\Response as ResponseFactory; | ||
use Illuminate\Support\Str; | ||
|
||
class ResetPasswordController extends Controller | ||
{ | ||
/** | ||
* Display the password reset view for the given token. | ||
*/ | ||
public function show(Request $request): Response | ||
{ | ||
return ResponseFactory::view('root::auth.reset-password', [ | ||
'email' => $request->route()->parameter('email'), | ||
'token' => $request->route()->parameter('token'), | ||
]); | ||
} | ||
|
||
/** | ||
* Reset the given user's password. | ||
*/ | ||
public function reset(ResetPasswordRequest $request): RedirectResponse | ||
{ | ||
$response = Password::broker()->reset( | ||
$request->only(['email', 'password', 'password_confirmation', 'token']), | ||
function (User $user, string $password): void { | ||
$this->resetPassword($user, $password); | ||
|
||
if (! $user->hasVerifiedEmail()) { | ||
$user->markEmailAsVerified(); | ||
} | ||
} | ||
); | ||
|
||
return $response == Password::PASSWORD_RESET | ||
? Redirect::route('root.dashboard')->with('message', __($response)) | ||
: Redirect::back()->withInput($request->only(['email']))->withErrors(['email' => __($response)]); | ||
} | ||
|
||
/** | ||
* Reset the given user's password. | ||
*/ | ||
protected function resetPassword(User $user, string $password): void | ||
{ | ||
$user->setAttribute('password', Hash::make($password)); | ||
|
||
$user->setRememberToken(Str::random(60)); | ||
|
||
$user->save(); | ||
|
||
Event::dispatch(new PasswordReset($user)); | ||
|
||
Auth::guard()->login($user); | ||
} | ||
} |