12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // 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)getVerifyCodeHandler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"获取验证码中"];
- [LCHttpHelper requestWithURLString:PhoneCode parameters:@{
- @"mobile":self.mobile,
- @"type":@"findadpwd"
- } 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
|