YMRetrievePasswordViewModel.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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)getVerifyCodeWithCapthca:(id)captcha Handler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler{
  28. NSMutableDictionary *dictm = [NSMutableDictionary dictionary];
  29. dictm[@"mobile"] = self.mobile;
  30. dictm[@"type"] = @"findadpwd";
  31. if ([captcha isKindOfClass:[NSString class]]) {
  32. dictm[@"captcha"] = captcha;
  33. }
  34. if ([captcha isKindOfClass:[NSDictionary class]]) {
  35. [dictm addEntriesFromDictionary:captcha];
  36. }
  37. @weakify(self)
  38. [ZCHUDHelper showWithStatus:@"获取验证码中"];
  39. [LCHttpHelper requestWithURLString:PhoneCode parameters:dictm needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  40. @strongify(self)
  41. NSDictionary* dict = (NSDictionary*)responseObject;
  42. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  43. if (code == 0) {
  44. [ZCHUDHelper showTitle:@"验证码已发送"];
  45. handler(dict?:@{},nil);
  46. }else{
  47. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  48. }
  49. } failure:^(NSError *error) {
  50. [ZCHUDHelper showTitle:error.localizedDescription];
  51. }];
  52. }
  53. - (void)retrievePasswordRequest{
  54. [LCHttpHelper requestWithURLString:UpdatePassword parameters:@{
  55. @"mobile":self.mobile?:@"",
  56. @"phone_code":self.verifyCode?:@"",
  57. @"password":self.password?:@"",
  58. @"agreement":@"1",
  59. } needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  60. NSDictionary* dict = (NSDictionary*)responseObject;
  61. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  62. if (code == 0) {
  63. [ZCHUDHelper showTitle:@"密码修改成功"];
  64. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  65. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  66. });
  67. }else{
  68. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  69. }
  70. } failure:^(NSError *error) {
  71. [ZCHUDHelper showTitle:error.localizedDescription];
  72. }];
  73. }
  74. @end