Update: 2026-05-13 22:58:30
This commit is contained in:
@@ -96,11 +96,18 @@ class AuthController extends GetxController {
|
||||
// Save secure data
|
||||
await _storage.saveToken(data['access_token']);
|
||||
await _storage.saveDeviceSecret(data['device_secret']);
|
||||
if (data['user']['email'] != null) {
|
||||
await _storage.saveEmail(data['user']['email']);
|
||||
}
|
||||
|
||||
AppSnackbar.showSuccess('مرحباً بك', 'تم تسجيل الدخول بنجاح');
|
||||
|
||||
// Navigate to Biometric Setup
|
||||
Get.offAllNamed(AppRoutes.BIOMETRIC_SETUP);
|
||||
// Navigate to Biometric Setup (unless it's the reviewer)
|
||||
if (data['user']['email'] == 'reviewer@musadaq.jo') {
|
||||
Get.offAllNamed(AppRoutes.MAIN);
|
||||
} else {
|
||||
Get.offAllNamed(AppRoutes.BIOMETRIC_SETUP);
|
||||
}
|
||||
}
|
||||
} on DioException catch (e, stackTrace) {
|
||||
AppLogger.error('OTP Verify Failed', e.response?.data, stackTrace);
|
||||
@@ -109,4 +116,72 @@ class AuthController extends GetxController {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loginWithEmail(String email, String password) async {
|
||||
try {
|
||||
if (email.trim().isEmpty || password.trim().isEmpty) {
|
||||
AppSnackbar.showError('خطأ', 'الرجاء إدخال البريد الإلكتروني وكلمة المرور');
|
||||
return;
|
||||
}
|
||||
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/login', data: {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'device_id': deviceId,
|
||||
'device_name': deviceName,
|
||||
'platform': Platform.operatingSystem,
|
||||
'app_version': '1.0.0', // Should ideally come from PackageInfo
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
AppLogger.print('Email Login Success. Tokens received.');
|
||||
final data = response.data['data'];
|
||||
|
||||
// Save secure data
|
||||
await _storage.saveToken(data['access_token']);
|
||||
// Note: auth/login might not return device_secret, handle if missing
|
||||
if (data['device_secret'] != null) {
|
||||
await _storage.saveDeviceSecret(data['device_secret']);
|
||||
}
|
||||
|
||||
if (data['user']['email'] != null) {
|
||||
await _storage.saveEmail(data['user']['email']);
|
||||
}
|
||||
|
||||
AppSnackbar.showSuccess('مرحباً بك', 'تم تسجيل الدخول بنجاح');
|
||||
|
||||
// Navigate to Dashboard for reviewer, else Biometric Setup
|
||||
if (email == 'reviewer@musadaq.jo') {
|
||||
Get.offAllNamed(AppRoutes.MAIN);
|
||||
} else {
|
||||
Get.offAllNamed(AppRoutes.BIOMETRIC_SETUP);
|
||||
}
|
||||
}
|
||||
} on DioException catch (e, stackTrace) {
|
||||
AppLogger.error('Email Login Failed', e.response?.data, stackTrace);
|
||||
String errorMessage = 'بيانات الدخول غير صحيحة';
|
||||
if (e.response?.data != null && e.response?.data is Map) {
|
||||
errorMessage = e.response?.data['message'] ?? errorMessage;
|
||||
}
|
||||
AppSnackbar.showError('خطأ', errorMessage);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user