refactor: optimize module navigation delay and clean up unused code in splash and auth logic
fix : role access to chicken app
This commit is contained in:
@@ -8,7 +8,6 @@ import 'package:rasadyar_chicken/features/common/data/model/response/user_info/u
|
||||
import 'package:rasadyar_chicken/features/common/data/model/response/user_profile_model/user_profile_model.dart';
|
||||
import 'package:rasadyar_chicken/features/common/data/repositories/auth/auth_repository.dart';
|
||||
import 'package:rasadyar_chicken/features/common/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_chicken/features/steward/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_chicken/presentation/widget/captcha/logic.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
@@ -124,16 +123,7 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
},
|
||||
),
|
||||
onSuccess: (result) async {
|
||||
await gService.saveSelectedModule(_module);
|
||||
await tokenStorageService.saveModule(_module);
|
||||
await tokenStorageService.saveAccessToken(
|
||||
_module,
|
||||
result?.accessToken ?? '',
|
||||
);
|
||||
await tokenStorageService.saveRefreshToken(
|
||||
_module,
|
||||
result?.accessToken ?? '',
|
||||
);
|
||||
|
||||
var tmpRoles = result?.role?.where((element) {
|
||||
final allowedRoles = {
|
||||
'poultryscience',
|
||||
@@ -150,36 +140,45 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
final lowerElement = element.toString().toLowerCase().trim();
|
||||
return allowedRoles.contains(lowerElement);
|
||||
}).toList();
|
||||
if (tmpRoles?.length==1) {
|
||||
await tokenStorageService.saveRoles(_module, tmpRoles ?? []);
|
||||
}
|
||||
|
||||
await tokenStorageService.saveRoles(_module, tmpRoles ?? []);
|
||||
if (rememberMe.value) {
|
||||
await tokenStorageService.saveUserPass(
|
||||
_module,
|
||||
usernameController.value.text,
|
||||
passwordController.value.text,
|
||||
);
|
||||
}
|
||||
|
||||
authTmp.stewardAppLogin(
|
||||
token: result?.accessToken ?? '',
|
||||
queryParameters: {
|
||||
"mobile": usernameController.value.text,
|
||||
"device_name": deviceName.value,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Get.offAndToNamed(CommonRoutes.role);
|
||||
|
||||
if (tmpRoles != null && tmpRoles.isNotEmpty ) {
|
||||
await gService.saveSelectedModule(_module);
|
||||
await tokenStorageService.saveModule(_module);
|
||||
await tokenStorageService.saveAccessToken(
|
||||
_module,
|
||||
result?.accessToken ?? '',
|
||||
);
|
||||
await tokenStorageService.saveRefreshToken(
|
||||
_module,
|
||||
result?.accessToken ?? '',
|
||||
);
|
||||
await tokenStorageService.saveRoles(_module, tmpRoles);
|
||||
if (rememberMe.value) {
|
||||
await tokenStorageService.saveUserPass(
|
||||
_module,
|
||||
usernameController.value.text,
|
||||
passwordController.value.text,
|
||||
);
|
||||
}
|
||||
|
||||
authTmp.stewardAppLogin(
|
||||
token: result?.accessToken ?? '',
|
||||
queryParameters: {
|
||||
"mobile": usernameController.value.text,
|
||||
"device_name": deviceName.value,
|
||||
},
|
||||
);
|
||||
|
||||
/* if (tmpRoles!.length > 1) {
|
||||
Get.offAndToNamed(CommonRoutes.role);
|
||||
} else {
|
||||
Get.offAllNamed(StewardRoutes.initSteward);
|
||||
} */
|
||||
Get.snackbar(
|
||||
'با احترام ',
|
||||
'دسترسی شما در دست اقدام میباشد ',
|
||||
backgroundColor: AppColor.warning,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: Duration(seconds: 5),
|
||||
).show();
|
||||
}
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
if (error is DioException) {
|
||||
|
||||
@@ -14,8 +14,40 @@ class RolePage extends GetView<RoleLogic> {
|
||||
isBase: true,
|
||||
child: Column(
|
||||
children: [
|
||||
Assets.images.selectRole.image(height: 212.h, width: Get.width.w, fit: BoxFit.cover),
|
||||
Assets.images.selectRole.image(
|
||||
height: 212.h,
|
||||
width: Get.width.w,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
ObxValue((data) {
|
||||
if (data.isEmpty) {
|
||||
return Expanded(
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24.w),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 64.w,
|
||||
color: AppColor.darkGreyDark,
|
||||
),
|
||||
SizedBox(height: 16.h),
|
||||
Text(
|
||||
'شما دسترسی به هیچ رولی ندارید',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppFonts.yekan16Bold.copyWith(
|
||||
color: AppColor.darkGreyDark,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8.h),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Expanded(
|
||||
child: GridView.builder(
|
||||
physics: BouncingScrollPhysics(),
|
||||
@@ -34,9 +66,15 @@ class RolePage extends GetView<RoleLogic> {
|
||||
onTap: () async {
|
||||
try {
|
||||
String route = role.values.first;
|
||||
await controller.gService.saveRoute(Module.chicken, route);
|
||||
await controller.gService.saveRoute(
|
||||
Module.chicken,
|
||||
route,
|
||||
);
|
||||
|
||||
await controller.gService.saveRole(Module.chicken, data[index]);
|
||||
await controller.gService.saveRole(
|
||||
Module.chicken,
|
||||
data[index],
|
||||
);
|
||||
Get.offAllNamed(route);
|
||||
} catch (e) {
|
||||
eLog(
|
||||
@@ -55,7 +93,12 @@ class RolePage extends GetView<RoleLogic> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget roleCard({required String title, Function()? onTap, int? width, int? height}) {
|
||||
Widget roleCard({
|
||||
required String title,
|
||||
Function()? onTap,
|
||||
int? width,
|
||||
int? height,
|
||||
}) {
|
||||
return Container(
|
||||
width: width?.w ?? 128.w,
|
||||
height: height?.h ?? 48.h,
|
||||
|
||||
Reference in New Issue
Block a user