feat : remember me for chicken module
This commit is contained in:
@@ -23,6 +23,7 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
late AnimationController _textAnimationController;
|
||||
late Animation<double> textAnimation;
|
||||
RxBool showCard = false.obs;
|
||||
RxBool rememberMe = false.obs;
|
||||
|
||||
Rx<GlobalKey<FormState>> formKeyOtp = GlobalKey<FormState>().obs;
|
||||
Rx<GlobalKey<FormState>> formKeySentOtp = GlobalKey<FormState>().obs;
|
||||
@@ -45,7 +46,7 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
RxInt secondsRemaining = 120.obs;
|
||||
Timer? _timer;
|
||||
|
||||
AuthRepository authRepository = diChicken.get<AuthRepository>(instanceName: 'oldRepo');
|
||||
AuthRepository authRepository = diChicken.get<AuthRepository>();
|
||||
|
||||
final Module _module = Get.arguments;
|
||||
|
||||
@@ -60,6 +61,8 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
});
|
||||
|
||||
textAnimation = CurvedAnimation(parent: _textAnimationController, curve: Curves.easeInOut);
|
||||
|
||||
initUserPassData();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -118,7 +121,7 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
|
||||
Future<void> submitLoginForm() async {
|
||||
if (!_isFormValid()) return;
|
||||
AuthRepository authTmp = diChicken.get<AuthRepository>(instanceName: 'newRepo');
|
||||
AuthRepository authTmp = diChicken.get<AuthRepository>();
|
||||
isLoading.value = true;
|
||||
await safeCall<UserProfileModel?>(
|
||||
call: () => authTmp.login(
|
||||
@@ -131,6 +134,16 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
await tokenStorageService.saveModule(_module);
|
||||
await tokenStorageService.saveAccessToken(result?.accessToken ?? '');
|
||||
await tokenStorageService.saveRefreshToken(result?.accessToken ?? '');
|
||||
if (rememberMe.value) {
|
||||
await tokenStorageService.saveUserPass(
|
||||
UserLocalModel(
|
||||
username: usernameController.value.text,
|
||||
password: passwordController.value.text,
|
||||
module: _module,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Get.offAndToNamed(ChickenRoutes.init);
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
@@ -163,4 +176,13 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
);
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
void initUserPassData() {
|
||||
UserLocalModel? userPass = tokenStorageService.getUserPass(_module);
|
||||
if (userPass != null) {
|
||||
usernameController.value.text = userPass.username ?? '';
|
||||
passwordController.value.text = userPass.password ?? '';
|
||||
rememberMe.value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,28 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
),
|
||||
SizedBox(height: 26),
|
||||
CaptchaWidget(),
|
||||
SizedBox(height: 23),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
ObxValue((data) {
|
||||
return Checkbox(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: VisualDensity(horizontal: -4, vertical: 4),
|
||||
tristate: true,
|
||||
value: data.value,
|
||||
onChanged: (value) {
|
||||
data.value = value ?? false;
|
||||
},
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
|
||||
activeColor: AppColor.blueNormal,
|
||||
);
|
||||
}, controller.rememberMe),
|
||||
Text(
|
||||
'مرا به خاطر بسپار',
|
||||
style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Obx(() {
|
||||
return RElevated(
|
||||
|
||||
Reference in New Issue
Block a user