logout api added.

design_3.0_TM_Module
Sikander Saleem 2 months ago
parent 19ee892d67
commit b2d3d60152

@ -3,14 +3,14 @@ class URLs {
static const String appReleaseBuildNumber = "22"; static const String appReleaseBuildNumber = "22";
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;
@ -21,7 +21,8 @@ class URLs {
// static String getFileUrl(String file) => (file == null || file.isEmpty) ? null :1 (file.contains("/") ? file : "$_host/attachment/$file"); // static String getFileUrl(String file) => (file == null || file.isEmpty) ? null :1 (file.contains("/") ? file : "$_host/attachment/$file");
// API Routes // API Routes
static get login => "$_baseUrl/MobileAuth/Login"; // web login static get login => "$_baseUrl/MobileAuth/Login";
static get logout => "$_baseUrl/MobileAuth/Logout";
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...

@ -117,6 +117,23 @@ class UserProvider extends ChangeNotifier {
} }
} }
Future<bool> logout(BuildContext context) async {
Response response;
try {
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
response = await ApiManager.instance.post(URLs.logout, body: {});
if (response.statusCode >= 200 && response.statusCode < 300) {
Navigator.pop(context);
return true;
}
Navigator.pop(context);
return false;
} catch (error) {
Navigator.pop(context);
return false;
}
}
/// sign up with User object; /// sign up with User object;
/// return -2 if request in progress /// return -2 if request in progress
/// return -1 if error happen when sending request /// return -1 if error happen when sending request

@ -73,8 +73,8 @@ class AppDrawer extends StatelessWidget {
// 18.height, // 18.height,
drawerItem("setting", context.translation.settings, context).onPress(() => Navigator.of(context).pushNamed(SettingsPage.id)), drawerItem("setting", context.translation.settings, context).onPress(() => Navigator.of(context).pushNamed(SettingsPage.id)),
18.height, 18.height,
if(userProvider.user!=null&&userProvider.user?.employeeIsHMG==false) if (userProvider.user != null && userProvider.user?.employeeIsHMG == false)
drawerItem("swipe", "Swipe History", context) .onPress(() => Navigator.of(context).pushNamed(SwipeHistoryView.routeName)), drawerItem("swipe", "Swipe History", context).onPress(() => Navigator.of(context).pushNamed(SwipeHistoryView.routeName)),
// 18.height, // 18.height,
// drawerItem("report", context.translation.reportBg, context) /*.onPress(() => Navigator.of(context).pushNamed(ReportBugPage.id))*/, // drawerItem("report", context.translation.reportBg, context) /*.onPress(() => Navigator.of(context).pushNamed(ReportBugPage.id))*/,
// 18.height, // 18.height,
@ -87,11 +87,14 @@ class AppDrawer extends StatelessWidget {
builder: (_) => AAlertDialog(title: context.translation.signOut, content: context.translation.logoutAlert), builder: (_) => AAlertDialog(title: context.translation.signOut, content: context.translation.logoutAlert),
); );
if (result) { if (result) {
settingProvider.resetSettings(); bool isSuccess = await userProvider.logout(context);
userProvider.reset(); if (isSuccess) {
Navigator.of(context).pop(); settingProvider.resetSettings();
Navigator.of(context).pop(); userProvider.reset();
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true); Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true);
}
} }
}), }),
18.height, 18.height,

@ -131,9 +131,12 @@ class _LandPageState extends State<LandPage> {
builder: (_) => AAlertDialog(title: context.translation.signOut, content: context.translation.logoutAlert), builder: (_) => AAlertDialog(title: context.translation.signOut, content: context.translation.logoutAlert),
); );
if (result) { if (result) {
Provider.of<SettingProvider>(context, listen: false).resetSettings(); bool isSuccess = await Provider.of<UserProvider>(context, listen: false).logout(context);
Provider.of<UserProvider>(context, listen: false).reset(); if (isSuccess) {
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true); Provider.of<SettingProvider>(context, listen: false).resetSettings();
Provider.of<UserProvider>(context, listen: false).reset();
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true);
}
} }
return false; return false;
}, },

@ -55,9 +55,12 @@ class _SwipeViewState extends State<SwipeView> {
builder: (_) => AAlertDialog(title: context.translation.signOut, content: context.translation.logoutAlert), builder: (_) => AAlertDialog(title: context.translation.signOut, content: context.translation.logoutAlert),
); );
if (result) { if (result) {
Provider.of<SettingProvider>(context, listen: false).resetSettings(); bool isSuccess = await Provider.of<UserProvider>(context, listen: false).logout(context);
Provider.of<UserProvider>(context, listen: false).reset(); if (isSuccess) {
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true); Provider.of<SettingProvider>(context, listen: false).resetSettings();
Provider.of<UserProvider>(context, listen: false).reset();
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true);
}
} }
return false; return false;
}, },

Loading…
Cancel
Save