From 0e630e709b7020b4f8b7a1a2709fb825e1a2a843 Mon Sep 17 00:00:00 2001 From: "mr.mojtaba" Date: Sat, 17 May 2025 09:39:09 +0330 Subject: [PATCH] feat : api call and get captcha --- packages/auth/build.yaml | 6 ++++++ .../login_request/login_request_model.g.dart | 8 ++++---- .../response/auth/auth_response_model.dart | 2 +- .../auth/auth_response_model.freezed.dart | 10 +++++----- .../captcha/captcha_response_model.g.dart | 16 ++++++++-------- .../data/repositories/auth_repository_imp.dart | 3 +-- packages/auth/lib/hive_registrar.g.dart | 2 +- .../lib/presentation/widget/captcha/view.dart | 18 ++++++++++++------ 8 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 packages/auth/build.yaml diff --git a/packages/auth/build.yaml b/packages/auth/build.yaml new file mode 100644 index 0000000..840029b --- /dev/null +++ b/packages/auth/build.yaml @@ -0,0 +1,6 @@ +targets: + $default: + builders: + json_serializable: + options: + field_rename: snake \ No newline at end of file diff --git a/packages/auth/lib/data/models/request/login_request/login_request_model.g.dart b/packages/auth/lib/data/models/request/login_request/login_request_model.g.dart index f10c8a6..4504142 100644 --- a/packages/auth/lib/data/models/request/login_request/login_request_model.g.dart +++ b/packages/auth/lib/data/models/request/login_request/login_request_model.g.dart @@ -10,14 +10,14 @@ _LoginRequestModel _$LoginRequestModelFromJson(Map json) => _LoginRequestModel( username: json['username'] as String?, password: json['password'] as String?, - captchaCode: json['captchaCode'] as String?, - captchaKey: json['captchaKey'] as String?, + captchaCode: json['captcha_code'] as String?, + captchaKey: json['captcha_key'] as String?, ); Map _$LoginRequestModelToJson(_LoginRequestModel instance) => { 'username': instance.username, 'password': instance.password, - 'captchaCode': instance.captchaCode, - 'captchaKey': instance.captchaKey, + 'captcha_code': instance.captchaCode, + 'captcha_key': instance.captchaKey, }; diff --git a/packages/auth/lib/data/models/response/auth/auth_response_model.dart b/packages/auth/lib/data/models/response/auth/auth_response_model.dart index c13cb0e..1f5faba 100644 --- a/packages/auth/lib/data/models/response/auth/auth_response_model.dart +++ b/packages/auth/lib/data/models/response/auth/auth_response_model.dart @@ -10,7 +10,7 @@ abstract class AuthResponseModel with _$AuthResponseModel { const factory AuthResponseModel({ String? refresh, String? access, - @JsonKey(name: 'otp_status') bool? otpStatus, + bool? otpStatus, }) = _AuthResponseModel; factory AuthResponseModel.fromJson(Map json) => diff --git a/packages/auth/lib/data/models/response/auth/auth_response_model.freezed.dart b/packages/auth/lib/data/models/response/auth/auth_response_model.freezed.dart index a61f9f7..c0c505f 100644 --- a/packages/auth/lib/data/models/response/auth/auth_response_model.freezed.dart +++ b/packages/auth/lib/data/models/response/auth/auth_response_model.freezed.dart @@ -16,7 +16,7 @@ T _$identity(T value) => value; /// @nodoc mixin _$AuthResponseModel { - String? get refresh; String? get access;@JsonKey(name: 'otp_status') bool? get otpStatus; + String? get refresh; String? get access; bool? get otpStatus; /// Create a copy of AuthResponseModel /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -49,7 +49,7 @@ abstract mixin class $AuthResponseModelCopyWith<$Res> { factory $AuthResponseModelCopyWith(AuthResponseModel value, $Res Function(AuthResponseModel) _then) = _$AuthResponseModelCopyWithImpl; @useResult $Res call({ - String? refresh, String? access,@JsonKey(name: 'otp_status') bool? otpStatus + String? refresh, String? access, bool? otpStatus }); @@ -82,12 +82,12 @@ as bool?, @JsonSerializable() class _AuthResponseModel implements AuthResponseModel { - const _AuthResponseModel({this.refresh, this.access, @JsonKey(name: 'otp_status') this.otpStatus}); + const _AuthResponseModel({this.refresh, this.access, this.otpStatus}); factory _AuthResponseModel.fromJson(Map json) => _$AuthResponseModelFromJson(json); @override final String? refresh; @override final String? access; -@override@JsonKey(name: 'otp_status') final bool? otpStatus; +@override final bool? otpStatus; /// Create a copy of AuthResponseModel /// with the given fields replaced by the non-null parameter values. @@ -122,7 +122,7 @@ abstract mixin class _$AuthResponseModelCopyWith<$Res> implements $AuthResponseM factory _$AuthResponseModelCopyWith(_AuthResponseModel value, $Res Function(_AuthResponseModel) _then) = __$AuthResponseModelCopyWithImpl; @override @useResult $Res call({ - String? refresh, String? access,@JsonKey(name: 'otp_status') bool? otpStatus + String? refresh, String? access, bool? otpStatus }); diff --git a/packages/auth/lib/data/models/response/captcha/captcha_response_model.g.dart b/packages/auth/lib/data/models/response/captcha/captcha_response_model.g.dart index a0ffdcb..8d69248 100644 --- a/packages/auth/lib/data/models/response/captcha/captcha_response_model.g.dart +++ b/packages/auth/lib/data/models/response/captcha/captcha_response_model.g.dart @@ -9,17 +9,17 @@ part of 'captcha_response_model.dart'; _CaptchaResponseModel _$CaptchaResponseModelFromJson( Map json, ) => _CaptchaResponseModel( - captchaKey: json['captchaKey'] as String?, - captchaImage: json['captchaImage'] as String?, - imageType: json['imageType'] as String?, - imageDecode: json['imageDecode'] as String?, + captchaKey: json['captcha_key'] as String?, + captchaImage: json['captcha_image'] as String?, + imageType: json['image_type'] as String?, + imageDecode: json['image_decode'] as String?, ); Map _$CaptchaResponseModelToJson( _CaptchaResponseModel instance, ) => { - 'captchaKey': instance.captchaKey, - 'captchaImage': instance.captchaImage, - 'imageType': instance.imageType, - 'imageDecode': instance.imageDecode, + 'captcha_key': instance.captchaKey, + 'captcha_image': instance.captchaImage, + 'image_type': instance.imageType, + 'image_decode': instance.imageDecode, }; diff --git a/packages/auth/lib/data/repositories/auth_repository_imp.dart b/packages/auth/lib/data/repositories/auth_repository_imp.dart index 6aa2e1a..9ddcd17 100644 --- a/packages/auth/lib/data/repositories/auth_repository_imp.dart +++ b/packages/auth/lib/data/repositories/auth_repository_imp.dart @@ -40,11 +40,10 @@ class AuthRepositoryImpl implements AuthRepository { 'captcha/', fromJson: CaptchaResponseModel.fromJson, ); - return res.data; }, onSuccess: (response) { - iLog(response); + return response; }, onError: (error, trace) { throw Exception('Error during captcha : $error'); diff --git a/packages/auth/lib/hive_registrar.g.dart b/packages/auth/lib/hive_registrar.g.dart index d174454..b4abe2c 100644 --- a/packages/auth/lib/hive_registrar.g.dart +++ b/packages/auth/lib/hive_registrar.g.dart @@ -2,8 +2,8 @@ // Do not modify // Check in to version control +import 'package:hive_ce/hive.dart'; import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart'; -import 'package:rasadyar_core/core.dart'; extension HiveRegistrar on HiveInterface { void registerAdapters() { diff --git a/packages/auth/lib/presentation/widget/captcha/view.dart b/packages/auth/lib/presentation/widget/captcha/view.dart index 4d42576..db795c2 100644 --- a/packages/auth/lib/presentation/widget/captcha/view.dart +++ b/packages/auth/lib/presentation/widget/captcha/view.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:rasadyar_auth/presentation/widget/clear_button.dart'; @@ -24,16 +26,20 @@ class CaptchaWidget extends GetView { border: Border.all(color: Colors.grey.shade300), borderRadius: BorderRadius.circular(8), ), - child: Expanded(child:controller.obx((state) { - return Container(color: Colors.blue,); - }, + child: controller.obx( + (state) => Image.memory(base64Decode(state?.captchaImage??''),fit: BoxFit.cover,), onLoading: const Center( - child: CircularProgressIndicator( + child: CupertinoActivityIndicator( color: AppColor.blueNormal, - strokeWidth: 2, ), ), - )), + onError: (error) { + return const Center( + child: Text( + 'خطا در بارگذاری کد امنیتی', + style: AppFonts.yekan13,)); + }, + ), ), const SizedBox(height: 20), IconButton(