123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //
- // YMVerifyCodeLoginViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/4.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMVerifyCodeLoginViewModel.h"
- #import "YMRetrievePasswordViewModel.h"
- #import "YMRegisterViewModel.h"
- #import "YMImproveInfoViewModel.h"
- @interface YMVerifyCodeLoginViewModel ()
- /// 登录按钮有效性
- @property (nonatomic, strong, readwrite) RACSignal *validLoginSignal;
- @end
- @implementation YMVerifyCodeLoginViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- /// 登录按钮有效性
- self.validLoginSignal = [[[RACSignal combineLatest:@[
- RACObserve(self, mobile),
- RACObserve(self, verifyCode)
- ] reduce:^(NSString *mobile, NSString *verifyCode) {
- //是否不为空
- return @(!OCStringIsEmpty(mobile) && !OCStringIsEmpty(verifyCode));
- }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
- }
- /// 获取验证码
- - (void)getVerifyCodeWithCaptcha:(id)captcha Handler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler{
- NSMutableDictionary *dictm = [NSMutableDictionary dictionary];
- dictm[@"mobile"] = self.mobile;
- dictm[@"type"] = @"login";
- 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)loginRequest{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"加载中..."];
- [LCHttpHelper requestWithURLString:PhoneCodeLogin parameters:@{
- @"mobile":self.mobile?:@"",
- @"phone_code":self.verifyCode?:@"",
- @"agreement":@"1",
- } needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
- YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- [LCSaveModel saveUserModel:userModel];
- [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
- [LCSaveData saveLoginMark:YES];
-
- [OCUserDefaults setObject:userModel.youpaipuserinfo.youpaipuser_id forKey:kUSER_ID];
- [OCUserDefaults setBool:userModel.youpaipuserinfo.youpaipgender == 1 ? YES : NO forKey:kIS_FEMALE_GENDER];
- [OCUserDefaults setBool:userModel.youpaipuserinfo.youpaipis_anchor == 1 ? YES : NO forKey:kIS_GODDESS_CERTIFIED];
- [OCUserDefaults setBool:userModel.youpaipuserinfo.youpaipvip == 0 ? NO : YES forKey:kIS_VIP];
- [OCUserDefaults synchronize];
-
- [LCHttpHelper requestWithURLString:GiftConfig parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSLog(@"GiftConfig == %@",dict);
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSMutableArray *giftArray = [NSMutableArray array];
- giftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
- for (int i = 0; i<giftArray.count; i++) {
- YOUPAILCGiftModel *model = giftArray[i];
- if (model.youpaipsvga.length > 0 ) {
- [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
- }
- }
- }
- } failure:^(NSError *error) {
-
- }];
-
- if (userModel.youpaipuserinfo.youpaiptype == 2) {
- //是特殊用户
- [LCSaveData saveIsspecial:YES];
- }
- //未完善资料,进入完善资料页面
- if (userModel.youpaipuserinfo.youpaipfinish_status == 0) {
-
- YMImproveInfoViewModel *improveInfoVM = [[YMImproveInfoViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_IMPROVE_INFO) withUserInfo:@{
- RouterViewModel:improveInfoVM
- } completion:nil];
-
- }else{
- //已经完善资料
- [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
- [LCTools changeRootToTabbar];
- }
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
-
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)gotoRegisterVC{
- YMRegisterViewModel *registerVM = [[YMRegisterViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_REGISTER) withUserInfo:@{
- RouterViewModel:registerVM
- } completion:nil];
- }
- @end
|