Update: 2026-05-06 02:59:42
This commit is contained in:
47
musadaq-app/lib/app/routes/app_pages.dart
Normal file
47
musadaq-app/lib/app/routes/app_pages.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../features/auth/views/phone_input_view.dart';
|
||||
import '../../features/auth/views/otp_verify_view.dart';
|
||||
import '../../features/dashboard/views/dashboard_view.dart';
|
||||
|
||||
part 'app_routes.dart';
|
||||
|
||||
class AppPages {
|
||||
static const INITIAL = AppRoutes.SPLASH;
|
||||
|
||||
static final routes = [
|
||||
GetPage(
|
||||
name: AppRoutes.SPLASH,
|
||||
page: () {
|
||||
// Simple splash logic to navigate to login after delay
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
Get.offAllNamed(AppRoutes.PHONE_INPUT);
|
||||
});
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.security, size: 100, color: Color(0xFF0F4C81)),
|
||||
SizedBox(height: 24),
|
||||
CircularProgressIndicator(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
GetPage(
|
||||
name: AppRoutes.PHONE_INPUT,
|
||||
page: () => PhoneInputView(),
|
||||
),
|
||||
GetPage(
|
||||
name: AppRoutes.OTP_VERIFY,
|
||||
page: () => OtpVerifyView(),
|
||||
),
|
||||
GetPage(
|
||||
name: AppRoutes.DASHBOARD,
|
||||
page: () => DashboardView(),
|
||||
),
|
||||
];
|
||||
}
|
||||
10
musadaq-app/lib/app/routes/app_routes.dart
Normal file
10
musadaq-app/lib/app/routes/app_routes.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
part of 'app_pages.dart';
|
||||
|
||||
abstract class AppRoutes {
|
||||
static const SPLASH = '/splash';
|
||||
static const PHONE_INPUT = '/phone-input';
|
||||
static const OTP_VERIFY = '/otp-verify';
|
||||
static const BIOMETRIC_SETUP = '/biometric-setup';
|
||||
static const LOGIN = '/login';
|
||||
static const DASHBOARD = '/dashboard';
|
||||
}
|
||||
41
musadaq-app/lib/app/theme/app_theme.dart
Normal file
41
musadaq-app/lib/app/theme/app_theme.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppTheme {
|
||||
static const Color primaryColor = Color(0xFF0F4C81); // Navy Blue
|
||||
static const Color secondaryColor = Color(0xFFD4AF37); // Gold
|
||||
static const Color tealColor = Color(0xFF008080); // Teal
|
||||
|
||||
static final ThemeData lightTheme = ThemeData(
|
||||
brightness: Brightness.light,
|
||||
primaryColor: primaryColor,
|
||||
colorScheme: const ColorScheme.light(
|
||||
primary: primaryColor,
|
||||
secondary: secondaryColor,
|
||||
),
|
||||
scaffoldBackgroundColor: const Color(0xFFF8F9FA),
|
||||
appBarTheme: const AppBarTheme(
|
||||
backgroundColor: primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
centerTitle: true,
|
||||
elevation: 0,
|
||||
),
|
||||
fontFamily: 'Tajawal', // Suggested Arabic Font
|
||||
);
|
||||
|
||||
static final ThemeData darkTheme = ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
primaryColor: primaryColor,
|
||||
colorScheme: const ColorScheme.dark(
|
||||
primary: primaryColor,
|
||||
secondary: secondaryColor,
|
||||
),
|
||||
scaffoldBackgroundColor: const Color(0xFF121212),
|
||||
appBarTheme: const AppBarTheme(
|
||||
backgroundColor: Color(0xFF1E1E1E),
|
||||
foregroundColor: Colors.white,
|
||||
centerTitle: true,
|
||||
elevation: 0,
|
||||
),
|
||||
fontFamily: 'Tajawal',
|
||||
);
|
||||
}
|
||||
34
musadaq-app/lib/core/network/dio_client.dart
Normal file
34
musadaq-app/lib/core/network/dio_client.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'hmac_interceptor.dart';
|
||||
import '../storage/secure_storage.dart';
|
||||
|
||||
class DioClient {
|
||||
static const String baseUrl = 'https://musadaq.intaleqapp.com/api/v1/'; // Update with actual URL
|
||||
late final Dio dio;
|
||||
|
||||
DioClient() {
|
||||
dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: baseUrl,
|
||||
connectTimeout: const Duration(seconds: 15),
|
||||
receiveTimeout: const Duration(seconds: 15),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Add Interceptors
|
||||
dio.interceptors.add(HmacInterceptor(SecureStorage()));
|
||||
|
||||
// Logging interceptor for debug
|
||||
dio.interceptors.add(LogInterceptor(
|
||||
requestBody: true,
|
||||
responseBody: true,
|
||||
error: true,
|
||||
));
|
||||
}
|
||||
|
||||
Dio get client => dio;
|
||||
}
|
||||
54
musadaq-app/lib/core/network/hmac_interceptor.dart
Normal file
54
musadaq-app/lib/core/network/hmac_interceptor.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../storage/secure_storage.dart';
|
||||
|
||||
class HmacInterceptor extends Interceptor {
|
||||
final SecureStorage secureStorage;
|
||||
|
||||
HmacInterceptor(this.secureStorage);
|
||||
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
|
||||
final token = await secureStorage.getToken();
|
||||
final deviceSecret = await secureStorage.getDeviceSecret();
|
||||
|
||||
if (token != null) {
|
||||
options.headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
|
||||
// Only sign if we have a device secret (after login)
|
||||
if (deviceSecret != null) {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
// Create signature payload
|
||||
String payload = '${options.method}:${options.path}:$timestamp';
|
||||
|
||||
// Include body in signature if present
|
||||
if (options.data != null && options.data is Map) {
|
||||
payload += ':${jsonEncode(options.data)}';
|
||||
}
|
||||
|
||||
// Generate HMAC-SHA256
|
||||
final key = utf8.encode(deviceSecret);
|
||||
final bytes = utf8.encode(payload);
|
||||
final hmac = Hmac(sha256, key);
|
||||
final digest = hmac.convert(bytes);
|
||||
|
||||
// Attach headers
|
||||
options.headers['X-Timestamp'] = timestamp;
|
||||
options.headers['X-Signature'] = digest.toString();
|
||||
}
|
||||
|
||||
super.onRequest(options, handler);
|
||||
}
|
||||
|
||||
@override
|
||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||
if (err.response?.statusCode == 401) {
|
||||
// Handle Token Expiry / Unauthorized
|
||||
// TODO: Trigger logout or token refresh
|
||||
}
|
||||
super.onError(err, handler);
|
||||
}
|
||||
}
|
||||
29
musadaq-app/lib/core/storage/secure_storage.dart
Normal file
29
musadaq-app/lib/core/storage/secure_storage.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class SecureStorage {
|
||||
final FlutterSecureStorage _storage = const FlutterSecureStorage();
|
||||
|
||||
static const String _keyToken = 'jwt_token';
|
||||
static const String _keyDeviceSecret = 'device_secret';
|
||||
static const String _keyUserId = 'user_id';
|
||||
|
||||
Future<void> saveToken(String token) async {
|
||||
await _storage.write(key: _keyToken, value: token);
|
||||
}
|
||||
|
||||
Future<String?> getToken() async {
|
||||
return await _storage.read(key: _keyToken);
|
||||
}
|
||||
|
||||
Future<void> saveDeviceSecret(String secret) async {
|
||||
await _storage.write(key: _keyDeviceSecret, value: secret);
|
||||
}
|
||||
|
||||
Future<String?> getDeviceSecret() async {
|
||||
return await _storage.read(key: _keyDeviceSecret);
|
||||
}
|
||||
|
||||
Future<void> clearAll() async {
|
||||
await _storage.deleteAll();
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
'قريباً', 'سيتم برمجة هذه الميزة في المرحلة الثانية');
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
30
musadaq-app/lib/main.dart
Normal file
30
musadaq-app/lib/main.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'app/routes/app_pages.dart';
|
||||
import 'app/theme/app_theme.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// TODO: Initialize ObjectBox, SecureStorage, and DioClient here
|
||||
|
||||
runApp(const MusadaqApp());
|
||||
}
|
||||
|
||||
class MusadaqApp extends StatelessWidget {
|
||||
const MusadaqApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp(
|
||||
title: 'Musadaq',
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
initialRoute: AppPages.INITIAL,
|
||||
getPages: AppPages.routes,
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: const Locale('ar', 'JO'), // Arabic by default
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user