|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/api_mapper_class.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/basic_member_information_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/chane_forgot_password_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/check_activation_code_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/check_mobile_app_version_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/generic_mapper_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/generic_response_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) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}Mohemm_GetMobileLoginInfo_NEW";
|
|
|
|
|
Map<String, dynamic> postParams = {};
|
|
|
|
|
postParams["DeviceToken"] = deviceToken;
|
|
|
|
|
postParams["DeviceType"] = deviceType;
|
|
|
|
|
// return await ApiClient().postJsonForObject((json) {
|
|
|
|
|
// GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
|
|
|
|
|
// print(jsonDecode(json["data"].first));
|
|
|
|
|
// GetMobileLoginInfoListModel? modelData= GetMobileLoginInfoListModel.fromRawJson(jsonDecode(json["data"].first));
|
|
|
|
|
// print("getMobileLoginInfoNEW: ${modelData.toJson()}");
|
|
|
|
|
// // return (responseData.mohemmGetMobileLoginInfoList?.length ?? 0) > 0 ? (responseData.mohemmGetMobileLoginInfoList!.first) : null;
|
|
|
|
|
// return modelData;
|
|
|
|
|
// }, url, postParams);
|
|
|
|
|
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
GetMobileLoginInfoListModel ress = await ApiClassMapper().handleApiEndpoint(endpoint: "Mohemm_GetMobileLoginInfo_NEW", jsonData: res.data);
|
|
|
|
|
return ress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool?> insertMobileLoginInfoNEW(String email, int sessionId, String employeeName, int loginType, String mobileNumber, String userName, String deviceToken, String deviceType) async {
|
|
|
|
|
//String url = "${ApiConsts.authRest}Mohemm_Insert_MobileDeviceInfo";
|
|
|
|
|
String url = "${ApiConsts.authRest}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_EMAIL_ADDRESS": email,
|
|
|
|
|
"gender": 1, //todo
|
|
|
|
|
};
|
|
|
|
|
postParams["deviceToken"] = deviceToken;
|
|
|
|
|
postParams["deviceType"] = deviceType;
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
dynamic ress = await ApiClassMapper().handleApiEndpoint(endpoint: "Mohemm_Insert_MobileDeviceInfo", jsonData: res);
|
|
|
|
|
|
|
|
|
|
return ress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ApiResponse?> checkMobileAppVersion() async {
|
|
|
|
|
String url = "${ApiConsts.authRest}CheckMobileAppVersion";
|
|
|
|
|
Map<String, dynamic> postParams = {};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, returnJsonData: false);
|
|
|
|
|
return ApiResponse.fromJson(response);
|
|
|
|
|
|
|
|
|
|
// if (res.data == null || res.data!.isEmpty) {
|
|
|
|
|
// return CheckMobileAppVersionModel(data: ""); // Handle the case where response data is null
|
|
|
|
|
// } else {
|
|
|
|
|
// CheckMobileAppVersionModel result = await ApiClassMapper().handleApiEndpoint(endpoint: "CheckMobileAppVersion", jsonData: response);
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<MemberLoginListModel> memberLogin(String username, String password) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}MemberLogin";
|
|
|
|
|
Map<String, dynamic> postParams = {"P_APP_VERSION": "CS", "P_LANGUAGE": "US", "P_PASSWORD": password, "P_USER_NAME": username};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
MemberLoginListModel ress = await ApiClassMapper().handleApiEndpoint(endpoint: "MemberLogin", jsonData: res.data);
|
|
|
|
|
AppState().postParamsObject?.setLogInTokenID = ress.logInTokenId;
|
|
|
|
|
|
|
|
|
|
print("getLogInTokenID: ${AppState().postParamsObject?.getLogInTokenID}");
|
|
|
|
|
return ress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<BasicMemberInformationModel?> mohemmSendActivationCodeByOTPNotificationType(int isMobileFingerPrint, String? mobileNumber, int optSendType, String? pUserName) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}Mohemm_SendActivationCodebyOTPNotificationType";
|
|
|
|
|
Map<String, dynamic> postParams = {"IsMobileFingerPrint": isMobileFingerPrint, "MobileNumber": mobileNumber, "OTP_SendType": optSendType, "P_USER_NAME": pUserName};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
postParams["logInTokenID"] = AppState().postParamsObject?.getLogInTokenID;
|
|
|
|
|
print(postParams);
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
AppState().postParamsObject?.setLogInTokenID = res.data["logInTokenID"] ?? AppState().postParamsObject?.getLogInTokenID;
|
|
|
|
|
return await ApiClassMapper().handleApiEndpoint(endpoint: "Mohemm_SendActivationCodebyOTPNotificationType", jsonData: res.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<CheckActivationCodeModel?> checkActivationCode(bool isDeviceNFC, String? mobileNumber, String activationCode, String? pUserName) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}CheckActivationCode";
|
|
|
|
|
Map<String, dynamic> postParams = {"IsDeviceNFC": isDeviceNFC, "MobileNumber": mobileNumber, "ActivationCode": activationCode, "P_USER_NAME": pUserName};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
postParams["logInTokenID"] = AppState().postParamsObject?.getLogInTokenID;
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
AppState().isLogged = true;
|
|
|
|
|
return await ApiClassMapper().handleApiEndpoint(endpoint: "CheckActivationCode", jsonData: res.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<BasicMemberInformationModel?> getBasicUserInformation(String pAppVersion, String pUsername) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}Get_BasicUserInformation";
|
|
|
|
|
Map<String, dynamic> postParams = {"P_APP_VERSION": pAppVersion, "P_USER_NAME": pUsername};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
return await ApiClassMapper().handleApiEndpoint(endpoint: "Get_BasicUserInformation", jsonData: res.data);
|
|
|
|
|
// return await ApiClient().postJsonForObject((json) => GenericResponseModel.fromJson(json).basicMemberInformation, url, postParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GenericResponseModel?> sendPublicActivationCode(String? mobileNumber, String? pUsername) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}SendPublicActivationCode"; // todo @zahoor, not found in swagger
|
|
|
|
|
Map<String, dynamic> postParams = {
|
|
|
|
|
"mobileNumber": mobileNumber,
|
|
|
|
|
"p_MOBILE_NUMBER": mobileNumber,
|
|
|
|
|
"p_USER_NAME": pUsername,
|
|
|
|
|
};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
return await ApiClient().postJsonForObject((json) {
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(json);
|
|
|
|
|
GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
|
|
|
|
AppState().postParamsObject?.setLogInTokenID = res.data['logInTokenID'] ?? AppState().postParamsObject?.getLogInTokenID;
|
|
|
|
|
AppState().postParamsObject?.setTokenID = res.data['logInTokenID'];
|
|
|
|
|
return responseData;
|
|
|
|
|
}, url, postParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GenericResponseModel?> checkPublicActivationCode(String activationCode, String? pUserName) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}checkPublicActivationCode"; // todo @zahoor, not found in swagger
|
|
|
|
|
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<ChangePasswordForgetModel?> changePasswordForget(String forgetPasswordTokenID, String pNewPassword, String pConfirmNewPassword, String? pUserName) async {
|
|
|
|
|
String url = "${ApiConsts.authRest}ChangePassword_Forget"; // todo @zahoor, not found in swagger
|
|
|
|
|
Map<String, dynamic> postParams = {"P_USER_NAME": pUserName, "ForgetPasswordTokenID": forgetPasswordTokenID, "P_Confirm_NEW_PASSWORD": pConfirmNewPassword, "P_NEW_PASSWORD": pNewPassword};
|
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
|
|
|
dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams);
|
|
|
|
|
ApiResponse res = ApiResponse.fromJson(response);
|
|
|
|
|
return await ApiClassMapper().handleApiEndpoint(endpoint: "ChangePassword_Forget", jsonData: res.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"; // todo @zahoor, not found in swagger
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|