Update: 2026-05-06 02:59:42
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
musadaq-app/lib/features/auth/views/otp_verify_view.dart
Normal file
67
musadaq-app/lib/features/auth/views/otp_verify_view.dart
Normal 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)),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
67
musadaq-app/lib/features/auth/views/phone_input_view.dart
Normal file
67
musadaq-app/lib/features/auth/views/phone_input_view.dart
Normal 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)),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
57
musadaq-app/lib/features/dashboard/views/dashboard_view.dart
Normal file
57
musadaq-app/lib/features/dashboard/views/dashboard_view.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../app/routes/app_pages.dart';
|
||||
import '../../../core/storage/secure_storage.dart';
|
||||
|
||||
class DashboardView extends StatelessWidget {
|
||||
DashboardView({super.key});
|
||||
|
||||
final SecureStorage _storage = SecureStorage();
|
||||
|
||||
void _logout() async {
|
||||
await _storage.clearAll();
|
||||
Get.offAllNamed(AppRoutes.PHONE_INPUT);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('لوحة التحكم - مُصادَق'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: _logout,
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.check_circle, size: 80, color: Colors.green),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'أهلاً بك في مُصادَق!',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'تم تسجيل الدخول بنجاح وتفعيل الـ HMAC.',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.document_scanner),
|
||||
label: const Text('المسح الضوئي (المرحلة 2)'),
|
||||
onPressed: () {
|
||||
Get.snackbar(
|
||||
'قريباً', 'سيتم برمجة هذه الميزة في المرحلة الثانية');
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user