feat : captcha widget
This commit is contained in:
@@ -1,43 +0,0 @@
|
|||||||
///This file is automatically generated. DO NOT EDIT, all your changes would be lost.
|
|
||||||
class Assets {
|
|
||||||
Assets._();
|
|
||||||
|
|
||||||
static const String iconsAdd = 'assets/icons/add.svg';
|
|
||||||
static const String iconsArrowLeft = 'assets/icons/arrow_left.svg';
|
|
||||||
static const String iconsArrowRight = 'assets/icons/arrow_right.svg';
|
|
||||||
static const String iconsBgHeaderUserProfile = 'assets/icons/bg_header_user_profile.svg';
|
|
||||||
static const String iconsCalendar = 'assets/icons/calendar.svg';
|
|
||||||
static const String iconsCalendarSearch = 'assets/icons/calendar_search.svg';
|
|
||||||
static const String iconsCall = 'assets/icons/call.svg';
|
|
||||||
static const String iconsDiagram = 'assets/icons/diagram.svg';
|
|
||||||
static const String iconsDownload = 'assets/icons/download.svg';
|
|
||||||
static const String iconsEdit = 'assets/icons/edit.svg';
|
|
||||||
static const String iconsExcelDownload = 'assets/icons/excel_download.svg';
|
|
||||||
static const String iconsFilter = 'assets/icons/filter.svg';
|
|
||||||
static const String iconsGps = 'assets/icons/gps.svg';
|
|
||||||
static const String iconsInformation = 'assets/icons/information.svg';
|
|
||||||
static const String iconsInspection = 'assets/icons/inspection.svg';
|
|
||||||
static const String iconsKey = 'assets/icons/key.svg';
|
|
||||||
static const String iconsLiveStock = 'assets/icons/liveStock.svg';
|
|
||||||
static const String iconsLogout = 'assets/icons/logout.svg';
|
|
||||||
static const String iconsMap = 'assets/icons/map.svg';
|
|
||||||
static const String iconsMapMarker = 'assets/icons/map_marker.svg';
|
|
||||||
static const String iconsMessageAdd = 'assets/icons/message_add.svg';
|
|
||||||
static const String iconsPdfDownload = 'assets/icons/pdf_download.svg';
|
|
||||||
static const String iconsPictureFrame = 'assets/icons/picture_frame.svg';
|
|
||||||
static const String iconsProfileCircle = 'assets/icons/profile_circle.svg';
|
|
||||||
static const String iconsProfileUser = 'assets/icons/profile_user.svg';
|
|
||||||
static const String iconsReceiptDiscount = 'assets/icons/receipt_discount.svg';
|
|
||||||
static const String iconsScan = 'assets/icons/scan.svg';
|
|
||||||
static const String iconsScanBarcode = 'assets/icons/scan_barcode.svg';
|
|
||||||
static const String iconsSearch = 'assets/icons/search.svg';
|
|
||||||
static const String iconsSecurityTime = 'assets/icons/security_time.svg';
|
|
||||||
static const String iconsSetting = 'assets/icons/setting.svg';
|
|
||||||
static const String iconsTagUser = 'assets/icons/tag_user.svg';
|
|
||||||
static const String iconsTrash = 'assets/icons/trash.svg';
|
|
||||||
static const String iconsUser = 'assets/icons/user.svg';
|
|
||||||
static const String iconsUserSquare = 'assets/icons/user_square.svg';
|
|
||||||
static const String imagesInnerSplash = 'assets/images/inner_splash.webp';
|
|
||||||
static const String imagesOutterSplash = 'assets/images/outter_splash.webp';
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -53,4 +53,6 @@ enum Module {
|
|||||||
liveStocks,
|
liveStocks,
|
||||||
@HiveField(1)
|
@HiveField(1)
|
||||||
inspection,
|
inspection,
|
||||||
|
@HiveField(2)
|
||||||
|
chicken,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ class ModuleAdapter extends TypeAdapter<Module> {
|
|||||||
return Module.liveStocks;
|
return Module.liveStocks;
|
||||||
case 1:
|
case 1:
|
||||||
return Module.inspection;
|
return Module.inspection;
|
||||||
|
case 2:
|
||||||
|
return Module.chicken;
|
||||||
default:
|
default:
|
||||||
return Module.liveStocks;
|
return Module.liveStocks;
|
||||||
}
|
}
|
||||||
@@ -78,6 +80,8 @@ class ModuleAdapter extends TypeAdapter<Module> {
|
|||||||
writer.writeByte(0);
|
writer.writeByte(0);
|
||||||
case Module.inspection:
|
case Module.inspection:
|
||||||
writer.writeByte(1);
|
writer.writeByte(1);
|
||||||
|
case Module.chicken:
|
||||||
|
writer.writeByte(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:rasadyar_auth/data/di/auth_di.dart';
|
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
|
||||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||||
import 'package:rasadyar_core/core.dart';
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ class AuthMiddleware extends GetMiddleware {
|
|||||||
final accessToken = tokenService.accessToken.value;
|
final accessToken = tokenService.accessToken.value;
|
||||||
|
|
||||||
if (refreshToken == null || accessToken == null) {
|
if (refreshToken == null || accessToken == null) {
|
||||||
return RouteSettings(name: AuthPaths.moduleList);
|
return RouteSettings(name: AuthPaths.auth, arguments: Module.chicken);
|
||||||
}
|
}
|
||||||
return super.redirect(route);
|
return super.redirect(route);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart
|
|||||||
|
|
||||||
extension HiveRegistrar on HiveInterface {
|
extension HiveRegistrar on HiveInterface {
|
||||||
void registerAdapters() {
|
void registerAdapters() {
|
||||||
registerAdapter(UserLocalModelAdapter());
|
|
||||||
registerAdapter(ModuleAdapter());
|
registerAdapter(ModuleAdapter());
|
||||||
|
registerAdapter(UserLocalModelAdapter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class ModulesLogic extends GetxController {
|
|||||||
List<ModuleModel> moduleList=[
|
List<ModuleModel> moduleList=[
|
||||||
ModuleModel(title: 'بازرسی', icon: Assets.icons.inspection.path, module: Module.inspection),
|
ModuleModel(title: 'بازرسی', icon: Assets.icons.inspection.path, module: Module.inspection),
|
||||||
ModuleModel(title: 'دام', icon: Assets.icons.liveStock.path, module: Module.liveStocks),
|
ModuleModel(title: 'دام', icon: Assets.icons.liveStock.path, module: Module.liveStocks),
|
||||||
|
ModuleModel(title: 'مرغ', icon: Assets.icons.liveStock.path, module: Module.chicken),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:rasadyar_auth/data/di/auth_di.dart';
|
import 'package:rasadyar_auth/data/di/auth_di.dart';
|
||||||
import 'package:rasadyar_auth/data/models/response/captcha/captcha_response_model.dart';
|
import 'package:rasadyar_auth/data/models/response/captcha/captcha_response_model.dart';
|
||||||
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
|
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
|
||||||
import 'package:rasadyar_auth/data/utils/safe_call.dart';
|
|
||||||
import 'package:rasadyar_core/core.dart';
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseModel> {
|
class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseModel> {
|
||||||
@@ -10,6 +11,7 @@ class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseM
|
|||||||
RxnString captchaKey = RxnString();
|
RxnString captchaKey = RxnString();
|
||||||
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||||
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
|
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
|
||||||
|
final Random random = Random();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@@ -27,15 +29,9 @@ class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseM
|
|||||||
Future<void> getCaptcha() async {
|
Future<void> getCaptcha() async {
|
||||||
change(null, status: RxStatus.loading());
|
change(null, status: RxStatus.loading());
|
||||||
textController.value.clear();
|
textController.value.clear();
|
||||||
safeCall(
|
await Future.delayed(Duration(milliseconds: 800));
|
||||||
call: () async => await authRepository.captcha(),
|
captchaKey.value = (random.nextInt(999999)+1000).toString();
|
||||||
onSuccess: (value) {
|
|
||||||
captchaKey.value = value?.captchaKey;
|
|
||||||
change(value, status: RxStatus.success());
|
change(value, status: RxStatus.success());
|
||||||
},
|
|
||||||
onError: (error, stackTrace) {
|
|
||||||
change(null, status: RxStatus.error(error.toString()));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -27,24 +27,22 @@ class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: controller.obx(
|
child: controller.obx(
|
||||||
(state) =>
|
(state) => Center(
|
||||||
Image.memory(
|
child: Stack(
|
||||||
base64Decode(state?.captchaImage ?? ''),
|
alignment: Alignment.center,
|
||||||
fit: BoxFit.cover,
|
children: [
|
||||||
|
CustomPaint(size: const Size(135, 50), painter: _CaptchaLinePainter()),
|
||||||
|
Text(controller.captchaKey.value ?? 'دوباره سعی کنید', style: AppFonts.yekan24Bold),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
onLoading: const Center(
|
|
||||||
child: CupertinoActivityIndicator(color: AppColor.blueNormal),
|
|
||||||
),
|
),
|
||||||
|
onLoading: const Center(child: CupertinoActivityIndicator(color: AppColor.blueNormal)),
|
||||||
onError: (error) {
|
onError: (error) {
|
||||||
return const Center(
|
return const Center(child: Text('خطا در بارگذاری کد امنیتی', style: AppFonts.yekan13));
|
||||||
child: Text(
|
|
||||||
'خطا در بارگذاری کد امنیتی',
|
|
||||||
style: AppFonts.yekan13,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -55,19 +53,11 @@ class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
|
|||||||
return RTextField(
|
return RTextField(
|
||||||
label: 'کد امنیتی',
|
label: 'کد امنیتی',
|
||||||
controller: data.value,
|
controller: data.value,
|
||||||
keyboardType: TextInputType.numberWithOptions(
|
keyboardType: TextInputType.numberWithOptions(decimal: false, signed: false),
|
||||||
decimal: false,
|
|
||||||
signed: false,
|
|
||||||
),
|
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
maxLength: 6,
|
maxLength: 6,
|
||||||
suffixIcon:
|
suffixIcon: (data.value.text.trim().isNotEmpty ?? false)
|
||||||
(data.value.text
|
? clearButton(() => controller.textController.value.clear())
|
||||||
.trim()
|
|
||||||
.isNotEmpty ?? false)
|
|
||||||
? clearButton(
|
|
||||||
() => controller.textController.value.clear(),
|
|
||||||
)
|
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
onSubmitted: (data) {},
|
onSubmitted: (data) {},
|
||||||
@@ -86,3 +76,33 @@ class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _CaptchaLinePainter extends CustomPainter {
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final random = Random();
|
||||||
|
final paint1 = Paint()
|
||||||
|
..color = Color.fromRGBO(random.nextInt(255), random.nextInt(255), random.nextInt(255), 1)
|
||||||
|
..strokeWidth = 2;
|
||||||
|
final paint2 = Paint()
|
||||||
|
..color = Color.fromRGBO(random.nextInt(255), random.nextInt(255), random.nextInt(255), 1)
|
||||||
|
..strokeWidth = 2;
|
||||||
|
|
||||||
|
// First line: top-left to bottom-right
|
||||||
|
canvas.drawLine(
|
||||||
|
Offset(0, 0),
|
||||||
|
Offset(size.width, size.height),
|
||||||
|
paint1,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Second line: bottom-left to top-right
|
||||||
|
canvas.drawLine(
|
||||||
|
Offset(0, size.height),
|
||||||
|
Offset(size.width, 0),
|
||||||
|
paint2,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
cd ../
|
cd ../
|
||||||
dart run build_runner build --delete-conflicting-outputs
|
dart run build_runner build --delete-conflicting-outputs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user