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(
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<String, dynamic> _$LoginRequestModelToJson(_LoginRequestModel instance) =>
<String, dynamic>{
'username': instance.username,
'password': instance.password,
'captchaCode': instance.captchaCode,
'captchaKey': instance.captchaKey,
'captcha_code': instance.captchaCode,
'captcha_key': instance.captchaKey,
};

View File

@@ -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<String, dynamic> json) =>

View File

@@ -16,7 +16,7 @@ T _$identity<T>(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<String, dynamic> 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
});

View File

@@ -9,17 +9,17 @@ part of 'captcha_response_model.dart';
_CaptchaResponseModel _$CaptchaResponseModelFromJson(
Map<String, dynamic> 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<String, dynamic> _$CaptchaResponseModelToJson(
_CaptchaResponseModel instance,
) => <String, dynamic>{
'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,
};

View File

@@ -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');

View File

@@ -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() {

View File

@@ -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<CaptchaWidgetLogic> {
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(