added api for forgot password otp
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tm_app/data/services/model/customer/customer.dart';
|
||||
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
|
||||
import 'package:tm_app/data/services/model/verify_otp_response/verify_otp_response_model.dart';
|
||||
import 'package:tm_app/views/forget_password_create/pages/forgot_password_create_screen.dart';
|
||||
|
||||
import '../core/utils/result.dart';
|
||||
import '../data/repositories/auth_repository.dart';
|
||||
@@ -11,7 +13,7 @@ class AuthViewModel with ChangeNotifier {
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
AuthViewModel({required AuthRepository authRepository})
|
||||
: _authRepository = authRepository {
|
||||
: _authRepository = authRepository {
|
||||
usernameController.addListener(_onTextChanged);
|
||||
passwordController.addListener(_onTextChanged);
|
||||
emailController.addListener(_onTextChanged);
|
||||
@@ -38,8 +40,7 @@ class AuthViewModel with ChangeNotifier {
|
||||
bool get obscureForgotPassword => _obscureForgotPassword;
|
||||
|
||||
bool get isLoginEnabled =>
|
||||
usernameController.text.isNotEmpty &&
|
||||
passwordController.text.isNotEmpty;
|
||||
usernameController.text.isNotEmpty && passwordController.text.isNotEmpty;
|
||||
|
||||
// Auth state
|
||||
bool _isLoading = false;
|
||||
@@ -52,6 +53,7 @@ class AuthViewModel with ChangeNotifier {
|
||||
String? get errorMessage => _errorMessage;
|
||||
Customer? get loggedInUser => _loggedInUser;
|
||||
String? get forgotPasswordMessage => _forgotPasswordMessage;
|
||||
String? resetToken;
|
||||
|
||||
void togglePasswordVisibility() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
@@ -75,7 +77,7 @@ class AuthViewModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
bool get canSubmitOtpPage {
|
||||
return isEmailValid && isOtpValid;
|
||||
return isOtpValid;
|
||||
}
|
||||
|
||||
bool get isNewPasswordValid {
|
||||
@@ -147,7 +149,6 @@ class AuthViewModel with ChangeNotifier {
|
||||
|
||||
notifyListeners();
|
||||
|
||||
// reset error after notify
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -168,7 +169,6 @@ class AuthViewModel with ChangeNotifier {
|
||||
successMessage = result.value.message;
|
||||
notifyListeners();
|
||||
|
||||
// پاک شدن بعد از یک بار مصرف
|
||||
Future.microtask(() {
|
||||
successMessage = null;
|
||||
});
|
||||
@@ -186,6 +186,37 @@ class AuthViewModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> verifyOtp(BuildContext context) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _authRepository.verifyOtp(
|
||||
code: otpController.text.trim(),
|
||||
email: emailController.text.trim(),
|
||||
);
|
||||
|
||||
switch (result) {
|
||||
case Ok<VerifyOtpResponseModel>():
|
||||
_isLoading = false;
|
||||
resetToken = result.value.data.token;
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const ForgotPasswordCreateScreen()),
|
||||
);
|
||||
break;
|
||||
|
||||
case Error<VerifyOtpResponseModel>():
|
||||
_isLoading = false;
|
||||
_errorMessage = result.error.toString();
|
||||
break;
|
||||
}
|
||||
notifyListeners();
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
usernameController.dispose();
|
||||
|
||||
Reference in New Issue
Block a user