67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/controller/my_controller.dart';
|
|
import 'package:marco/helpers/services/auth_service.dart';
|
|
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
|
import 'package:marco/helpers/widgets/my_validators.dart';
|
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
|
class ForgotPasswordController extends MyController {
|
|
MyFormValidator basicValidator = MyFormValidator();
|
|
bool showPassword = false;
|
|
|
|
@override
|
|
void onInit() {
|
|
basicValidator.addField(
|
|
'email',
|
|
required: true,
|
|
label: "Email",
|
|
validators: [MyEmailValidator()],
|
|
controller: TextEditingController(text: "demo@example.com"),
|
|
);
|
|
|
|
super.onInit();
|
|
}
|
|
|
|
Future<void> onLogin() async {
|
|
if (basicValidator.validateForm()) {
|
|
update();
|
|
var errors = await AuthService.loginUser(basicValidator.getData());
|
|
if (errors != null) {
|
|
basicValidator.validateForm();
|
|
basicValidator.clearErrors();
|
|
}
|
|
Get.toNamed('/auth/reset_password');
|
|
update();
|
|
}
|
|
}
|
|
|
|
/// New: Forgot password function
|
|
Future<void> onForgotPassword() async {
|
|
if (basicValidator.validateForm()) {
|
|
update();
|
|
final data = basicValidator.getData();
|
|
final email = data['email']?.toString() ?? '';
|
|
final result = await AuthService.forgotPassword(email);
|
|
|
|
if (result != null) {
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Your password reset link was sent.",
|
|
type: SnackbarType.success,
|
|
);
|
|
} else {
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Your password reset link was sent.",
|
|
type: SnackbarType.success,
|
|
);
|
|
}
|
|
update();
|
|
}
|
|
}
|
|
|
|
void gotoLogIn() {
|
|
Get.toNamed('/auth/login');
|
|
}
|
|
}
|