ForgotPasswordController.php
This handles the verification of a user's email, sending a one-time password (OTP) for password reset, and resetting the user's password when provided with the correct user ID and new password.
verifyEmail
verifyEmailpublic function verifyEmail(Request $request)
{
// Get the email address from the request
$email = $request->input('email');
// Check if a user account with the provided email exists
$userAccount = UserAccount::where('email', $email)->first();
if (isset($userAccount)) {
// Generate a random OTP (One-Time Password)
$otp = strval(mt_rand(100000, 999999));
// Compose the email subject and body with the OTP
$subject = "Reset password";
$body = "<div style='display:block'>OTP: " . $otp . "</div>";
// Send the email with the OTP to the user's email address
Mail::to($userAccount->email)->send(new EmailContent($subject, $body));
// Prepare the success response with OTP and user details
$response = [
'SUCCESS' => 1,
'OTP' => $otp,
'USER_ID' => $userAccount->id,
];
return $response;
} else {
// If the user account is not found, return a failure response
$response = [
'SUCCESS' => 0,
];
return $response;
}
}resetPassword
resetPasswordLast updated