YMRetrievePasswordViewModel.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // YMRetrievePasswordViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/6.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMRetrievePasswordViewModel.h"
  9. @interface YMRetrievePasswordViewModel ()
  10. /// 重置密码按钮有效性
  11. @property (nonatomic, strong, readwrite) RACSignal *validRetrievePasswordSignal;
  12. @end
  13. @implementation YMRetrievePasswordViewModel
  14. - (void)ym_initialize{
  15. [super ym_initialize];
  16. /// 找回按钮有效性
  17. self.validRetrievePasswordSignal = [[[RACSignal combineLatest:@[
  18. RACObserve(self, mobile),
  19. RACObserve(self, verifyCode),
  20. RACObserve(self, password)
  21. ] reduce:^(NSString *mobile, NSString *verifyCode, NSString *password ) {
  22. //是否不为空
  23. return @(!OCStringIsEmpty(mobile) && !OCStringIsEmpty(verifyCode) &&!OCStringIsEmpty(password));
  24. }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
  25. }
  26. /// 获取验证码
  27. - (void)getVerifyCodeHandler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler{
  28. @weakify(self)
  29. [ZCHUDHelper showWithStatus:@"获取验证码中"];
  30. [LCHttpHelper requestWithURLString:PhoneCode parameters:@{
  31. @"mobile":self.mobile,
  32. @"type":@"findadpwd"
  33. } needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  34. @strongify(self)
  35. NSDictionary* dict = (NSDictionary*)responseObject;
  36. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  37. if (code == 0) {
  38. [ZCHUDHelper showTitle:@"验证码已发送"];
  39. handler(dict?:@{},nil);
  40. }else{
  41. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  42. }
  43. } failure:^(NSError *error) {
  44. [ZCHUDHelper showTitle:error.localizedDescription];
  45. }];
  46. }
  47. - (void)retrievePasswordRequest{
  48. [LCHttpHelper requestWithURLString:UpdatePassword parameters:@{
  49. @"mobile":self.mobile?:@"",
  50. @"phone_code":self.verifyCode?:@"",
  51. @"password":self.password?:@"",
  52. @"agreement":@"1",
  53. } needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  54. NSDictionary* dict = (NSDictionary*)responseObject;
  55. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  56. if (code == 0) {
  57. [ZCHUDHelper showTitle:@"密码修改成功"];
  58. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  59. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  60. });
  61. }else{
  62. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  63. }
  64. } failure:^(NSError *error) {
  65. [ZCHUDHelper showTitle:error.localizedDescription];
  66. }];
  67. }
  68. @end