Update: 2026-05-06 02:59:42

This commit is contained in:
Hamza-Ayed
2026-05-06 02:59:43 +03:00
parent dc2ba2ebcb
commit 9952e0eca5
78 changed files with 3490 additions and 48 deletions

View File

@@ -0,0 +1,79 @@
import 'package:get/get.dart';
import 'package:dio/dio.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';
import '../../../core/network/dio_client.dart';
import '../../../core/storage/secure_storage.dart';
import '../../../app/routes/app_pages.dart';
class AuthController extends GetxController {
final Dio _dio = DioClient().client;
final SecureStorage _storage = SecureStorage();
var isLoading = false.obs;
var phone = ''.obs;
Future<void> requestOtp(String phoneNumber) async {
try {
isLoading.value = true;
phone.value = phoneNumber;
final response = await _dio.post('auth/mobile/request-otp', data: {
'phone': phoneNumber,
});
if (response.statusCode == 200) {
Get.toNamed(AppRoutes.OTP_VERIFY);
}
} on DioException catch (e) {
Get.snackbar('خطأ', e.response?.data['message'] ?? 'فشل الاتصال بالخادم');
} finally {
isLoading.value = false;
}
}
Future<void> verifyOtp(String otp) async {
try {
isLoading.value = true;
// Get device info
final deviceInfo = DeviceInfoPlugin();
String deviceId = '';
String deviceName = '';
if (Platform.isAndroid) {
final androidInfo = await deviceInfo.androidInfo;
deviceId = androidInfo.id;
deviceName = androidInfo.model;
} else if (Platform.isIOS) {
final iosInfo = await deviceInfo.iosInfo;
deviceId = iosInfo.identifierForVendor ?? 'unknown_ios';
deviceName = iosInfo.name;
}
final response = await _dio.post('auth/mobile/verify-otp', data: {
'phone': phone.value,
'otp': otp,
'device_id': deviceId,
'device_name': deviceName,
'platform': Platform.operatingSystem,
'app_version': '1.0.0', // TODO: Get from package_info_plus
});
if (response.statusCode == 200) {
final data = response.data['data'];
// Save secure data
await _storage.saveToken(data['access_token']);
await _storage.saveDeviceSecret(data['device_secret']);
// Navigate to Dashboard or Biometric Setup
Get.offAllNamed(AppRoutes.DASHBOARD);
}
} on DioException catch (e) {
Get.snackbar('خطأ', e.response?.data['message'] ?? 'رمز التحقق غير صحيح');
} finally {
isLoading.value = false;
}
}
}

View File

@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/auth_controller.dart';
class OtpVerifyView extends StatelessWidget {
OtpVerifyView({super.key});
final AuthController controller = Get.find<AuthController>();
final TextEditingController otpController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('التحقق من الرمز')),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'تم إرسال رمز التحقق إلى رقمك',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Obx(() => Text(
controller.phone.value,
textDirection: TextDirection.ltr,
style: const TextStyle(fontSize: 18, color: Colors.grey),
textAlign: TextAlign.center,
)),
const SizedBox(height: 32),
TextField(
controller: otpController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
maxLength: 6,
style: const TextStyle(fontSize: 24, letterSpacing: 8),
decoration: InputDecoration(
counterText: '',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
const SizedBox(height: 24),
Obx(() => ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
onPressed: controller.isLoading.value
? null
: () => controller.verifyOtp(otpController.text),
child: controller.isLoading.value
? const CircularProgressIndicator(color: Colors.white)
: const Text('تحقق', style: TextStyle(fontSize: 16)),
)),
],
),
),
);
}
}

View File

@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/auth_controller.dart';
class PhoneInputView extends StatelessWidget {
PhoneInputView({super.key});
final AuthController controller = Get.put(AuthController());
final TextEditingController phoneController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('تسجيل الدخول')),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Icon(Icons.security, size: 80, color: Color(0xFF0F4C81)),
const SizedBox(height: 32),
const Text(
'أهلاً بك في مُصادَق',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
const Text(
'أدخل رقم هاتفك المسجل في النظام لتسجيل الدخول',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey),
),
const SizedBox(height: 32),
TextField(
controller: phoneController,
keyboardType: TextInputType.phone,
textDirection: TextDirection.ltr,
decoration: InputDecoration(
labelText: 'رقم الهاتف',
prefixIcon: const Icon(Icons.phone),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
const SizedBox(height: 24),
Obx(() => ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
onPressed: controller.isLoading.value
? null
: () => controller.requestOtp(phoneController.text),
child: controller.isLoading.value
? const CircularProgressIndicator(color: Colors.white)
: const Text('إرسال رمز التحقق', style: TextStyle(fontSize: 16)),
)),
],
),
),
);
}
}