feat: add verify mobile
This commit is contained in:
@@ -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,7 +453,71 @@ public function checkOTP(Request $request)
|
|||||||
'token' => $token,
|
'token' => $token,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
public function requestMobileVerification(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'mobile' => ['required', 'string', new MobileNumber],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = auth()->user();
|
||||||
|
$mobile = MobileNumberHelper::formatMobile($data['mobile']);
|
||||||
|
|
||||||
|
// چک اینکه موبایل مال یوزر دیگه نباشه
|
||||||
|
if (User::where('mobile', $mobile)
|
||||||
|
->where('id', '!=', $user->id)
|
||||||
|
->exists()) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'mobile already taken'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// حذف otp های قبلی
|
||||||
|
$user->otpTokens()->delete();
|
||||||
|
|
||||||
|
$otp = rand(10000, 99999);
|
||||||
|
|
||||||
|
$user->otpTokens()->create([
|
||||||
|
'token' => $otp
|
||||||
|
]);
|
||||||
|
|
||||||
|
SendOTPJob::dispatch($mobile, (string)$otp);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'otp sent successfully'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
public function confirmMobileVerification(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'mobile' => ['required', 'string', new MobileNumber],
|
||||||
|
'token' => 'required|string'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = auth()->user();
|
||||||
|
$mobile = MobileNumberHelper::formatMobile($data['mobile']);
|
||||||
|
|
||||||
|
$otp = $user->otpTokens()
|
||||||
|
->where('token', $data['token'])
|
||||||
|
->where('created_at', '>', now()->subMinutes(5))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$otp) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'invalid or expired 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([
|
||||||
|
|||||||
Reference in New Issue
Block a user