feat : api call and get captcha

This commit is contained in:
2025-05-17 09:39:09 +03:30
parent 64c89af440
commit 0e630e709b
8 changed files with 38 additions and 27 deletions

6
packages/auth/build.yaml Normal file
View File

@@ -0,0 +1,6 @@
targets:
$default:
builders:
json_serializable:
options:
field_rename: snake

View File

@@ -10,14 +10,14 @@ _LoginRequestModel _$LoginRequestModelFromJson(Map<String, dynamic> json) =>
_LoginRequestModel( _LoginRequestModel(
username: json['username'] as String?, username: json['username'] as String?,
password: json['password'] as String?, password: json['password'] as String?,
captchaCode: json['captchaCode'] as String?, captchaCode: json['captcha_code'] as String?,
captchaKey: json['captchaKey'] as String?, captchaKey: json['captcha_key'] as String?,
); );
Map<String, dynamic> _$LoginRequestModelToJson(_LoginRequestModel instance) => Map<String, dynamic> _$LoginRequestModelToJson(_LoginRequestModel instance) =>
<String, dynamic>{ <String, dynamic>{
'username': instance.username, 'username': instance.username,
'password': instance.password, 'password': instance.password,
'captchaCode': instance.captchaCode, 'captcha_code': instance.captchaCode,
'captchaKey': instance.captchaKey, 'captcha_key': instance.captchaKey,
}; };

View File

@@ -10,7 +10,7 @@ abstract class AuthResponseModel with _$AuthResponseModel {
const factory AuthResponseModel({ const factory AuthResponseModel({
String? refresh, String? refresh,
String? access, String? access,
@JsonKey(name: 'otp_status') bool? otpStatus, bool? otpStatus,
}) = _AuthResponseModel; }) = _AuthResponseModel;
factory AuthResponseModel.fromJson(Map<String, dynamic> json) => factory AuthResponseModel.fromJson(Map<String, dynamic> json) =>

View File

@@ -16,7 +16,7 @@ T _$identity<T>(T value) => value;
/// @nodoc /// @nodoc
mixin _$AuthResponseModel { 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 /// Create a copy of AuthResponseModel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@@ -49,7 +49,7 @@ abstract mixin class $AuthResponseModelCopyWith<$Res> {
factory $AuthResponseModelCopyWith(AuthResponseModel value, $Res Function(AuthResponseModel) _then) = _$AuthResponseModelCopyWithImpl; factory $AuthResponseModelCopyWith(AuthResponseModel value, $Res Function(AuthResponseModel) _then) = _$AuthResponseModelCopyWithImpl;
@useResult @useResult
$Res call({ $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() @JsonSerializable()
class _AuthResponseModel implements AuthResponseModel { 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<String, dynamic> json) => _$AuthResponseModelFromJson(json); factory _AuthResponseModel.fromJson(Map<String, dynamic> json) => _$AuthResponseModelFromJson(json);
@override final String? refresh; @override final String? refresh;
@override final String? access; @override final String? access;
@override@JsonKey(name: 'otp_status') final bool? otpStatus; @override final bool? otpStatus;
/// Create a copy of AuthResponseModel /// Create a copy of AuthResponseModel
/// with the given fields replaced by the non-null parameter values. /// 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; factory _$AuthResponseModelCopyWith(_AuthResponseModel value, $Res Function(_AuthResponseModel) _then) = __$AuthResponseModelCopyWithImpl;
@override @useResult @override @useResult
$Res call({ $Res call({
String? refresh, String? access,@JsonKey(name: 'otp_status') bool? otpStatus String? refresh, String? access, bool? otpStatus
}); });

View File

@@ -9,17 +9,17 @@ part of 'captcha_response_model.dart';
_CaptchaResponseModel _$CaptchaResponseModelFromJson( _CaptchaResponseModel _$CaptchaResponseModelFromJson(
Map<String, dynamic> json, Map<String, dynamic> json,
) => _CaptchaResponseModel( ) => _CaptchaResponseModel(
captchaKey: json['captchaKey'] as String?, captchaKey: json['captcha_key'] as String?,
captchaImage: json['captchaImage'] as String?, captchaImage: json['captcha_image'] as String?,
imageType: json['imageType'] as String?, imageType: json['image_type'] as String?,
imageDecode: json['imageDecode'] as String?, imageDecode: json['image_decode'] as String?,
); );
Map<String, dynamic> _$CaptchaResponseModelToJson( Map<String, dynamic> _$CaptchaResponseModelToJson(
_CaptchaResponseModel instance, _CaptchaResponseModel instance,
) => <String, dynamic>{ ) => <String, dynamic>{
'captchaKey': instance.captchaKey, 'captcha_key': instance.captchaKey,
'captchaImage': instance.captchaImage, 'captcha_image': instance.captchaImage,
'imageType': instance.imageType, 'image_type': instance.imageType,
'imageDecode': instance.imageDecode, 'image_decode': instance.imageDecode,
}; };

View File

@@ -40,11 +40,10 @@ class AuthRepositoryImpl implements AuthRepository {
'captcha/', 'captcha/',
fromJson: CaptchaResponseModel.fromJson, fromJson: CaptchaResponseModel.fromJson,
); );
return res.data; return res.data;
}, },
onSuccess: (response) { onSuccess: (response) {
iLog(response); return response;
}, },
onError: (error, trace) { onError: (error, trace) {
throw Exception('Error during captcha : $error'); throw Exception('Error during captcha : $error');

View File

@@ -2,8 +2,8 @@
// Do not modify // Do not modify
// Check in to version control // 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_auth/data/models/local/user_local/user_local_model.dart';
import 'package:rasadyar_core/core.dart';
extension HiveRegistrar on HiveInterface { extension HiveRegistrar on HiveInterface {
void registerAdapters() { void registerAdapters() {

View File

@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:rasadyar_auth/presentation/widget/clear_button.dart'; import 'package:rasadyar_auth/presentation/widget/clear_button.dart';
@@ -24,16 +26,20 @@ class CaptchaWidget extends GetView<CaptchaWidgetLogic> {
border: Border.all(color: Colors.grey.shade300), border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
child: Expanded(child:controller.obx((state) { child: controller.obx(
return Container(color: Colors.blue,); (state) => Image.memory(base64Decode(state?.captchaImage??''),fit: BoxFit.cover,),
},
onLoading: const Center( onLoading: const Center(
child: CircularProgressIndicator( child: CupertinoActivityIndicator(
color: AppColor.blueNormal, color: AppColor.blueNormal,
strokeWidth: 2,
), ),
), ),
)), onError: (error) {
return const Center(
child: Text(
'خطا در بارگذاری کد امنیتی',
style: AppFonts.yekan13,));
},
),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
IconButton( IconButton(