auth and attachment fixes

design_3.0_TM_Module
waseemabbasi22 2 months ago
parent 187bf717ed
commit 6c3f36944a

@ -3,14 +3,14 @@ class URLs {
static const String appReleaseBuildNumber = "23"; static const String appReleaseBuildNumber = "23";
static const host1 = "https://atomsm.hmg.com"; // production url // static const host1 = "https://atomsm.hmg.com"; // production url
// static const host1 = "https://atomsmdev.hmg.com"; // local DEV url // static const host1 = "https://atomsmdev.hmg.com"; // local DEV url
// static const host1 = "https://atomsmuat.hmg.com"; // local UAT url static const host1 = "https://atomsmuat.hmg.com"; // local UAT url
// static String _baseUrl = "$_host/mobile"; // static String _baseUrl = "$_host/mobile";
// static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis // static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis
// static final String _baseUrl = "$_host/mobile"; // host local UAT static final String _baseUrl = "$_host/mobile"; // host local UAT
static final String _baseUrl = "$_host/v3/mobile"; // v3 for new CM,PM,TM // static final String _baseUrl = "$_host/v3/mobile"; // v3 for new CM,PM,TM
static String _host = host1; static String _host = host1;
@ -22,7 +22,9 @@ class URLs {
// API Routes // API Routes
static get login => "$_baseUrl/MobileAuth/Login"; static get login => "$_baseUrl/MobileAuth/Login";
static get getUserInfo => "$_baseUrl/MobileAuth/GetUserInfo";
static get logout => "$_baseUrl/MobileAuth/Logout"; static get logout => "$_baseUrl/MobileAuth/Logout";
static get enableFaceId => "$_baseUrl/MobileAuth/EnabledFaceId";
static get checkLoginValidation => "$_baseUrl/Account/Authenticate"; // web login static get checkLoginValidation => "$_baseUrl/Account/Authenticate"; // web login
static get checkAppVersion => "$_baseUrl/Account/CheckAppVersion"; // web login static get checkAppVersion => "$_baseUrl/Account/CheckAppVersion"; // web login
//Reset Password Apis... //Reset Password Apis...

@ -32,6 +32,10 @@ class UserProvider extends ChangeNotifier {
User? get user => _user; User? get user => _user;
User? _refreshedUser;
User? get refreshedUser => _refreshedUser;
File? profileImage; File? profileImage;
VerifyOtpModel _verifyOtpModel = VerifyOtpModel(); VerifyOtpModel _verifyOtpModel = VerifyOtpModel();
@ -117,6 +121,37 @@ class UserProvider extends ChangeNotifier {
} }
} }
Future<bool> getUserInfo({ String? fireBaseToken}) async {
// if (_loading == true) return false;
// _loading = true;
notifyListeners();
Response response;
try {
response = await ApiManager.instance.post(URLs.getUserInfo,body: {
'fireBaseToken':fireBaseToken,
});
// _loading = false;
if (response.statusCode >= 200 && response.statusCode < 300) {
_refreshedUser = await User.fromJson(jsonDecode(response.body));
_refreshedUser!.profilePhotoName = URLs.getFileUrl(_user!.profilePhotoName);
notifyListeners();
if (response.statusCode == 200) {
return true;
}
}
notifyListeners();
return false;
} catch (error) {
print('SSL or Network Error: $error');
// _loading = false;
notifyListeners();
return false;
}
}
Future<bool> logout(BuildContext context) async { Future<bool> logout(BuildContext context) async {
Response response; Response response;
try { try {

@ -178,6 +178,22 @@ class SettingProvider extends ChangeNotifier {
} }
} }
Future<bool> checkIsEnabledFaceId({required bool status}) async {
try {
final response = await ApiManager.instance.post(
URLs.enableFaceId,
body: <String, dynamic>{
'isEnabled':status,
},
);
return response.statusCode >= 200 && response.statusCode < 300;
} catch (error) {
return false;
}
}
Future<bool> checkAppUpdate(String buildNumber, String osType) async { Future<bool> checkAppUpdate(String buildNumber, String osType) async {
Response response; Response response;
bool isValid = false; bool isValid = false;

@ -103,7 +103,7 @@ class _DashboardViewState extends State<DashboardView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
bool isNurse = (Provider.of<UserProvider>(context, listen: false).user!.type) == UsersTypes.normal_user; bool isNurse = (Provider.of<UserProvider>(context, listen: false).user?.type) == UsersTypes.normal_user;
final user = Provider.of<UserProvider>(context, listen: false).user; final user = Provider.of<UserProvider>(context, listen: false).user;
return Stack( return Stack(
children: [ children: [

@ -42,6 +42,7 @@ class User {
bool? enableWifi; bool? enableWifi;
bool? enableNFC; bool? enableNFC;
bool? enableQR; bool? enableQR;
bool? isEnabledFaceId;
bool? onlySwipe; bool? onlySwipe;
User({ User({
@ -79,6 +80,7 @@ class User {
this.enableNFC, this.enableNFC,
this.enableQR, this.enableQR,
this.enableWifi, this.enableWifi,
this.isEnabledFaceId,
this.onlySwipe, this.onlySwipe,
}); });
@ -86,9 +88,12 @@ class User {
Future<Map<String, dynamic>> toLoginJson() async { Future<Map<String, dynamic>> toLoginJson() async {
String notificationType = (Platform.isAndroid && !(await FirebaseNotificationManger.isGoogleServicesAvailable())) ? "HMC" : "FCM"; String notificationType = (Platform.isAndroid && !(await FirebaseNotificationManger.isGoogleServicesAvailable())) ? "HMC" : "FCM";
if(FirebaseNotificationManger.token==null){
//calling this agin to check for token as sometimes token is null fresh install..
await FirebaseNotificationManger.getToken();
}
return {"username": userName, "password": password, "fireBaseToken": FirebaseNotificationManger?.token ?? "", "notificationType": notificationType}; return {"username": userName, "password": password, "fireBaseToken": FirebaseNotificationManger?.token ?? "", "notificationType": notificationType};
} }
UsersTypes? get type { UsersTypes? get type {
switch (userRoles?.first.value) { switch (userRoles?.first.value) {
case "R-6": case "R-6":
@ -167,6 +172,7 @@ class User {
map['enableNFC'] = enableNFC; map['enableNFC'] = enableNFC;
map['enableQR'] = enableQR; map['enableQR'] = enableQR;
map['onlySwipe'] = onlySwipe; map['onlySwipe'] = onlySwipe;
map['isEnabledFaceId'] = isEnabledFaceId;
return map; return map;
} }
@ -233,6 +239,7 @@ class User {
enableNFC = json['enableNFC']; enableNFC = json['enableNFC'];
enableQR = json['enableQR']; enableQR = json['enableQR'];
onlySwipe = json['onlySwipe']; onlySwipe = json['onlySwipe'];
isEnabledFaceId = json['isEnabledFaceId'];
} }
} }
@ -300,6 +307,14 @@ class AssetGroup {
data['enabledEngineerTimer'] = enabledEngineerTimer; data['enabledEngineerTimer'] = enabledEngineerTimer;
return data; return data;
} }
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is AssetGroup && runtimeType == other.runtimeType && id == other.id;
@override
int get hashCode => id.hashCode;
} }
class UserContactInfoModel { class UserContactInfoModel {

@ -233,8 +233,17 @@ class _LoginPageState extends State<LoginPage> {
int status = await _userProvider.login(context: context, user: _user); int status = await _userProvider.login(context: context, user: _user);
if (status >= 200 && status < 300 && _userProvider.user!.isAuthenticated! ?? false) { if (status >= 200 && status < 300 && _userProvider.user!.isAuthenticated! ?? false) {
await _settingProvider!.setUser(_userProvider.user!); await _settingProvider!.setUser(_userProvider.user!);
(await SharedPreferences.getInstance()).remove(ASettings.localAuth);
// (await SharedPreferences.getInstance()).remove(ASettings.localAuth);
await _settingProvider!.setRememberMe(_user.userName!, _user.password!, rememberMe); await _settingProvider!.setRememberMe(_user.userName!, _user.password!, rememberMe);
//TODO need to verify this here...
if(_userProvider.user?.isEnabledFaceId==true){
await _settingProvider!.setAuth(_userProvider.user!.isEnabledFaceId!);
}else{
(await SharedPreferences.getInstance()).remove(ASettings.localAuth);
}
Navigator.pushReplacementNamed(context, LandPage.routeName); Navigator.pushReplacementNamed(context, LandPage.routeName);
} else { } else {
Fluttertoast.showToast(msg: _userProvider.user?.message ?? context.translation.failedToCompleteRequest); Fluttertoast.showToast(msg: _userProvider.user?.message ?? context.translation.failedToCompleteRequest);

@ -51,6 +51,7 @@ class _SettingsPageState extends State<SettingsPage> {
if (authStatus) { if (authStatus) {
localAuth = !localAuth; localAuth = !localAuth;
await _settingProvider!.setAuth(localAuth); await _settingProvider!.setAuth(localAuth);
await _settingProvider!.checkIsEnabledFaceId(status: localAuth);
// authController.value = _settingProvider.localAuth == buttonState.toString(); // authController.value = _settingProvider.localAuth == buttonState.toString();
setState(() {}); setState(() {});
} else { } else {

@ -1,6 +1,8 @@
import 'dart:developer';
import 'dart:io'; import 'dart:io';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flare_flutter/flare_actor.dart'; import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -40,6 +42,7 @@ class _SplashPageState extends State<SplashPage> {
@override @override
void initState() { void initState() {
Firebase.initializeApp(); Firebase.initializeApp();
// NotificationManger.initialisation((notificationDetails) { // NotificationManger.initialisation((notificationDetails) {
// // todo @sikander, check notifications payload, because notification model is different to need to check from backend // // todo @sikander, check notifications payload, because notification model is different to need to check from backend
// // SystemNotificationModel notification = SystemNotificationModel.fromJson(json.decode(notificationDetails.payload)); // // SystemNotificationModel notification = SystemNotificationModel.fromJson(json.decode(notificationDetails.payload));
@ -117,7 +120,15 @@ class _SplashPageState extends State<SplashPage> {
if (isSuccess) { if (isSuccess) {
_userProvider.setUser(_settingProvider.user!); _userProvider.setUser(_settingProvider.user!);
if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
await _userProvider.getUserInfo(fireBaseToken:FirebaseNotificationManger.token).then((status) async{
if(status&&_userProvider.refreshedUser!=null){
_userProvider.refreshedUser!.token = _settingProvider.user?.token;
await _settingProvider.setUser(_userProvider.refreshedUser!);
_userProvider.setUser(_settingProvider.user!);
await _settingProvider.setAuth(_settingProvider.user?.isEnabledFaceId??false);
}
});
if (_userProvider.user!.onlySwipe!) { if (_userProvider.user!.onlySwipe!) {
Navigator.of(context).pushNamedAndRemoveUntil(SwipeView.routeName, (routes) => true); Navigator.of(context).pushNamedAndRemoveUntil(SwipeView.routeName, (routes) => true);
} else { } else {

@ -475,10 +475,11 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
} }
onFilePicker() async { onFilePicker() async {
if (widget.attachment.length >= 5) { //TODO removed on request by Backend as they don't have anyissue with large number of files
Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); // if (widget.attachment.length >= 5) {
return; // Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5);
} // return;
// }
ImageSource? source = await showModalBottomSheet<ImageSource>( ImageSource? source = await showModalBottomSheet<ImageSource>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {

Loading…
Cancel
Save