|
|
|
|
@ -10,9 +10,11 @@ import 'package:http/http.dart';
|
|
|
|
|
import 'package:huawei_fido/huawei_fido.dart';
|
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
import 'package:local_auth/local_auth.dart';
|
|
|
|
|
import 'package:logger/logger.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
|
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
|
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:mc_common_app/main.dart';
|
|
|
|
|
import 'package:mc_common_app/models/general_models/m_response.dart';
|
|
|
|
|
@ -70,19 +72,16 @@ class UserVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> changeUserEmail(
|
|
|
|
|
BuildContext context, String email, String password) async {
|
|
|
|
|
Future<void> changeUserEmail(BuildContext context, String email, String password) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
ChanEmailRespModel otpRequest =
|
|
|
|
|
await userRepo.changeEmailOTPRequest(email, password);
|
|
|
|
|
ChanEmailRespModel otpRequest = await userRepo.changeEmailOTPRequest(email, password);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpRequest.messageStatus == 1) {
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
ConfirmEmailRespModel otpCompare = await userRepo.changeEmail(
|
|
|
|
|
otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
ConfirmEmailRespModel otpCompare = await userRepo.changeEmail(otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpCompare.messageStatus == 1) {
|
|
|
|
|
showMDialog(
|
|
|
|
|
@ -91,9 +90,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
title: LocaleKeys.emailChangedSuccessfully.tr(),
|
|
|
|
|
//"Email is Changed Successfully",
|
|
|
|
|
onClick: () {
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.loginWithPassword,
|
|
|
|
|
(Route<dynamic> route) => true);
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(AppRoutes.loginWithPassword, (Route<dynamic> route) => true);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
@ -107,19 +104,16 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> changeUserMobile(BuildContext context, int countryId,
|
|
|
|
|
String mobileNo, String password) async {
|
|
|
|
|
Future<void> changeUserMobile(BuildContext context, int countryId, String mobileNo, String password) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
ChangeMobileRespModel otpRequest =
|
|
|
|
|
await userRepo.changeMobileNoOTPRequest(countryId, mobileNo, password);
|
|
|
|
|
ChangeMobileRespModel otpRequest = await userRepo.changeMobileNoOTPRequest(countryId, mobileNo, password);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpRequest.messageStatus == 1) {
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
ConfirmMobileRespModel otpCompare = await userRepo.changeMobileNo(
|
|
|
|
|
otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
ConfirmMobileRespModel otpCompare = await userRepo.changeMobileNo(otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpCompare.messageStatus == 1) {
|
|
|
|
|
showMDialog(
|
|
|
|
|
@ -128,9 +122,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
title: LocaleKeys.phoneNumberVerified.tr(),
|
|
|
|
|
//"Phone Number Verified",
|
|
|
|
|
onClick: () {
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.loginWithPassword,
|
|
|
|
|
(Route<dynamic> route) => true);
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(AppRoutes.loginWithPassword, (Route<dynamic> route) => true);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
@ -144,19 +136,16 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> changeUserPassword(
|
|
|
|
|
BuildContext context, String newPassword, String currentPassword) async {
|
|
|
|
|
Future<void> changeUserPassword(BuildContext context, String newPassword, String currentPassword) async {
|
|
|
|
|
if (Utils.passwordValidateStructure(newPassword)) {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
MResponse res =
|
|
|
|
|
await userRepo.changePassword(currentPassword, newPassword);
|
|
|
|
|
MResponse res = await userRepo.changePassword(currentPassword, newPassword);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.passwordIsUpdated.tr());
|
|
|
|
|
//("Password is Updated");
|
|
|
|
|
// navigateWithName(context, AppRoutes.loginWithPassword);
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
|
AppRoutes.loginWithPassword, (Route<dynamic> route) => true);
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(AppRoutes.loginWithPassword, (Route<dynamic> route) => true);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(res.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
@ -255,12 +244,10 @@ class UserVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> confirmPasswordOTP(BuildContext context,
|
|
|
|
|
{required String userToken, required String newPassword}) async {
|
|
|
|
|
Future<void> confirmPasswordOTP(BuildContext context, {required String userToken, required String newPassword}) async {
|
|
|
|
|
if (Utils.passwordValidateStructure(newPassword)) {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
ConfirmPasswordRespModel data =
|
|
|
|
|
await userRepo.forgetPassword(userToken, newPassword);
|
|
|
|
|
ConfirmPasswordRespModel data = await userRepo.forgetPassword(userToken, newPassword);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (data.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.passwordIsUpdated.tr());
|
|
|
|
|
@ -273,8 +260,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> verifyEmail(BuildContext context,
|
|
|
|
|
{required String email, required String userID}) async {
|
|
|
|
|
Future<void> verifyEmail(BuildContext context, {required String email, required String userID}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
VerifyEmailRespModel otpRequest = await userRepo.emailVerify(email, userID);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
@ -283,8 +269,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
MResponse otpCompare = await userRepo.emailVerifyOTPVerify(
|
|
|
|
|
otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
MResponse otpCompare = await userRepo.emailVerifyOTPVerify(otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpCompare.messageStatus == 1) {
|
|
|
|
|
AppState().getUser.data!.userInfo!.isEmailVerified = true;
|
|
|
|
|
@ -300,19 +285,16 @@ class UserVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> forgetPasswordOTPMethod(BuildContext context,
|
|
|
|
|
{required String userToken}) async {
|
|
|
|
|
Future<void> forgetPasswordOTPMethod(BuildContext context, {required String userToken}) async {
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
PasswordOTPCompareResModel otpCompare =
|
|
|
|
|
await userRepo.forgetPasswordOTPCompare(userToken, code);
|
|
|
|
|
PasswordOTPCompareResModel otpCompare = await userRepo.forgetPasswordOTPCompare(userToken, code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpCompare.messageStatus == 1) {
|
|
|
|
|
var userToken = otpCompare.data!.userToken;
|
|
|
|
|
navigateWithName(context, AppRoutes.confirmNewPasswordPage,
|
|
|
|
|
arguments: userToken);
|
|
|
|
|
navigateWithName(context, AppRoutes.confirmNewPasswordPage, arguments: userToken);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(otpCompare.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
@ -320,48 +302,35 @@ class UserVM extends BaseVM {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> forgetPasswordPhoneOTP(BuildContext context,
|
|
|
|
|
{required String countryCode,
|
|
|
|
|
required String userName,
|
|
|
|
|
required int otpType}) async {
|
|
|
|
|
Future<void> forgetPasswordPhoneOTP(BuildContext context, {required String countryCode, required String userName, required int otpType}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response = await userRepo.forgetPasswordOTPRequest(
|
|
|
|
|
countryCode + userName, otpType);
|
|
|
|
|
Response response = await userRepo.forgetPasswordOTPRequest(countryCode + userName, otpType);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
PasswordOTPRequestRespModel otpRequest =
|
|
|
|
|
PasswordOTPRequestRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
PasswordOTPRequestRespModel otpRequest = PasswordOTPRequestRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
if (otpRequest.messageStatus == 1) {
|
|
|
|
|
var userToken = otpRequest.data!.userToken;
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.forgetPasswordMethodPage,
|
|
|
|
|
arguments: userToken);
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.forgetPasswordMethodPage, arguments: userToken);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(otpRequest.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> forgetPasswordEmailOTP(BuildContext context,
|
|
|
|
|
{required String countryCode,
|
|
|
|
|
required String userName,
|
|
|
|
|
required int otpType}) async {
|
|
|
|
|
Future<void> forgetPasswordEmailOTP(BuildContext context, {required String countryCode, required String userName, required int otpType}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response =
|
|
|
|
|
await userRepo.forgetPasswordOTPRequest(userName, otpType);
|
|
|
|
|
Response response = await userRepo.forgetPasswordOTPRequest(userName, otpType);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
PasswordOTPRequestRespModel otpRequest =
|
|
|
|
|
PasswordOTPRequestRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
PasswordOTPRequestRespModel otpRequest = PasswordOTPRequestRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
if (otpRequest.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.codeSentToEmail.tr());
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
PasswordOTPCompareResModel otpCompare = await userRepo
|
|
|
|
|
.forgetPasswordOTPCompare(otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
PasswordOTPCompareResModel otpCompare = await userRepo.forgetPasswordOTPCompare(otpRequest.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (otpCompare.messageStatus == 1) {
|
|
|
|
|
var userToken = otpCompare.data!.userToken;
|
|
|
|
|
navigateWithName(context, AppRoutes.confirmNewPasswordPage,
|
|
|
|
|
arguments: userToken);
|
|
|
|
|
navigateWithName(context, AppRoutes.confirmNewPasswordPage, arguments: userToken);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(otpCompare.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
@ -372,33 +341,25 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtpLoginSelectionPage(BuildContext context,
|
|
|
|
|
{required String userToken,
|
|
|
|
|
required AppType appType,
|
|
|
|
|
String? loginType}) async {
|
|
|
|
|
Future<void> performBasicOtpLoginSelectionPage(BuildContext context, {required String userToken, required AppType appType, String? loginType}) async {
|
|
|
|
|
if (loginType == "3" || loginType == "4") {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
LoginPasswordRespModel user =
|
|
|
|
|
await userRepo.loginV2OTP(userToken, loginType!);
|
|
|
|
|
LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, loginType!);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (user.messageStatus == 1) {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response2 =
|
|
|
|
|
await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", "9999");
|
|
|
|
|
Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", "9999");
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
RegisterUserRespModel verifiedUser =
|
|
|
|
|
RegisterUserRespModel.fromJson(jsonDecode(response2.body));
|
|
|
|
|
RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body));
|
|
|
|
|
if (verifiedUser.messageStatus == 1) {
|
|
|
|
|
User user = User.fromJson(jsonDecode(response2.body));
|
|
|
|
|
if (appType == AppType.provider) {
|
|
|
|
|
if (user.data!.userInfo!.roleId == 5 ||
|
|
|
|
|
user.data!.userInfo!.roleId == 6) {
|
|
|
|
|
if (user.data!.userInfo!.roleId == 5 || user.data!.userInfo!.roleId == 6) {
|
|
|
|
|
AppState().setUser = user;
|
|
|
|
|
SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
|
|
|
|
|
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
|
|
|
|
|
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
|
|
|
|
|
SharedPrefManager.setData(
|
|
|
|
|
jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.dashboard);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(LocaleKeys.onlyProviderApp.tr());
|
|
|
|
|
@ -410,8 +371,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
|
|
|
|
|
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
|
|
|
|
|
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
|
|
|
|
|
SharedPrefManager.setData(
|
|
|
|
|
jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.dashboard);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(LocaleKeys.onlyCustomerApp.tr());
|
|
|
|
|
@ -430,24 +390,18 @@ class UserVM extends BaseVM {
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response2 = await userRepo.loginV2OTPVerify(
|
|
|
|
|
user.data!.userToken ?? "", code);
|
|
|
|
|
Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
RegisterUserRespModel verifiedUser =
|
|
|
|
|
RegisterUserRespModel.fromJson(jsonDecode(response2.body));
|
|
|
|
|
RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body));
|
|
|
|
|
if (verifiedUser.messageStatus == 1) {
|
|
|
|
|
User user = User.fromJson(jsonDecode(response2.body));
|
|
|
|
|
if (appType == AppType.provider) {
|
|
|
|
|
if (user.data!.userInfo!.roleId == 5 ||
|
|
|
|
|
user.data!.userInfo!.roleId == 6) {
|
|
|
|
|
if (user.data!.userInfo!.roleId == 5 || user.data!.userInfo!.roleId == 6) {
|
|
|
|
|
AppState().setUser = user;
|
|
|
|
|
SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
|
|
|
|
|
SharedPrefManager.setUserId(
|
|
|
|
|
user.data!.userInfo!.userId ?? "");
|
|
|
|
|
SharedPrefManager.setRefreshToken(
|
|
|
|
|
user.data!.refreshToken ?? "");
|
|
|
|
|
SharedPrefManager.setData(
|
|
|
|
|
jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
|
|
|
|
|
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
|
|
|
|
|
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.dashboard);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(LocaleKeys.onlyProviderApp.tr());
|
|
|
|
|
@ -457,12 +411,9 @@ class UserVM extends BaseVM {
|
|
|
|
|
if (user.data!.userInfo!.roleId == 4) {
|
|
|
|
|
AppState().setUser = user;
|
|
|
|
|
SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
|
|
|
|
|
SharedPrefManager.setUserId(
|
|
|
|
|
user.data!.userInfo!.userId ?? "");
|
|
|
|
|
SharedPrefManager.setRefreshToken(
|
|
|
|
|
user.data!.refreshToken ?? "");
|
|
|
|
|
SharedPrefManager.setData(
|
|
|
|
|
jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
|
|
|
|
|
SharedPrefManager.setRefreshToken(user.data!.refreshToken ?? "");
|
|
|
|
|
SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson()));
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.dashboard);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(LocaleKeys.onlyCustomerApp.tr());
|
|
|
|
|
@ -479,8 +430,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<String> performApiCallLoginVerificationPage(
|
|
|
|
|
BuildContext context) async {
|
|
|
|
|
Future<String> performApiCallLoginVerificationPage(BuildContext context) async {
|
|
|
|
|
String userToken = "";
|
|
|
|
|
String userName = await SharedPrefManager.getPhoneOrEmail();
|
|
|
|
|
String password = await SharedPrefManager.getUserPassword();
|
|
|
|
|
@ -488,8 +438,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response = await userRepo.loginV1(userName, password);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
LoginPasswordRespModel user =
|
|
|
|
|
LoginPasswordRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
LoginPasswordRespModel user = LoginPasswordRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
if (user.messageStatus == 1) {
|
|
|
|
|
userToken = user.data!.userToken ?? "";
|
|
|
|
|
// navigateWithName(context, AppRoutes.loginMethodSelection, arguments: user.data!.userToken);
|
|
|
|
|
@ -500,8 +449,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
return userToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtpLoginVerificationPage(BuildContext context,
|
|
|
|
|
{required String userToken}) async {
|
|
|
|
|
Future<void> performBasicOtpLoginVerificationPage(BuildContext context, {required String userToken}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, "1");
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
@ -510,11 +458,9 @@ class UserVM extends BaseVM {
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response2 =
|
|
|
|
|
await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", code);
|
|
|
|
|
Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
RegisterUserRespModel verifiedUser =
|
|
|
|
|
RegisterUserRespModel.fromJson(jsonDecode(response2.body));
|
|
|
|
|
RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body));
|
|
|
|
|
if (verifiedUser.messageStatus == 1) {
|
|
|
|
|
User user = User.fromJson(jsonDecode(response2.body));
|
|
|
|
|
AppState().setUser = user;
|
|
|
|
|
@ -529,19 +475,16 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtpLoginVerifyAccountPage(BuildContext context,
|
|
|
|
|
{required String phoneNum, required int otpType}) async {
|
|
|
|
|
Future<void> performBasicOtpLoginVerifyAccountPage(BuildContext context, {required String phoneNum, required int otpType}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
BasicOtpRespModel basicOtp =
|
|
|
|
|
await userRepo.basicOtp(phoneNum, otpType: otpType);
|
|
|
|
|
BasicOtpRespModel basicOtp = await userRepo.basicOtp(phoneNum, otpType: otpType);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (basicOtp.messageStatus == 1) {
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
RegisterUserRespModel user = await userRepo.basicVerify(
|
|
|
|
|
phoneNum, code, basicOtp.data!.userToken ?? "");
|
|
|
|
|
RegisterUserRespModel user = await userRepo.basicVerify(phoneNum, code, basicOtp.data!.userToken ?? "");
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (user.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(user.message ?? "");
|
|
|
|
|
@ -552,8 +495,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
//"Phone Number Verified",
|
|
|
|
|
onClick: () {
|
|
|
|
|
pop(context);
|
|
|
|
|
navigateWithName(context, AppRoutes.profile1,
|
|
|
|
|
arguments: user);
|
|
|
|
|
navigateWithName(context, AppRoutes.profile1, arguments: user);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
@ -567,23 +509,25 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtpLoginWithPasswordPage(BuildContext context,
|
|
|
|
|
{required ClassType type,
|
|
|
|
|
required String countryCode,
|
|
|
|
|
required String phoneNum,
|
|
|
|
|
required String password}) async {
|
|
|
|
|
Future<void> performBasicOtpLoginWithPasswordPage(BuildContext context, {required ClassType type, String? countryCode, required String phoneNum, required String password}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response = await userRepo.loginV1(
|
|
|
|
|
type == ClassType.NUMBER ? countryCode + phoneNum : phoneNum, password);
|
|
|
|
|
type == ClassType.NUMBER && countryCode != null
|
|
|
|
|
? countryCode + phoneNum
|
|
|
|
|
: type == ClassType.NUMBER && countryCode == null
|
|
|
|
|
? phoneNum
|
|
|
|
|
: phoneNum,
|
|
|
|
|
password);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
LoginPasswordRespModel user =
|
|
|
|
|
LoginPasswordRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
LoginPasswordRespModel user = LoginPasswordRespModel.fromJson(jsonDecode(response.body));
|
|
|
|
|
if (user.messageStatus == 1) {
|
|
|
|
|
SharedPrefManager.setPhoneOrEmail(
|
|
|
|
|
type == ClassType.NUMBER ? countryCode + phoneNum : phoneNum);
|
|
|
|
|
SharedPrefManager.setPhoneOrEmail(type == ClassType.NUMBER && countryCode != null
|
|
|
|
|
? countryCode + phoneNum
|
|
|
|
|
: type == ClassType.NUMBER && countryCode == null
|
|
|
|
|
? phoneNum
|
|
|
|
|
: phoneNum);
|
|
|
|
|
SharedPrefManager.setUserPassword(password);
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.loginMethodSelection,
|
|
|
|
|
arguments: user.data!.userToken);
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.loginMethodSelection, arguments: user.data!.userToken);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(user.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
@ -594,14 +538,9 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtpRegisterPage(BuildContext context,
|
|
|
|
|
{required String countryCode,
|
|
|
|
|
required String phoneNum,
|
|
|
|
|
required int role,
|
|
|
|
|
bool isNeedToPassToken = false,
|
|
|
|
|
VoidCallback? reloadPage}) async {
|
|
|
|
|
{required String countryCode, required String phoneNum, required int role, bool isNeedToPassToken = false, VoidCallback? reloadPage}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
BasicOtpRespModel basicOtp = await userRepo.basicOtp(countryCode + phoneNum,
|
|
|
|
|
roleId: role, isNeedToPassToken: isNeedToPassToken);
|
|
|
|
|
BasicOtpRespModel basicOtp = await userRepo.basicOtp(countryCode + phoneNum, roleId: role, isNeedToPassToken: isNeedToPassToken);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (basicOtp.messageStatus == 1) {
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
@ -619,9 +558,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
Utils.showToast(user.message ?? "");
|
|
|
|
|
user.data!.roleId = role;
|
|
|
|
|
user.data!.isNeedToPassToken = isNeedToPassToken;
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.completeProfile,
|
|
|
|
|
arguments: user)
|
|
|
|
|
.then((value) {
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.completeProfile, arguments: user).then((value) {
|
|
|
|
|
if (reloadPage != null) {
|
|
|
|
|
reloadPage();
|
|
|
|
|
}
|
|
|
|
|
@ -647,8 +584,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
}) async {
|
|
|
|
|
bool auth = await CommonAuthImp().authenticate();
|
|
|
|
|
if (auth) {
|
|
|
|
|
performBasicOtpLoginSelectionPage(context!,
|
|
|
|
|
userToken: userToken!, appType: apptype!, loginType: loginType);
|
|
|
|
|
performBasicOtpLoginSelectionPage(context!, userToken: userToken!, appType: apptype!, loginType: loginType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -666,8 +602,7 @@ class UserVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> updateUserImage(BuildContext context) async {
|
|
|
|
|
File? myPick =
|
|
|
|
|
await commanServices.pickFile(context, fileType: FileType.image);
|
|
|
|
|
File? myPick = await commanServices.pickFile(context, fileType: FileType.image);
|
|
|
|
|
if (myPick != null) {
|
|
|
|
|
userRepo.updateUserImage(encodeBase64Image(myPick)).whenComplete(() {
|
|
|
|
|
AppState().getUser.data!.userInfo!.userLocalImage = myPick;
|
|
|
|
|
@ -681,4 +616,20 @@ class UserVM extends BaseVM {
|
|
|
|
|
print(imageBytes);
|
|
|
|
|
return base64Encode(imageBytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> isAlreadyUserLoggedin(BuildContext context) async {
|
|
|
|
|
String uName = await SharedPrefManager.getPhoneOrEmail();
|
|
|
|
|
String pass = await SharedPrefManager.getUserPassword();
|
|
|
|
|
|
|
|
|
|
if (uName.isNotEmpty && pass.isNotEmpty) {
|
|
|
|
|
logger.d(uName);
|
|
|
|
|
if (uName.isNum()) {
|
|
|
|
|
performBasicOtpLoginWithPasswordPage(context, type: ClassType.NUMBER, countryCode: null, phoneNum: uName, password: pass);
|
|
|
|
|
}
|
|
|
|
|
if (uName.isValidEmail()) {
|
|
|
|
|
performBasicOtpLoginWithPasswordPage(context, type: ClassType.EMAIL, countryCode: null, phoneNum: uName, password: pass);
|
|
|
|
|
}
|
|
|
|
|
logger.d("Skip Login Triggered");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|