switch to new image api strat and fix onboarding cache strat
This commit is contained in:
parent
48b434dad9
commit
a5bdee892c
39 changed files with 540 additions and 791 deletions
|
|
@ -4,11 +4,85 @@ import 'package:flutter/material.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class MihAuthenticationServices {
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
bool validEmail(String email) {
|
||||
var regex = RegExp(r'^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$');
|
||||
return regex.hasMatch(email);
|
||||
}
|
||||
|
||||
Future<void> signUserUp(
|
||||
String email,
|
||||
String password,
|
||||
String confirmPassword,
|
||||
BuildContext context,
|
||||
) async {
|
||||
context.read<MzansiProfileProvider>().reset();
|
||||
if (!validEmail(email)) {
|
||||
MihAlertServices().invalidEmailAlert(context);
|
||||
} else if (password != confirmPassword) {
|
||||
MihAlertServices().passwordMatchAlert(context);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
try {
|
||||
Uri uri =
|
||||
Uri.parse("$baseAPI/auth/emailpassword/email/exists?email=$email");
|
||||
var response = await http.get(uri);
|
||||
if (response.statusCode == 200) {
|
||||
var userExists = jsonDecode(response.body);
|
||||
if (userExists["exists"]) {
|
||||
context.pop();
|
||||
MihAlertServices().emailExistsAlert(context);
|
||||
} else {
|
||||
var response2 = await http.post(
|
||||
Uri.parse("$baseAPI/auth/signup"),
|
||||
body:
|
||||
'{"formFields": [{"id": "email","value": "$email"}, {"id": "password","value": "$password"}]}',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
);
|
||||
if (response2.statusCode == 200) {
|
||||
var userCreated = jsonDecode(response2.body);
|
||||
if (userCreated["status"] == "OK") {
|
||||
String uid = await SuperTokens.getUserId();
|
||||
await MihUserServices().createUser(
|
||||
email,
|
||||
uid,
|
||||
context,
|
||||
);
|
||||
context.pop();
|
||||
} else if (userCreated["status"] == "FIELD_ERROR") {
|
||||
context.pop();
|
||||
MihAlertServices().passwordRequirementAlert(context);
|
||||
} else {
|
||||
context.pop();
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
Navigator.of(context).pop();
|
||||
signUpError(error, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> signUserIn(
|
||||
String email,
|
||||
String password,
|
||||
|
|
@ -104,74 +178,28 @@ class MihAuthenticationServices {
|
|||
);
|
||||
}
|
||||
|
||||
void signUpError(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: null,
|
||||
onWindowTapClose: null,
|
||||
backgroundColor: MihColors.red(),
|
||||
windowBody: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 100,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
Center(
|
||||
child: Text(
|
||||
"Email Already Exists",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Text(
|
||||
"Here are some things to keep in mind:",
|
||||
style: TextStyle(
|
||||
color: MihColors.red(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"1) Are you sure you're using the correct email address associated with your account?\n2) Is your caps lock key on? Passwords are case-sensitive.\n3) If you've forgotten your password, no worries! Click on \"Forgot Password?\" to reset it.",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: MihColors.secondary(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 300,
|
||||
elevation: 10,
|
||||
child: Text(
|
||||
"Dismiss",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
void signUpError(Exception error, BuildContext context) {
|
||||
MihAlertServices().errorAdvancedAlert(
|
||||
"Sign Up Error",
|
||||
"An error occurred while signing up: $error Please try again later.",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 200,
|
||||
child: Text(
|
||||
"Dismiss",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
context,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
|
|
@ -12,7 +10,7 @@ class MihDataHelperServices {
|
|||
Future<void> getUserData(MzansiProfileProvider profileProvider) async {
|
||||
String url;
|
||||
await MihUserServices().getMyUserDetails(profileProvider);
|
||||
url = await MihFileApi.getMinioFileUrl(
|
||||
url = MihFileApi.getMinioFileUrlV2(
|
||||
profileProvider.user!.pro_pic_path,
|
||||
);
|
||||
profileProvider.setUserProfilePicUrl(url);
|
||||
|
|
@ -29,12 +27,12 @@ class MihDataHelperServices {
|
|||
Business? responseBusiness = await MihBusinessDetailsServices()
|
||||
.getBusinessDetailsByUser(profileProvider);
|
||||
if (responseBusiness != null) {
|
||||
logoUrl = await MihFileApi.getMinioFileUrl(
|
||||
logoUrl = MihFileApi.getMinioFileUrlV2(
|
||||
profileProvider.business!.logo_path,
|
||||
);
|
||||
profileProvider.setBusinessProfilePicUrl(logoUrl);
|
||||
await MihMyBusinessUserServices().getBusinessUser(profileProvider);
|
||||
signatureUrl = await MihFileApi.getMinioFileUrl(
|
||||
signatureUrl = MihFileApi.getMinioFileUrlV2(
|
||||
profileProvider.businessUser!.sig_path,
|
||||
);
|
||||
profileProvider.setBusinessUserSignatureUrl(signatureUrl);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,23 @@ class MihUserConsentServices {
|
|||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int?> insertUserConsentStatusV2(
|
||||
UserConsent userConsent,
|
||||
) async {
|
||||
try {
|
||||
final response = await http
|
||||
.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/insert/"),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(userConsent.toJson()),
|
||||
)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> updateUserConsentStatus(
|
||||
String latestPrivacyPolicyDate,
|
||||
String latestTermOfServiceDate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue