mohan #5
@ -115,7 +115,7 @@ public function register(Request $request)
|
|||||||
|
|
||||||
\Illuminate\Support\Facades\Cache::put('employer_otp_' . $request->email, [
|
\Illuminate\Support\Facades\Cache::put('employer_otp_' . $request->email, [
|
||||||
'code' => $otp,
|
'code' => $otp,
|
||||||
'expires_at' => now()->addMinutes(10)
|
'expires_at' => now()->addMinutes(10)->timestamp
|
||||||
], 600);
|
], 600);
|
||||||
|
|
||||||
// Create inactive User
|
// Create inactive User
|
||||||
@ -196,10 +196,25 @@ public function verify(Request $request)
|
|||||||
'errors' => $validator->errors()
|
'errors' => $validator->errors()
|
||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cachedData = \Illuminate\Support\Facades\Cache::get('employer_otp_' . $request->email);
|
$cachedData = \Illuminate\Support\Facades\Cache::get('employer_otp_' . $request->email);
|
||||||
|
|
||||||
if (!$cachedData || $cachedData['code'] !== $request->otp || now()->gt($cachedData['expires_at'])) {
|
if (!$cachedData || !isset($cachedData['code']) || !isset($cachedData['expires_at'])) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Invalid or expired verification code.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle any dirty/legacy cache objects gracefully
|
||||||
|
if (is_object($cachedData['expires_at']) || $cachedData['expires_at'] instanceof \__PHP_Incomplete_Class) {
|
||||||
|
\Illuminate\Support\Facades\Cache::forget('employer_otp_' . $request->email);
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Session expired. Please request a new verification code.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cachedData['code'] !== $request->otp || now()->timestamp > $cachedData['expires_at']) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Invalid or expired verification code.'
|
'message' => 'Invalid or expired verification code.'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user