- Replaced instances of the Logger package with a custom appLogger for consistent logging. - Introduced app_logger.dart to manage logging with file output and storage permissions. - Updated all controllers (e.g., DashboardController, EmployeesScreenController, etc.) to use appLogger for logging messages. - Ensured that logging messages are appropriately categorized (info, warning, error) throughout the application. - Implemented a file logging mechanism to store logs in a designated directory. - Cleaned up old log files to maintain only the most recent logs.
73 lines
2.1 KiB
Dart
73 lines
2.1 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';
|
|
import 'package:marco/helpers/services/app_logger.dart';
|
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
|
|
|
class ForgotPasswordController extends MyController {
|
|
final MyFormValidator basicValidator = MyFormValidator();
|
|
final RxBool isLoading = false.obs;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
basicValidator.addField(
|
|
'email',
|
|
required: true,
|
|
label: "Email",
|
|
validators: [MyEmailValidator()],
|
|
controller: TextEditingController(text: "demo@example.com"),
|
|
);
|
|
}
|
|
|
|
Future<void> onForgotPassword() async {
|
|
if (!basicValidator.validateForm()) return;
|
|
|
|
isLoading.value = true;
|
|
final data = basicValidator.getData();
|
|
final email = data['email']?.toString() ?? '';
|
|
|
|
try {
|
|
appLogger.i("Forgot password requested for: $email");
|
|
final result = await AuthService.forgotPassword(email);
|
|
|
|
if (result == null) {
|
|
// Success case
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Password reset link has been sent.",
|
|
type: SnackbarType.success,
|
|
);
|
|
await LocalStorage.logout();
|
|
} else {
|
|
// Failure case with error map
|
|
final errorMessage = result['error'] ?? "Failed to send reset link. Please try again.";
|
|
showAppSnackbar(
|
|
title: "Failed",
|
|
message: errorMessage,
|
|
type: SnackbarType.error,
|
|
);
|
|
appLogger.w("Failed to send reset password email for $email: $errorMessage");
|
|
}
|
|
} catch (e, stacktrace) {
|
|
appLogger.e("Error during forgot password", error: e, stackTrace: stacktrace);
|
|
showAppSnackbar(
|
|
title: "Error",
|
|
message: "Something went wrong. Please try again later.",
|
|
type: SnackbarType.error,
|
|
);
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
|
|
void gotoLogIn() {
|
|
Get.offAllNamed('/auth/login-option');
|
|
}
|
|
}
|