added api for forgot password otp

This commit is contained in:
llsajjad
2025-09-16 17:18:51 +03:30
parent 69980925ad
commit e9a1d0c665
17 changed files with 800 additions and 79 deletions
@@ -1,5 +1,6 @@
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
import 'package:tm_app/data/services/model/login_response/login_response_model.dart';
import 'package:tm_app/data/services/model/verify_otp_response/verify_otp_response_model.dart';
import '../../core/utils/result.dart';
import '../services/auth_service.dart';
@@ -31,4 +32,11 @@ class AuthRepository {
}) async {
return _authService.forgotPassword(email: email);
}
Future<Result<VerifyOtpResponseModel>> verifyOtp({
required String code,
required String email,
}) async {
return _authService.verifyOtp(code: code, email: email);
}
}
+18
View File
@@ -8,6 +8,7 @@ import 'package:tm_app/data/services/api/auth_api.dart';
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
import 'package:tm_app/data/services/model/login_response/login_response_model.dart';
import 'package:tm_app/data/services/model/logout_response/logout_response.dart';
import 'package:tm_app/data/services/model/verify_otp_response/verify_otp_response_model.dart';
import '../../core/network/network_manager.dart';
import '../../core/utils/result.dart';
@@ -72,4 +73,21 @@ class AuthService {
return result;
}
Future<Result<VerifyOtpResponseModel>> verifyOtp({
required String code,
required String email,
}) async {
final data = jsonEncode({"code": code, "email": email});
final result = await _networkManager.makeRequest(
"/api/v1/profile/verify-otp",
method: 'POST',
(json) => VerifyOtpResponseModel.fromJson(json),
data: data,
);
return result;
}
}
@@ -0,0 +1,16 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'verify_otp_data.freezed.dart';
part 'verify_otp_data.g.dart';
@freezed
abstract class VerifyOtpData with _$VerifyOtpData {
const factory VerifyOtpData({
required String message,
required bool success,
required String token,
}) = _VerifyOtpData;
factory VerifyOtpData.fromJson(Map<String, dynamic> json) =>
_$VerifyOtpDataFromJson(json);
}
@@ -0,0 +1,283 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'verify_otp_data.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$VerifyOtpData {
String get message; bool get success; String get token;
/// Create a copy of VerifyOtpData
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$VerifyOtpDataCopyWith<VerifyOtpData> get copyWith => _$VerifyOtpDataCopyWithImpl<VerifyOtpData>(this as VerifyOtpData, _$identity);
/// Serializes this VerifyOtpData to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is VerifyOtpData&&(identical(other.message, message) || other.message == message)&&(identical(other.success, success) || other.success == success)&&(identical(other.token, token) || other.token == token));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,message,success,token);
@override
String toString() {
return 'VerifyOtpData(message: $message, success: $success, token: $token)';
}
}
/// @nodoc
abstract mixin class $VerifyOtpDataCopyWith<$Res> {
factory $VerifyOtpDataCopyWith(VerifyOtpData value, $Res Function(VerifyOtpData) _then) = _$VerifyOtpDataCopyWithImpl;
@useResult
$Res call({
String message, bool success, String token
});
}
/// @nodoc
class _$VerifyOtpDataCopyWithImpl<$Res>
implements $VerifyOtpDataCopyWith<$Res> {
_$VerifyOtpDataCopyWithImpl(this._self, this._then);
final VerifyOtpData _self;
final $Res Function(VerifyOtpData) _then;
/// Create a copy of VerifyOtpData
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? message = null,Object? success = null,Object? token = null,}) {
return _then(_self.copyWith(
message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,success: null == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool,token: null == token ? _self.token : token // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [VerifyOtpData].
extension VerifyOtpDataPatterns on VerifyOtpData {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _VerifyOtpData value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _VerifyOtpData() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _VerifyOtpData value) $default,){
final _that = this;
switch (_that) {
case _VerifyOtpData():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _VerifyOtpData value)? $default,){
final _that = this;
switch (_that) {
case _VerifyOtpData() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String message, bool success, String token)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _VerifyOtpData() when $default != null:
return $default(_that.message,_that.success,_that.token);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String message, bool success, String token) $default,) {final _that = this;
switch (_that) {
case _VerifyOtpData():
return $default(_that.message,_that.success,_that.token);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String message, bool success, String token)? $default,) {final _that = this;
switch (_that) {
case _VerifyOtpData() when $default != null:
return $default(_that.message,_that.success,_that.token);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _VerifyOtpData implements VerifyOtpData {
const _VerifyOtpData({required this.message, required this.success, required this.token});
factory _VerifyOtpData.fromJson(Map<String, dynamic> json) => _$VerifyOtpDataFromJson(json);
@override final String message;
@override final bool success;
@override final String token;
/// Create a copy of VerifyOtpData
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$VerifyOtpDataCopyWith<_VerifyOtpData> get copyWith => __$VerifyOtpDataCopyWithImpl<_VerifyOtpData>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$VerifyOtpDataToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _VerifyOtpData&&(identical(other.message, message) || other.message == message)&&(identical(other.success, success) || other.success == success)&&(identical(other.token, token) || other.token == token));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,message,success,token);
@override
String toString() {
return 'VerifyOtpData(message: $message, success: $success, token: $token)';
}
}
/// @nodoc
abstract mixin class _$VerifyOtpDataCopyWith<$Res> implements $VerifyOtpDataCopyWith<$Res> {
factory _$VerifyOtpDataCopyWith(_VerifyOtpData value, $Res Function(_VerifyOtpData) _then) = __$VerifyOtpDataCopyWithImpl;
@override @useResult
$Res call({
String message, bool success, String token
});
}
/// @nodoc
class __$VerifyOtpDataCopyWithImpl<$Res>
implements _$VerifyOtpDataCopyWith<$Res> {
__$VerifyOtpDataCopyWithImpl(this._self, this._then);
final _VerifyOtpData _self;
final $Res Function(_VerifyOtpData) _then;
/// Create a copy of VerifyOtpData
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? message = null,Object? success = null,Object? token = null,}) {
return _then(_VerifyOtpData(
message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,success: null == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool,token: null == token ? _self.token : token // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on
@@ -0,0 +1,21 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'verify_otp_data.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_VerifyOtpData _$VerifyOtpDataFromJson(Map<String, dynamic> json) =>
_VerifyOtpData(
message: json['message'] as String,
success: json['success'] as bool,
token: json['token'] as String,
);
Map<String, dynamic> _$VerifyOtpDataToJson(_VerifyOtpData instance) =>
<String, dynamic>{
'message': instance.message,
'success': instance.success,
'token': instance.token,
};
@@ -0,0 +1,18 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:tm_app/data/services/model/verify_otp_data/verify_otp_data.dart';
part 'verify_otp_response_model.freezed.dart';
part 'verify_otp_response_model.g.dart';
@freezed
abstract class VerifyOtpResponseModel with _$VerifyOtpResponseModel {
const factory VerifyOtpResponseModel({
required bool success,
required String message,
required VerifyOtpData data,
}) = _VerifyOtpResponseModel;
factory VerifyOtpResponseModel.fromJson(Map<String, dynamic> json) =>
_$VerifyOtpResponseModelFromJson(json);
}
@@ -0,0 +1,301 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'verify_otp_response_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$VerifyOtpResponseModel {
bool get success; String get message; VerifyOtpData get data;
/// Create a copy of VerifyOtpResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$VerifyOtpResponseModelCopyWith<VerifyOtpResponseModel> get copyWith => _$VerifyOtpResponseModelCopyWithImpl<VerifyOtpResponseModel>(this as VerifyOtpResponseModel, _$identity);
/// Serializes this VerifyOtpResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is VerifyOtpResponseModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data);
@override
String toString() {
return 'VerifyOtpResponseModel(success: $success, message: $message, data: $data)';
}
}
/// @nodoc
abstract mixin class $VerifyOtpResponseModelCopyWith<$Res> {
factory $VerifyOtpResponseModelCopyWith(VerifyOtpResponseModel value, $Res Function(VerifyOtpResponseModel) _then) = _$VerifyOtpResponseModelCopyWithImpl;
@useResult
$Res call({
bool success, String message, VerifyOtpData data
});
$VerifyOtpDataCopyWith<$Res> get data;
}
/// @nodoc
class _$VerifyOtpResponseModelCopyWithImpl<$Res>
implements $VerifyOtpResponseModelCopyWith<$Res> {
_$VerifyOtpResponseModelCopyWithImpl(this._self, this._then);
final VerifyOtpResponseModel _self;
final $Res Function(VerifyOtpResponseModel) _then;
/// Create a copy of VerifyOtpResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? success = null,Object? message = null,Object? data = null,}) {
return _then(_self.copyWith(
success: null == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool,message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,data: null == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as VerifyOtpData,
));
}
/// Create a copy of VerifyOtpResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$VerifyOtpDataCopyWith<$Res> get data {
return $VerifyOtpDataCopyWith<$Res>(_self.data, (value) {
return _then(_self.copyWith(data: value));
});
}
}
/// Adds pattern-matching-related methods to [VerifyOtpResponseModel].
extension VerifyOtpResponseModelPatterns on VerifyOtpResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _VerifyOtpResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _VerifyOtpResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _VerifyOtpResponseModel value) $default,){
final _that = this;
switch (_that) {
case _VerifyOtpResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _VerifyOtpResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _VerifyOtpResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool success, String message, VerifyOtpData data)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _VerifyOtpResponseModel() when $default != null:
return $default(_that.success,_that.message,_that.data);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool success, String message, VerifyOtpData data) $default,) {final _that = this;
switch (_that) {
case _VerifyOtpResponseModel():
return $default(_that.success,_that.message,_that.data);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool success, String message, VerifyOtpData data)? $default,) {final _that = this;
switch (_that) {
case _VerifyOtpResponseModel() when $default != null:
return $default(_that.success,_that.message,_that.data);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _VerifyOtpResponseModel implements VerifyOtpResponseModel {
const _VerifyOtpResponseModel({required this.success, required this.message, required this.data});
factory _VerifyOtpResponseModel.fromJson(Map<String, dynamic> json) => _$VerifyOtpResponseModelFromJson(json);
@override final bool success;
@override final String message;
@override final VerifyOtpData data;
/// Create a copy of VerifyOtpResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$VerifyOtpResponseModelCopyWith<_VerifyOtpResponseModel> get copyWith => __$VerifyOtpResponseModelCopyWithImpl<_VerifyOtpResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$VerifyOtpResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _VerifyOtpResponseModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data);
@override
String toString() {
return 'VerifyOtpResponseModel(success: $success, message: $message, data: $data)';
}
}
/// @nodoc
abstract mixin class _$VerifyOtpResponseModelCopyWith<$Res> implements $VerifyOtpResponseModelCopyWith<$Res> {
factory _$VerifyOtpResponseModelCopyWith(_VerifyOtpResponseModel value, $Res Function(_VerifyOtpResponseModel) _then) = __$VerifyOtpResponseModelCopyWithImpl;
@override @useResult
$Res call({
bool success, String message, VerifyOtpData data
});
@override $VerifyOtpDataCopyWith<$Res> get data;
}
/// @nodoc
class __$VerifyOtpResponseModelCopyWithImpl<$Res>
implements _$VerifyOtpResponseModelCopyWith<$Res> {
__$VerifyOtpResponseModelCopyWithImpl(this._self, this._then);
final _VerifyOtpResponseModel _self;
final $Res Function(_VerifyOtpResponseModel) _then;
/// Create a copy of VerifyOtpResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? success = null,Object? message = null,Object? data = null,}) {
return _then(_VerifyOtpResponseModel(
success: null == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool,message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String,data: null == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as VerifyOtpData,
));
}
/// Create a copy of VerifyOtpResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$VerifyOtpDataCopyWith<$Res> get data {
return $VerifyOtpDataCopyWith<$Res>(_self.data, (value) {
return _then(_self.copyWith(data: value));
});
}
}
// dart format on
@@ -0,0 +1,23 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'verify_otp_response_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_VerifyOtpResponseModel _$VerifyOtpResponseModelFromJson(
Map<String, dynamic> json,
) => _VerifyOtpResponseModel(
success: json['success'] as bool,
message: json['message'] as String,
data: VerifyOtpData.fromJson(json['data'] as Map<String, dynamic>),
);
Map<String, dynamic> _$VerifyOtpResponseModelToJson(
_VerifyOtpResponseModel instance,
) => <String, dynamic>{
'success': instance.success,
'message': instance.message,
'data': instance.data,
};