fist commit ftc staff app clone
This commit is contained in:
57
lib/controllers/auth_module/agency_sign_in_controller.dart
Normal file
57
lib/controllers/auth_module/agency_sign_in_controller.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AgencySignInController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
final TextEditingController emailPhoneController = TextEditingController();
|
||||
RxString emailPhoneErrorMsg = "".obs;
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
bool validateEmailPhone() {
|
||||
if(emailPhoneController.text.isEmpty) {
|
||||
emailPhoneErrorMsg.value = ConstantText.kEmailPhoneIsRequired;
|
||||
} else {
|
||||
emailPhoneErrorMsg.value = "";
|
||||
}
|
||||
return emailPhoneErrorMsg.isEmpty;
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
void onSendCodeButton() async {
|
||||
if(validateEmailPhone()){
|
||||
isLoading.value = true;
|
||||
var response = await AuthService().passwordLessLogin(
|
||||
email: emailPhoneController.text,
|
||||
);
|
||||
if (response is bool) {
|
||||
await LocalStorageManager.saveSession(
|
||||
tokenKey: LocalStorageKeys.kSaveEmailKey,
|
||||
tokenValue: emailPhoneController.text,
|
||||
);
|
||||
isLoading.value = false;
|
||||
await Navigator.pushNamed(
|
||||
screenKey.currentContext!,
|
||||
CustomRouteNames.kOTPScreenRoute,
|
||||
arguments: emailPhoneController.text,
|
||||
);
|
||||
} else {
|
||||
isLoading.value = false;
|
||||
FrequentFunctions.showToast(
|
||||
message: response["message"],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
emailPhoneController.dispose();
|
||||
Get.delete<AgencySignInController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
4
lib/controllers/auth_module/export_auth_module.dart
Normal file
4
lib/controllers/auth_module/export_auth_module.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
export 'splash_screen_controller.dart';
|
||||
export 'sing_in_screen_controller.dart';
|
||||
export 'agency_sign_in_controller.dart';
|
||||
export 'otp_screen_controller.dart';
|
||||
53
lib/controllers/auth_module/otp_screen_controller.dart
Normal file
53
lib/controllers/auth_module/otp_screen_controller.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class OTPScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
// final TextEditingController otpController = TextEditingController(text: "");
|
||||
final TextEditingController otpController = TextEditingController(text: "123456");
|
||||
RxString otpErrorMsg = "".obs;
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
bool validateOTP() {
|
||||
if(otpController.text.isEmpty) {
|
||||
otpErrorMsg.value = ConstantText.kPleaseInputOTP;
|
||||
} else if(otpController.text.length<6) {
|
||||
otpErrorMsg.value = ConstantText.kInvalidOTP;
|
||||
} else {
|
||||
otpErrorMsg.value = "";
|
||||
}
|
||||
return otpErrorMsg.isEmpty;
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
void onSubmitButton() async {
|
||||
if (validateOTP()) {
|
||||
var response = await AuthService().verifyOtp(
|
||||
verificationCode: otpController.text,
|
||||
).showLoader();
|
||||
if (response is bool && response == true) {
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
screenKey.currentContext!,
|
||||
CustomRouteNames.kDashboardScreenRoute,
|
||||
(route) => false,
|
||||
);
|
||||
} else if (response is String) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
} else {
|
||||
FrequentFunctions.showToast(message: response.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
otpController.dispose();
|
||||
Get.delete<OTPScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
116
lib/controllers/auth_module/sing_in_screen_controller.dart
Normal file
116
lib/controllers/auth_module/sing_in_screen_controller.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SignInScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
// final emailController = TextEditingController(text: "");
|
||||
// final passwordController = TextEditingController(text: "");
|
||||
final emailController = TextEditingController(text: "ashu@gmail.com");
|
||||
final passwordController = TextEditingController(text: "Abc@1234");
|
||||
final emailErrorMsg = "".obs, passwordErrorMsg = "".obs;
|
||||
// final isRememberMe = false.obs;
|
||||
final isLoading = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
emailController.text =
|
||||
LocalStorageManager.getSessionToken(tokenKey: LocalStorageKeys.kSaveEmailKey);
|
||||
// isRememberMe.value = _sessionManagement
|
||||
// .getSessionToken(tokenKey: SessionKeys.kRememberMeKey)
|
||||
// .toLowerCase() ==
|
||||
// "true";
|
||||
emailController.text = 'ashu@gmail.com';
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
bool validateEmail() {
|
||||
if (emailController.text.isEmpty) {
|
||||
emailErrorMsg.value = ConstantText.kEmailIsRequired;
|
||||
} else if (!GetUtils.isEmail(emailController.text)) {
|
||||
emailErrorMsg.value = ConstantText.kInvalidEmail;
|
||||
} else {
|
||||
emailErrorMsg.value = "";
|
||||
}
|
||||
return emailErrorMsg.isEmpty;
|
||||
}
|
||||
|
||||
bool validatePassword() {
|
||||
if (passwordController.text.isEmpty) {
|
||||
passwordErrorMsg.value = ConstantText.kPasswordIsRequired;
|
||||
} else {
|
||||
passwordErrorMsg.value = "";
|
||||
}
|
||||
return passwordErrorMsg.isEmpty;
|
||||
}
|
||||
|
||||
void onLogInButton() async {
|
||||
if (validateEmail() & validatePassword()) {
|
||||
isLoading.value = true;
|
||||
var response = await AuthService().loginUser(
|
||||
email: emailController.text,
|
||||
password: passwordController.text,
|
||||
);
|
||||
if (response is bool) {
|
||||
// if (isRememberMe.isTrue) {
|
||||
// await _sessionManagement.saveSession(
|
||||
// tokenKey: SessionKeys.kRememberMeKey,
|
||||
// tokenValue: "${isRememberMe.isTrue}",
|
||||
// );
|
||||
// }
|
||||
await LocalStorageManager.saveSession(
|
||||
tokenKey: LocalStorageKeys.kSaveEmailKey,
|
||||
tokenValue: emailController.text,
|
||||
);
|
||||
isLoading.value = false;
|
||||
await Navigator.pushNamed(
|
||||
screenKey.currentContext!,
|
||||
CustomRouteNames.kOTPScreenRoute,
|
||||
);
|
||||
} else {
|
||||
isLoading.value = false;
|
||||
FrequentFunctions.showToast(
|
||||
message: response["message"],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onForgotButton() {
|
||||
showDialog(
|
||||
context: screenKey.currentState!.context,
|
||||
builder: (BuildContext context) {
|
||||
return CustomForgetPasswordDialog(
|
||||
dialogButtonCloseText: "Cancel",
|
||||
dialogButtonAcceptText: "Email Link",
|
||||
dialogMessageText:
|
||||
"A password reset link will be sent to your registered email.",
|
||||
dialogMessageTextBold: "",
|
||||
headingText: "Send Reset Password Link",
|
||||
// acceptFunction: (String email) async {
|
||||
// // await AuthService().forgetPassword(email: email);
|
||||
// },
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void onAgencyLogInButton() async {
|
||||
await Navigator.pushNamed(
|
||||
screenKey.currentContext!,
|
||||
CustomRouteNames.kAgencySignInScreenRoute,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
emailController.dispose();
|
||||
passwordController.dispose();
|
||||
Get.delete<SignInScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
119
lib/controllers/auth_module/splash_screen_controller.dart
Normal file
119
lib/controllers/auth_module/splash_screen_controller.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/utilities/app_session_manager.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
|
||||
class SplashScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
5.seconds.delay(() {
|
||||
// _gotoLoginScreen();
|
||||
|
||||
if (_loginTokenNotFound) {
|
||||
_gotoLoginScreen();
|
||||
} else {
|
||||
_checkOngoingShift();
|
||||
}
|
||||
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
//true if login token found in local storage
|
||||
bool get _loginTokenNotFound {
|
||||
return LocalStorageManager.getLoginToken().isEmpty;
|
||||
}
|
||||
|
||||
DateTime _getDateTimeObjFor({required int hour, required int minute}) {
|
||||
return DateTime(DateTime.now().year, DateTime.now().month,
|
||||
DateTime.now().day, hour, minute);
|
||||
}
|
||||
|
||||
//Todo: If Shift present then logout half an hour before start time
|
||||
// Else logout 7am uk time
|
||||
_checkOngoingShift() {
|
||||
final shift = LocalStorageManager.getOngoingShift();
|
||||
|
||||
//if shift present
|
||||
if (shift != null) {
|
||||
///boolean value [isShiftExpired] to check
|
||||
///if there is an expired shift in local storage.
|
||||
final isShiftExpired = shift.endTime!.isBefore(TimeOfDay.now());
|
||||
if (isShiftExpired) {
|
||||
LocalStorageManager.removeOngoingShift();
|
||||
} else {
|
||||
final shiftNotStartedYet = shift.startTime!.isAfter(TimeOfDay.now());
|
||||
|
||||
if (shiftNotStartedYet) {
|
||||
///checking if shift is going to start in 30 minutes or less
|
||||
if ((shift.startTime!.minute - TimeOfDay.now().minute) <= 30) {
|
||||
_gotoLoginScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
///checking if shift is going to start in 60 minutes or less, then
|
||||
///start session timer which will alert session expire to user
|
||||
///if 30minutes left in shift start and logout the user.
|
||||
if ((shift.startTime!.minute - TimeOfDay.now().minute) <= 60) {
|
||||
//starting session timer
|
||||
|
||||
final sessionExpireDateTime = _getDateTimeObjFor(
|
||||
hour: shift.startTime!.hour,
|
||||
minute: shift.startTime!.minute,
|
||||
).subtract(30.minutes);
|
||||
|
||||
final millisLeft = sessionExpireDateTime.millisecondsSinceEpoch -
|
||||
DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
AppSessionManager.instance.startSessionTimer(millisLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final currentTime = TimeOfDay.now();
|
||||
const time7am = TimeOfDay(hour: 7, minute: 0);
|
||||
|
||||
///checking if current time is before [7:00 AM]
|
||||
if (currentTime.isBefore(time7am)) {
|
||||
///checking if remaining 30 minutes or less time
|
||||
if ((time7am.minute - currentTime.minute) <= 30) {
|
||||
//starting session timer
|
||||
final dateTime7am =
|
||||
_getDateTimeObjFor(hour: time7am.hour, minute: time7am.minute);
|
||||
|
||||
final millisLeft = dateTime7am.millisecondsSinceEpoch -
|
||||
DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
AppSessionManager.instance.startSessionTimer(millisLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_gotoDashboardScreen();
|
||||
}
|
||||
|
||||
_gotoLoginScreen() {
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
screenKey.currentContext!,
|
||||
CustomRouteNames.kLoginScreenRoute,
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
_gotoDashboardScreen() {
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
screenKey.currentContext!,
|
||||
CustomRouteNames.kDashboardScreenRoute,
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Get.delete<SplashScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user