This commit is contained in:
2026-02-25 00:03:37 +03:30
parent acf2ed7f18
commit e6b0ad6cf9
+13 -65
View File
@@ -233,19 +233,19 @@ public function register(Request $request)
// ✅ Check if email can receive a message before creating the user // ✅ Check if email can receive a message before creating the user
if (isset($data['email'])) { if (isset($data['email'])) {
$code = rand(1000, 9999); $code = rand(1000, 9999);
try { // try {
if ($method === 'code') { // if ($method === 'code') {
\Mail::to($data['email'])->send(new \App\Mail\VerifyEmailCodeMail($code)); // \Mail::to($data['email'])->send(new \App\Mail\VerifyEmailCodeMail($code));
} else { // } else {
$verificationUrl = url("api/auth/verify-email-link/{$token}?package={$packageNameValue}"); // $verificationUrl = url("api/auth/verify-email-link/{$token}?package={$packageNameValue}");
\Mail::to($data['email'])->send(new \App\Mail\VerifyEmailLinkMail($verificationUrl)); // \Mail::to($data['email'])->send(new \App\Mail\VerifyEmailLinkMail($verificationUrl));
} // }
} catch (\Exception $e) { // } catch (\Exception $e) {
return response()->json([ // return response()->json([
'error' => $e->getMessage(), // 'error' => $e->getMessage(),
'message' => 'لطفا آدرس ایمیل خود را بررسی کنید و مجدد تلاش کنید' // 'message' => 'لطفا آدرس ایمیل خود را بررسی کنید و مجدد تلاش کنید'
], 400); // ], 400);
} // }
// try { // try {
// // Try sending email // // Try sending email
// \Mail::to($data['email'])->send(new \App\Mail\VerifyEmailCodeMail($code)); // \Mail::to($data['email'])->send(new \App\Mail\VerifyEmailCodeMail($code));
@@ -453,59 +453,7 @@ public function checkOTP(Request $request)
'token' => $token, 'token' => $token,
]); ]);
} }
public function requestMobileVerification(Request $request)
{
$data = $request->validate([
'mobile' => ['required', 'string', new MobileNumber],
]);
$mobile = MobileNumberHelper::formatMobile($data['mobile']);
if (User::where('mobile', $mobile)->where('id', '!=', auth()->id())->exists()) {
return response()->json(['message' => 'mobile already taken'], 400);
}
$otp = rand(10000, 99999);
auth()->user()->otpTokens()->create([
'token' => $otp
]);
SendOTPJob::dispatch($mobile, (string)$otp);
return response()->json(['message' => 'otp sent']);
}
public function confirmMobileVerification(Request $request)
{
$data = $request->validate([
'mobile' => ['required', 'string', new MobileNumber],
'token' => 'required|string'
]);
$mobile = MobileNumberHelper::formatMobile($data['mobile']);
$user = auth()->user();
$otp = $user->otpTokens()
->where('token', $data['token'])
->where('created_at', '>', now()->subMinutes(15))
->first();
if (!$otp) {
return response()->json(['message' => 'invalid token'], 400);
}
$otp->delete();
$user->update([
'mobile' => $mobile,
'mobile_verified_at' => now(),
]);
return response()->json([
'message' => 'mobile verified successfully'
]);
}
public function updateProfile(Request $request) public function updateProfile(Request $request)
{ {
$data = $request->validate([ $data = $request->validate([