You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
435 lines
20 KiB
Dart
435 lines
20 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
import 'package:mohem_flutter_app/models/basic_member_information_model.dart';
|
|
import 'package:mohem_flutter_app/models/check_mobile_app_version_model.dart';
|
|
import 'package:mohem_flutter_app/models/generic_response_model.dart';
|
|
import 'package:mohem_flutter_app/models/dependent/get_mobile_login_info_dependent_model.dart';
|
|
import 'package:mohem_flutter_app/models/get_mobile_login_info_list_model.dart';
|
|
import 'package:mohem_flutter_app/models/member_login_list_model.dart';
|
|
|
|
class LoginApiClient {
|
|
static final LoginApiClient _instance = LoginApiClient._internal();
|
|
|
|
LoginApiClient._internal();
|
|
|
|
factory LoginApiClient() => _instance;
|
|
|
|
Future<GetMobileLoginInfoListModel?> getMobileLoginInfoNEW(String deviceToken, String deviceType, {int? memberType}) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_GetMobileLoginInfo_NEW";
|
|
Map<String, dynamic> postParams = {};
|
|
postParams["DeviceToken"] = deviceToken;
|
|
postParams["DeviceType"] = deviceType;
|
|
postParams["MemberType"] = memberType ?? ApiConsts.selectedMemberType.value;
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
|
|
return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? (responseData.mohemmGetMobileLoginInfoList!.first) : null;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GetMobileLoginInfoDependentModel?> getMobileLoginInfoNEWDependent(String deviceToken, String deviceType, {int? memberType}) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_GetMobileLoginInfo_NEW_Dependent";
|
|
String effectiveDeviceToken = deviceToken;
|
|
if (effectiveDeviceToken.isEmpty) {
|
|
effectiveDeviceToken = AppState().getDeviceToken ?? "";
|
|
}
|
|
// if (effectiveDeviceToken.isEmpty && !AppState().getIsHuawei) {
|
|
// try {
|
|
// await Firebase.initializeApp();
|
|
// String? tok = await FirebaseMessaging.instance.getToken();
|
|
// if (tok != null && tok.isNotEmpty) {
|
|
// effectiveDeviceToken = tok;
|
|
// AppState().setDeviceToken = tok;
|
|
// }
|
|
// } catch (_) {}
|
|
// }
|
|
|
|
Map<String, dynamic> postParams = {};
|
|
postParams["DeviceToken"] = effectiveDeviceToken;
|
|
postParams["DeviceType"] = deviceType;
|
|
postParams["MemberType"] = memberType ?? MemberType.dependent.value;
|
|
return await ApiClient().postJsonForObject((json) {
|
|
if (kDebugMode) {
|
|
print("Mohemm_GetMobileLoginInfo_NEW_Dependent Response: $json");
|
|
}
|
|
List? list = json['Mohemm_GetMobileLoginInfo_NEW_DependentList'] ??
|
|
json['Mohemm_GetMobileLoginInfo_NEW_Dependent'] ??
|
|
json['Mohemm_GetMobileLoginInfo_DependentList'] ??
|
|
json['Mohemm_GetMobileLoginInfoDependentList'] ??
|
|
json['Mohemm_GetMobileLoginInfoList'] ??
|
|
json['GetMobileLoginInfoList'] ??
|
|
json['Response'] ??
|
|
json['Data'];
|
|
if (list != null && list.isNotEmpty && list.first is Map<String, dynamic>) {
|
|
return GetMobileLoginInfoDependentModel.fromJson(list.first as Map<String, dynamic>);
|
|
}
|
|
if (json is Map<String, dynamic> &&
|
|
(json['DependentID'] != null || json['DepedentName'] != null || json['DOB'] != null || json['NationalID'] != null || json['LoginType'] != null)) {
|
|
return GetMobileLoginInfoDependentModel.fromJson(json);
|
|
}
|
|
return null;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> insertMobileLoginInfoNEW(
|
|
String email, int sessionId, String employeeName, int loginType, String mobileNumber, String userName, String deviceToken, String deviceType,
|
|
{int? memberType}) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_InsertMobileLoginInfo";
|
|
Map<String, dynamic> postParams = {
|
|
"MobileNumber": mobileNumber,
|
|
"P_USER_NAME": userName,
|
|
"UserName": userName,
|
|
"CompanyID": 1, // todo 'sikander' @discuss umer for companyID
|
|
"DeviceToken": deviceToken,
|
|
"LoginType": loginType,
|
|
"EmployeeName": employeeName,
|
|
"P_SESSION_ID": sessionId,
|
|
"P_EMAIL_ADDRESS": email,
|
|
"MemberType": memberType ?? ApiConsts.selectedMemberType.value,
|
|
};
|
|
postParams["DeviceToken"] = deviceToken;
|
|
postParams["DeviceType"] = deviceType;
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
|
|
AppState().setLogged = true;
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> insertMobileLoginInfoDependent({
|
|
required int loginType,
|
|
String? nationalId,
|
|
String? dob,
|
|
String? dependentName,
|
|
String? mobileNumber,
|
|
String? logInTokenID,
|
|
String? tokenID,
|
|
int? sessionId,
|
|
String? email,
|
|
String? deviceToken,
|
|
String? deviceType,
|
|
int? companyId,
|
|
int? versionId,
|
|
int? channel,
|
|
int? memberType,
|
|
BuildContext? context,
|
|
}) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_InsertMobileLoginInfo_Dependent";
|
|
String devType = deviceType ?? (Platform.isAndroid ? "android" : "ios");
|
|
String devToken = (deviceToken != null && deviceToken.isNotEmpty)
|
|
? deviceToken
|
|
: (AppState().getIsHuawei ? AppState().getHuaweiPushToken : (AppState().getDeviceToken ?? ""));
|
|
|
|
String effectiveToken = (tokenID != null && tokenID.isNotEmpty)
|
|
? tokenID
|
|
: (AppState().postParamsObject?.tokenID ?? AppState().authenticationTokenID ?? "");
|
|
|
|
Map<String, dynamic> postParams = {
|
|
"VersionID": versionId ?? 5,
|
|
"Channel": channel ?? 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"MemberType": memberType ?? 1,
|
|
"MobileType": devType,
|
|
"MobileNumber": mobileNumber ?? "",
|
|
"UserName": nationalId ?? "",
|
|
"P_USER_NAME": nationalId ?? "",
|
|
"P_DEP_NATIONAL_ID": nationalId ?? "",
|
|
"P_DEP_BIRTH_DATE": dob ?? "",
|
|
"P_DEPENDENT_NAME": dependentName ?? "",
|
|
"EmployeeName": dependentName ?? "",
|
|
"LogInTokenID": logInTokenID ?? (AppState().postParamsObject?.logInTokenID ?? ""),
|
|
"CompanyID": companyId ?? 1,
|
|
"DeviceType": devType,
|
|
"DeviceToken": devToken,
|
|
"LoginType": loginType,
|
|
"P_SESSION_ID": sessionId ?? (AppState().postParamsObject?.pSessionId ?? 0),
|
|
"TokenID": effectiveToken,
|
|
"P_EMAIL_ADDRESS": email ?? "",
|
|
};
|
|
|
|
if (kDebugMode) {
|
|
print("Mohemm_InsertMobileLoginInfo (Dependent) Request: $postParams");
|
|
}
|
|
|
|
return await ApiClient().postJsonForObject((json) {
|
|
if (kDebugMode) {
|
|
print("Mohemm_InsertMobileLoginInfo (Dependent) Response: $json");
|
|
}
|
|
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
|
|
AppState().setLogged = true;
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<CheckMobileAppVersionModel> checkMobileAppVersion() async {
|
|
String url = "${ApiConsts.utilitiesRest}CheckMobileAppVersion";
|
|
Map<String, dynamic> postParams = {};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) => CheckMobileAppVersionModel.fromJson(json), url, postParams);
|
|
}
|
|
|
|
Future<MemberLoginListModel?> memberLogin(String username, String password) async {
|
|
String url = "${ApiConsts.erpRest}MemberLogin";
|
|
Map<String, dynamic> postParams = {"P_APP_VERSION": "CS", "P_LANGUAGE": "US", "P_PASSWORD": password, "P_USER_NAME": username};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
AppState().postParamsObject?.setLogInTokenID = responseData.logInTokenID;
|
|
return responseData.memberLoginList;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<BasicMemberInformationModel?> mohemmSendActivationCodeByOTPNotificationType(int isMobileFingerPrint, String? mobileNumber, int optSendType, String? pUserName) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_SendActivationCodebyOTPNotificationType";
|
|
Map<String, dynamic> postParams = {
|
|
"IsMobileFingerPrint": isMobileFingerPrint,
|
|
"MobileNumber": mobileNumber,
|
|
"OTP_SendType": optSendType,
|
|
"P_USER_NAME": pUserName,
|
|
"NotificationCenterAppGUID": ApiConsts.notificationCenterAppGUID,
|
|
"NotificationCenterAppSeviceGUID": ApiConsts.notificationCenterLoginServiceGUID,
|
|
};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) => GenericResponseModel.fromJson(json).basicMemberInformation, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> checkActivationCode(bool isDeviceNFC, String? mobileNumber, String activationCode, String? pUserName) async {
|
|
String url = "${ApiConsts.erpRest}CheckActivationCode";
|
|
Map<String, dynamic> postParams = {"IsDeviceNFC": isDeviceNFC, "MobileNumber": mobileNumber, "activationCode": activationCode, "P_USER_NAME": pUserName};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
AppState().postParamsObject?.setTokenID = responseData.tokenID;
|
|
AppState().postParamsObject?.mobileNumber = responseData.basicMemberInformation!.pMOBILENUMBER;
|
|
AppState().postParamsObject?.userName = AppState().getUserName;
|
|
AppState().postParamsObject?.pEmailAddress = responseData.basicMemberInformation!.pEMAILADDRESS;
|
|
AppState().postParamsObject?.pSessionId = responseData.pSESSIONID;
|
|
AppState().postParamsObject?.pUserName = AppState().getUserName;
|
|
AppState().postParamsObject?.pSelectedEmployeeNumber = AppState().getUserName;
|
|
AppState().postParamsObject?.setPLegislationCode = responseData.basicMemberInformation!.pLEGISLATIONCODE;
|
|
AppState().postParamsInitConfig.setPLegislationCode = responseData.basicMemberInformation!.pLEGISLATIONCODE;
|
|
AppState().postParamsObject?.setPayrollCodeStr = responseData.memberInformationList!.first.pAYROLLCODE;
|
|
AppState().setBusinessCardPrivilege = responseData.businessCardPrivilege ?? false;
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<BasicMemberInformationModel?> getBasicUserInformation(String pAppVersion, String pUsername) async {
|
|
String url = "${ApiConsts.erpRest}Get_BasicUserInformation";
|
|
Map<String, dynamic> postParams = {"P_APP_VERSION": pAppVersion, "P_USER_NAME": pUsername};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) => GenericResponseModel.fromJson(json).basicMemberInformation, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> sendPublicActivationCode(String? mobileNumber, String? pUsername) async {
|
|
String url = "${ApiConsts.erpRest}SendPublicActivationCode";
|
|
Map<String, dynamic> postParams = {
|
|
"MobileNumber": mobileNumber,
|
|
"P_MOBILE_NUMBER": mobileNumber,
|
|
"P_USER_NAME": pUsername,
|
|
"NotificationCenterAppGUID": ApiConsts.notificationCenterAppGUID,
|
|
"NotificationCenterAppSeviceGUID": ApiConsts.notificationCenterForgotPasswordServiceGUID,
|
|
};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
AppState().postParamsObject?.setLogInTokenID = responseData.logInTokenID;
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> checkPublicActivationCode(String activationCode, String? pUserName) async {
|
|
String url = "${ApiConsts.erpRest}checkPublicActivationCode";
|
|
Map<String, dynamic> postParams = {"activationCode": activationCode, "P_USER_NAME": pUserName};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
AppState().setForgetPasswordTokenID = responseData.forgetPasswordTokenID;
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> changePasswordForget(String forgetPasswordTokenID, String pNewPassword, String pConfirmNewPassword, String? pUserName) async {
|
|
String url = "${ApiConsts.erpRest}ChangePassword_Forget";
|
|
Map<String, dynamic> postParams = {"P_USER_NAME": pUserName, "ForgetPasswordTokenID": forgetPasswordTokenID, "P_Confirm_NEW_PASSWORD": pConfirmNewPassword, "P_NEW_PASSWORD": pNewPassword};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> changePasswordFromActiveSession(String pOldPassword, String pNewPassword, String pConfirmNewPassword) async {
|
|
String url = "${ApiConsts.erpRest}ChangePassword_FromActiveSession";
|
|
Map<String, dynamic> postParams = {"P_OLD_PASSWORD": pOldPassword, "P_Confirm_NEW_PASSWORD": pConfirmNewPassword, "P_NEW_PASSWORD": pNewPassword};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel> changePasswordFromActiveDirectorySession(String password, String email) async {
|
|
String url = "${ApiConsts.authenticationRest}SetPassword";
|
|
Map<String, dynamic> postParams = {"EmailAddress": email, "Password": password, "generalid": "Cs2020@2016\$2958"};
|
|
postParams.addAll(AppState().postParamsJson);
|
|
postParams["LogInTokenID"] = "@acT!V3D!r3Ct0rY"; // hard code token for active directory
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> memberLoginDependent({
|
|
required String nationalId,
|
|
required String birthDate,
|
|
String? deviceToken,
|
|
String? deviceType,
|
|
BuildContext? context,
|
|
}) async {
|
|
String url = "${ApiConsts.erpRest}MemberLogin_Dependent";
|
|
String devType = deviceType ?? (Platform.isAndroid ? "android" : "ios");
|
|
String devToken = deviceToken ?? "";
|
|
if (devToken.isEmpty) {
|
|
devToken = AppState().getIsHuawei
|
|
? AppState().getHuaweiPushToken
|
|
: (AppState().getDeviceToken ?? "");
|
|
}
|
|
if (devToken.isEmpty && !AppState().getIsHuawei) {
|
|
try {
|
|
String savedToken = await Utils.getStringFromPrefs("P_DEP_DEVICE_TOKEN");
|
|
if (savedToken.isNotEmpty) {
|
|
devToken = savedToken;
|
|
}
|
|
} catch (_) {}
|
|
}
|
|
|
|
Map<String, dynamic> postParams = {
|
|
"VersionID": 20,
|
|
"Channel": 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"DeviceToken": devToken,
|
|
"DeviceType": devType,
|
|
"MobileType": devType,
|
|
"P_DEP_NATIONAL_ID": nationalId,
|
|
"P_DEP_BIRTH_DATE": birthDate,
|
|
};
|
|
if (kDebugMode) {
|
|
print("MemberLogin_Dependent Request: $postParams");
|
|
}
|
|
return await ApiClient().postJsonForObject((json) {
|
|
if (kDebugMode) {
|
|
print("MemberLogin_Dependent Response: $json");
|
|
}
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
if (responseData.logInTokenID != null && responseData.logInTokenID!.isNotEmpty) {
|
|
AppState().postParamsObject?.setLogInTokenID = responseData.logInTokenID;
|
|
}
|
|
String? authToken = (responseData.authenticationTokenID != null && responseData.authenticationTokenID!.trim().isNotEmpty)
|
|
? responseData.authenticationTokenID!.trim()
|
|
: null;
|
|
if (authToken != null && authToken.isNotEmpty) {
|
|
AppState().postParamsObject?.setTokenID = authToken;
|
|
AppState().setAuthenticationTokenID = authToken;
|
|
}
|
|
if (responseData.getWalaplusDepInfoModel != null) {
|
|
AppState().setWalaplusDepInfoModel = responseData.getWalaplusDepInfoModel;
|
|
if (responseData.getWalaplusDepInfoModel?.pDependentName != null &&
|
|
responseData.getWalaplusDepInfoModel!.pDependentName!.trim().isNotEmpty) {
|
|
AppState().setDependentName = responseData.getWalaplusDepInfoModel!.pDependentName!.trim();
|
|
}
|
|
}
|
|
AppState().setUserName = nationalId;
|
|
AppState().postParamsObject?.setUserName = nationalId;
|
|
AppState().postParamsObject?.setPUserName = nationalId;
|
|
AppState().postParamsObject?.channel = 31;
|
|
AppState().postParamsObject?.versionID = 20;
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> mohemmSendOTPDependent({
|
|
required String nationalId,
|
|
required String mobileNumber,
|
|
required String logInTokenID,
|
|
BuildContext? context,
|
|
}) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_SendOTP_Dependent";
|
|
Map<String, dynamic> postParams = {
|
|
"VersionID": 20,
|
|
"Channel": 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"MobileType": Platform.isAndroid ? "android" : "ios",
|
|
"OTP_SendType": 1,
|
|
"MobileNumber": mobileNumber,
|
|
"IsMobileFingerPrint": 0,
|
|
"P_DEP_NATIONAL_ID": nationalId,
|
|
"P_USER_NAME": nationalId,
|
|
"LogInTokenID": logInTokenID,
|
|
};
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
|
|
Future<GenericResponseModel?> mohemmCheckOTPDependent({
|
|
required String logInTokenID,
|
|
required String activationCode,
|
|
required String nationalId,
|
|
required String mobileNumber,
|
|
BuildContext? context,
|
|
}) async {
|
|
String url = "${ApiConsts.erpRest}Mohemm_CheckOTP_Dependent";
|
|
Map<String, dynamic> postParams = {
|
|
"LogInTokenID": logInTokenID,
|
|
"activationCode": activationCode,
|
|
"P_USER_NAME": nationalId,
|
|
"P_DEP_NATIONAL_ID": nationalId,
|
|
"MobileNumber": mobileNumber,
|
|
"VersionID": 20,
|
|
"Channel": 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"MobileType": Platform.isAndroid ? "android" : "ios",
|
|
};
|
|
return await ApiClient().postJsonForObject((json) {
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
String effectiveToken = (responseData.authenticationTokenID != null && responseData.authenticationTokenID!.trim().isNotEmpty)
|
|
? responseData.authenticationTokenID!.trim()
|
|
: (AppState().postParamsObject?.tokenID ?? AppState().authenticationTokenID ?? "");
|
|
|
|
AppState().postParamsObject?.setTokenID = effectiveToken;
|
|
AppState().setAuthenticationTokenID = effectiveToken;
|
|
AppState().postParamsObject?.setLogInTokenID = (responseData.logInTokenID != null && responseData.logInTokenID!.isNotEmpty)
|
|
? responseData.logInTokenID!
|
|
: logInTokenID;
|
|
AppState().postParamsObject?.setUserName = nationalId;
|
|
AppState().postParamsObject?.setPUserName = nationalId;
|
|
AppState().postParamsObject?.setMobileNumer = mobileNumber;
|
|
AppState().postParamsObject?.channel = 31;
|
|
AppState().postParamsObject?.versionID = 20;
|
|
AppState().setUserName = nationalId;
|
|
AppState().isAuthenticated = true;
|
|
AppState().setLogged = true;
|
|
|
|
if (responseData.getWalaplusDepInfoModel != null) {
|
|
AppState().setWalaplusDepInfoModel = responseData.getWalaplusDepInfoModel;
|
|
if (responseData.getWalaplusDepInfoModel?.pDependentName != null &&
|
|
responseData.getWalaplusDepInfoModel!.pDependentName!.trim().isNotEmpty) {
|
|
AppState().setDependentName = responseData.getWalaplusDepInfoModel!.pDependentName!.trim();
|
|
}
|
|
}
|
|
|
|
return responseData;
|
|
}, url, postParams);
|
|
}
|
|
}
|