95 lines
2.3 KiB
Dart
95 lines
2.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:qpay/abstracts/AbstractController.dart';
|
|
import 'package:qpay/http/http.dart';
|
|
import 'package:qpay/screens/onboarding/onboarding_controller.dart';
|
|
|
|
class VerifyModel {
|
|
String? code;
|
|
bool isLoading = false;
|
|
String? errorMessage;
|
|
String? status = 'failed';
|
|
}
|
|
|
|
class VerifyController extends AbstractController {
|
|
late OnboardingController onboardingController;
|
|
final Http http = Http();
|
|
BuildContext context;
|
|
|
|
VerifyModel model = VerifyModel();
|
|
|
|
VerifyController(this.context){
|
|
onboardingController = Provider.of<OnboardingController>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
}
|
|
|
|
void updateCode(String code) {
|
|
model.code = code;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> verifyOtp () async {
|
|
Map user = {
|
|
"username": onboardingController.model.phone,
|
|
"otpCode": model.code,
|
|
"otpType": "REGISTRATION",
|
|
"workflowId": onboardingController.model.workflowId,
|
|
};
|
|
|
|
try {
|
|
model.isLoading = true;
|
|
notifyListeners();
|
|
|
|
Map response = await http.post(
|
|
'/auth/verify',
|
|
user
|
|
);
|
|
model.status = response['state'];
|
|
if(response['state'] == 'failed') {
|
|
model.errorMessage = response['message'];
|
|
showErrorSnackBar(model.errorMessage);
|
|
}
|
|
} catch (e) {
|
|
logger.e(e);
|
|
showErrorSnackBar(
|
|
"Problem during registration, please try again or contact support?",
|
|
);
|
|
}
|
|
|
|
model.isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> resendOtp () async {
|
|
Map user = {
|
|
"username": onboardingController.model.phone,
|
|
"phone": onboardingController.model.phone,
|
|
"workflowId": onboardingController.model.workflowId,
|
|
};
|
|
|
|
try {
|
|
model.isLoading = true;
|
|
notifyListeners();
|
|
|
|
Map response = await http.post(
|
|
'/auth/resend',
|
|
user
|
|
);
|
|
model.status = response['state'];
|
|
if(response['state'] == 'failed') {
|
|
model.errorMessage = response['message'];
|
|
showErrorSnackBar(model.errorMessage);
|
|
}
|
|
} catch (e) {
|
|
logger.e(e);
|
|
showErrorSnackBar(
|
|
"Problem during registration, please try again or contact support?",
|
|
);
|
|
}
|
|
|
|
model.isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
} |