1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // YMRetrievePasswordViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/6.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMRetrievePasswordViewModel.h"
- @interface YMRetrievePasswordViewModel ()
- /// 重置密码按钮有效性
- @property (nonatomic, strong, readwrite) RACSignal *validRetrievePasswordSignal;
- @end
- @implementation YMRetrievePasswordViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- /// 找回按钮有效性
- self.validRetrievePasswordSignal = [[[RACSignal combineLatest:@[
- RACObserve(self, mobile),
- RACObserve(self, verifyCode),
- RACObserve(self, password)
- ] reduce:^(NSString *mobile, NSString *verifyCode, NSString *password ) {
- //是否不为空
- return @(!OCStringIsEmpty(mobile) && !OCStringIsEmpty(verifyCode) &&!OCStringIsEmpty(password));
- }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
- }
- /// 获取验证码
- - (void)getVerifyCodeWithCapthca:(id)captcha Handler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler{
- NSMutableDictionary *dictm = [NSMutableDictionary dictionary];
- dictm[@"mobile"] = self.mobile;
- dictm[@"type"] = @"findadpwd";
- if ([captcha isKindOfClass:[NSString class]]) {
- dictm[@"captcha"] = captcha;
- }
- if ([captcha isKindOfClass:[NSDictionary class]]) {
- [dictm addEntriesFromDictionary:captcha];
- }
-
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"获取验证码中"];
- [LCHttpHelper requestWithURLString:PhoneCode parameters:dictm needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper showTitle:@"验证码已发送"];
- handler(dict?:@{},nil);
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)retrievePasswordRequest{
- [LCHttpHelper requestWithURLString:UpdatePassword parameters:@{
- @"mobile":self.mobile?:@"",
- @"phone_code":self.verifyCode?:@"",
- @"password":self.password?:@"",
- @"agreement":@"1",
- } needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper showTitle:@"密码修改成功"];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
- });
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- @end
|