73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Actions\PasswordResetAction;
|
|
use App\Exceptions\UserNotFoundException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Services\OTPService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class PasswordResetController extends Controller
|
|
{
|
|
public function show()
|
|
{
|
|
return view('auth.passwords.reset');
|
|
}
|
|
|
|
public function sendCode(Request $request, PasswordResetAction $action)
|
|
{
|
|
$data = $request->validate([
|
|
'email' => 'required|email',
|
|
]);
|
|
|
|
try {
|
|
$action->execute($data);
|
|
|
|
return to_route('password.reset.show.verify')->with('success', 'Password reset code is sent');
|
|
} catch (UserNotFoundException $e) {
|
|
return to_route('password.reset.show.verify')->with('success', 'Password reset code is sent');
|
|
}
|
|
}
|
|
|
|
public function showVerify()
|
|
{
|
|
return view('auth.passwords.verify');
|
|
}
|
|
|
|
public function verify(Request $request, OTPService $otpService)
|
|
{
|
|
$data = $request->validate(['otp' => 'required|string:min:5:max:6']);
|
|
try {
|
|
$isVerified = $otpService->verify($data['otp']);
|
|
if (! $isVerified) {
|
|
return back()->with('error', 'Invalid OTP');
|
|
}
|
|
|
|
return to_route('password.reset.show.update')->with('success', 'OTP Verified');
|
|
} catch (UserNotFoundException $e) {
|
|
return back()->with('error', 'Session Expired');
|
|
}
|
|
}
|
|
|
|
public function showUpdate()
|
|
{
|
|
return view('auth.passwords.update');
|
|
}
|
|
|
|
public function update(Request $request)
|
|
{
|
|
$data = $request->validate(['password' => 'required', 'confirmed', Password::min(8)->letters()->mixedCase()->numbers()->symbols()]);
|
|
$user = User::find(Session::get('user_id'));
|
|
if (! $user) {
|
|
return back()->with('error', 'Session Expired');
|
|
}
|
|
$user->update(['password' => $data['password']]);
|
|
|
|
return to_route('login.create')->with('success', 'Password updated successfully');
|
|
}
|
|
}
|