sign_up_controller.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 'sign_up_state.dart';
  9. class SignUpController extends GetxController with DioCancelableMixin {
  10. final AuthRepository _authRepository = Get.find();
  11. final SignUpState state = SignUpState();
  12. //执行注册操作
  13. void doSignUp() {
  14. state.emailErrorText = null;
  15. state.passwordErrorText = null;
  16. state.confirmPasswordErrorText = null;
  17. update();
  18. var emailController = state.formData['email']!['controller'];
  19. var passwordController = state.formData['password']!['controller'];
  20. var confirmController = state.formData['confirm_password']!['controller'];
  21. state.email = emailController.text;
  22. state.password = passwordController.text;
  23. state.confirmPassword = confirmController.text;
  24. Log.d('当前待提交的 email:${state.email} password:${state.password} confirmPassword:${state.confirmPassword}');
  25. if (Utils.isEmpty(state.email)) {
  26. state.emailErrorText = "The email cannot be empty!".tr;
  27. update();
  28. } else if (Utils.isEmpty(state.password)) {
  29. state.passwordErrorText = "The password cannot be empty!".tr;
  30. update();
  31. } else if (Utils.isEmpty(state.confirmPassword)) {
  32. state.confirmPasswordErrorText = "The confirm password cannot be empty!".tr;
  33. update();
  34. } else if (state.confirmPassword != state.password) {
  35. state.confirmPasswordErrorText = "Please confirm your confirmed password!".tr;
  36. update();
  37. } else {
  38. //执行密码登录
  39. _request2Signup();
  40. }
  41. }
  42. // 调用接口注册
  43. void _request2Signup() async {
  44. var result = await _authRepository.hotelRegister(state.email, state.password, state.confirmPassword, cancelToken: cancelToken);
  45. //处理数据
  46. if (result.isSuccess) {
  47. //提交成功
  48. NotifyEngine.showSuccess("Successful".tr);
  49. Get.back();
  50. } else {
  51. ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
  52. }
  53. }
  54. }