reset_psd_controller.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'package:domain/repository/auth_repository.dart';
  2. import 'package:get/get.dart';
  3. import 'package:plugin_platform/engine/notify/notify_engine.dart';
  4. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  5. import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:shared/utils/util.dart';
  8. import 'reset_psd_state.dart';
  9. class ResetPasswordController extends GetxController with DioCancelableMixin{
  10. final AuthRepository _authRepository = Get.find();
  11. final ResetPasswordState state = ResetPasswordState();
  12. //执行注册操作
  13. void doResetPassword() {
  14. state.passwordErrorText = null;
  15. state.confirmPasswordErrorText = null;
  16. update();
  17. var oldPasswordController = state.formData['old_password']!['controller'];
  18. var passwordController = state.formData['new_password']!['controller'];
  19. var confirmController = state.formData['confirm_password']!['controller'];
  20. state.oldPassword = oldPasswordController.text;
  21. state.password = passwordController.text;
  22. state.confirmPassword = confirmController.text;
  23. Log.d('当前待提交的 password:${state.password} confirmPassword:${state.confirmPassword}');
  24. if (Utils.isEmpty(state.oldPassword)) {
  25. state.passwordErrorText = "The password cannot be empty!".tr;
  26. update();
  27. } else if (Utils.isEmpty(state.password)) {
  28. state.confirmPasswordErrorText = "The new password cannot be empty!".tr;
  29. update();
  30. } else if (Utils.isEmpty(state.confirmPassword)) {
  31. state.confirmPasswordErrorText = "The confirm password cannot be empty!".tr;
  32. update();
  33. } else if (state.confirmPassword != state.password) {
  34. state.confirmPasswordErrorText = "Please confirm your confirmed password!".tr;
  35. update();
  36. } else {
  37. //执行密码登录
  38. _request2ResetPassword();
  39. }
  40. }
  41. // 调用接口重置密码
  42. void _request2ResetPassword() async {
  43. var result = await _authRepository.resetPassword(state.oldPassword, state.password, state.confirmPassword, cancelToken: cancelToken);
  44. //处理数据
  45. if (result.isSuccess) {
  46. //提交成功
  47. NotifyEngine.showSuccess("Successful".tr);
  48. Get.back();
  49. } else {
  50. ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
  51. }
  52. }
  53. }