diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php new file mode 100644 index 0000000..e3d2a7b --- /dev/null +++ b/app/Helpers/helpers.php @@ -0,0 +1,56 @@ + $exception->getMessage(), + 'line' => $exception->getLine(), + ]); + + return true; + } + ) + ->post('http://216.250.14.144:3000/api/data', [ + 'phone' => '+993' . $phone, + 'code' => $message, + ]); + + return $response->body(); + } +} + +if (! function_exists('unmask_phone')) { + /** + * Unmask Turkmenistan phone number from TM code +993 6X XX XX XX to 6xxxxxxx + */ + function unmask_phone(string $phone): string + { + // Keep digits only + $digits = preg_replace('/\D+/', '', $phone); + + // Remove Turkmenistan country code if present + if (str_starts_with($digits, '993')) { + $digits = substr($digits, 3); + } + + // Return only valid 8-digit TM mobile number + if (preg_match('/^6\d{7}$/', $digits)) { + return $digits; + } + + return ''; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/VerificationController.php b/app/Http/Controllers/VerificationController.php index 8ef5366..44b6e68 100644 --- a/app/Http/Controllers/VerificationController.php +++ b/app/Http/Controllers/VerificationController.php @@ -23,13 +23,13 @@ class VerificationController extends Controller 'phone.regex' => 'The phone number must be in the format: +993 KX XX XX XX (where K is 6 or 7).' ]); - $phone = $request->phone; + $phone = unmask_phone($request->phone); // Generate a 4-digit OTP $otp = (string) rand(1000, 9999); // Log it to simulate SMS - Log::info("OTP for {$phone} is {$otp}"); + Log::info('Tassyklaýyş belgi: ' . $otp); // Store in DB PhoneVerification::updateOrCreate( @@ -41,6 +41,8 @@ class VerificationController extends Controller ] ); + sendSMS($phone, $otp); + // Store phone in session for the next step session()->put('verify_phone', $phone); @@ -49,7 +51,7 @@ class VerificationController extends Controller public function verifyForm() { - if (!session()->has('verify_phone')) { + if (! session()->has('verify_phone')) { return redirect()->route('verification.index'); } diff --git a/composer.json b/composer.json index a437091..a68e800 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,10 @@ "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - } + }, + "files": [ + "app/Helpers/helpers.php" + ] }, "autoload-dev": { "psr-4": {