MOSetPasswordSMS.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. //
  2. // MOSetPasswordSMS.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/31.
  6. //
  7. #import "MOSetPasswordSMS.h"
  8. #import "MOCountDownButton.h"
  9. #import "MOSetPasswordVC.h"
  10. #import "MOBingMobileVC.h"
  11. #import "MOSuccessfulVC.h"
  12. #import "MOBindingEmailVC.h"
  13. #import "NSString+YYAdd.h"
  14. #import "MOInputCodeView.h"
  15. #import "MOSMSInputView.h"
  16. #define kCountDownTime 120
  17. @interface MOSetPasswordSMS ()
  18. @property (weak, nonatomic) IBOutlet UILabel *titleTipLab;
  19. @property (weak, nonatomic) IBOutlet UILabel *contentTipLab;
  20. @property (weak, nonatomic) IBOutlet UILabel *phoneLab;
  21. @property (nonatomic, strong) MOInputCodeView *smsInputView;
  22. @property (nonatomic, strong) MOSMSInputView *oldSmsInputView;
  23. @property (nonatomic, strong) MOCountDownButton *smsBtn;
  24. @property (nonatomic, strong) UIButton *finishBtn;
  25. @property (nonatomic, strong) UILabel *countdownLabel;
  26. @property (nonatomic, strong) UIButton *resendButton;
  27. @property (nonatomic, strong) NSTimer *countdownTimer;
  28. @property (nonatomic, assign) NSInteger countdownSeconds;
  29. @property (nonatomic, copy) NSString *smsCode;
  30. @end
  31. @implementation MOSetPasswordSMS
  32. - (void)viewWillDisappear:(BOOL)animated {
  33. [super viewWillDisappear:animated];
  34. [self stopTimer];
  35. }
  36. - (void)viewWillAppear:(BOOL)animated{
  37. [super viewWillAppear:animated];
  38. [self.navigationController setNavigationBarHidden:NO animated:animated];
  39. [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
  40. }
  41. - (void)viewDidAppear:(BOOL)animated {
  42. [super viewDidAppear:animated];
  43. [self startTimer];
  44. }
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. [self setupUI];
  48. if(self.vcType == MOEnterCodeBindPhoneType){
  49. //绑定手机
  50. self.navigationItem.title = NSLocalString(@"mimo_setting_mobile");
  51. if(!self.isHaveSendCode){
  52. [self toGetSMSCodeWithBindPhoneAndBlock:nil];
  53. }
  54. else{
  55. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  56. }
  57. }
  58. else if (self.vcType == MOEnterChangeOldPhoneCode){
  59. self.navigationItem.title = NSLocalString(@"mimo_mine_phone_change");
  60. if(!self.isHaveSendCode){
  61. [self toGetOldPhoneCodeAndBlock:nil];
  62. }
  63. else{
  64. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  65. }
  66. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  67. }
  68. else if (self.vcType == MOEnterChangeNewPhoneCode){
  69. self.navigationItem.title = NSLocalString(@"mimo_mine_phone_change");
  70. if(!self.isHaveSendCode){
  71. [self toGetNewPhoneCodeAndBlock:nil];
  72. }
  73. else{
  74. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  75. }
  76. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  77. }
  78. else if (self.vcType == MOEnterCodeBindEmail){
  79. //第一次绑定邮箱
  80. self.navigationItem.title = NSLocalString(@"mimo_mine_binding_email");
  81. if(!self.isHaveSendCode){
  82. [self firstBindTheEmailAndBlock:nil];
  83. }
  84. else{
  85. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_send_tip")];
  86. }
  87. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  88. self.titleTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_one");
  89. self.contentTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_two");
  90. }
  91. else if (self.vcType == MOEnterCodeBindNewEmailOne){
  92. self.navigationItem.title = NSLocalString(@"mimo_mine_email_change");
  93. if(!self.isHaveSendCode){
  94. [self emailChangeToGetOldEmailCodeAndBlock:nil];
  95. }
  96. else{
  97. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_code_tip_two")];
  98. }
  99. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  100. self.titleTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_one");
  101. self.contentTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_two");
  102. }
  103. else if (self.vcType == MOEnterCodeChangeEmailAndNewEmailCode){
  104. self.navigationItem.title = NSLocalString(@"mimo_mine_email_change");
  105. if(!self.isHaveSendCode){
  106. [self emailChangeAndGetTheNewEmailCodeAndBlock:nil];
  107. }
  108. else{
  109. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_code_tip_two")];
  110. }
  111. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  112. self.titleTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_one");
  113. self.contentTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_two");
  114. }
  115. else if (self.vcType == MOEnterCodeSetPsw2Type){
  116. self.navigationItem.title = NSLocalString(@"mimo_mine_password2_guild");
  117. if(!self.isHaveSendCode){
  118. [self thePassword2SettingSendCodeAndBlock:nil];
  119. }
  120. else{
  121. if(self.psw2Type == 1){
  122. //手机
  123. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  124. }
  125. else{
  126. //邮箱
  127. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_code_tip_two")];
  128. }
  129. }
  130. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  131. if(self.psw2Type == 2){
  132. self.titleTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_one");
  133. self.contentTipLab.text = NSLocalString(@"mimo_mine_binding_email_code_tip_two");
  134. }
  135. if(self.isForgetPsw2){
  136. self.navigationItem.title = NSLocalString(@"mimo_mine_password2_forget_title");
  137. }
  138. }
  139. else if (self.vcType == MOSetPsw2NumType){
  140. self.navigationItem.title = NSLocalString(@"mimo_mine_password2_guild");
  141. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  142. self.titleTipLab.text = NSLocalString(@"mimo_mine_password2_enter_tip");
  143. self.contentTipLab.hidden = YES;
  144. self.phoneLab.hidden = YES;
  145. self.smsBtn.hidden = YES;
  146. }
  147. else if (self.vcType == MOChangePsw2EnterOldPsw){
  148. //修改密码2 - 输入旧密码
  149. self.navigationItem.title = NSLocalString(@"mimo_mine_password2_change_title");
  150. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  151. self.titleTipLab.text = NSLocalString(@"mimo_mine_password2_change_vc_tip_one");
  152. self.contentTipLab.hidden = YES;
  153. self.phoneLab.hidden = YES;
  154. self.smsBtn.hidden = YES;
  155. }
  156. else if (self.vcType == MOChangePsw2EnterNewPsw){
  157. //修改密码2 - 输入新密码
  158. self.navigationItem.title = NSLocalString(@"mimo_mine_password2_change_title");
  159. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  160. self.titleTipLab.text = NSLocalString(@"mimo_mine_password2_change_vc_tip_two");
  161. self.contentTipLab.hidden = YES;
  162. self.phoneLab.hidden = YES;
  163. self.smsBtn.hidden = YES;
  164. } else if (self.vcType == MOEnterCodeReSetPasswordType) {
  165. //重置密码
  166. self.navigationItem.title = NSLocalString(@"mimo_reset_psw_title");
  167. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  168. }
  169. else{
  170. //设置密码
  171. self.navigationItem.title = NSLocalString(@"mimo_set_psw_title");
  172. if(!self.isHaveSendCode){
  173. [self toGetSMSCodeAndBlock:nil];
  174. }
  175. else{
  176. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  177. }
  178. [self.finishBtn setTitle:NSLocalString(@"mimo_login_next_step") forState:UIControlStateNormal];
  179. }
  180. [self performSelector:@selector(theSearchTexBecomeFirst) withObject:nil afterDelay:1.0];
  181. }
  182. - (void)theSearchTexBecomeFirst{
  183. [self.smsInputView showKeyboard];
  184. }
  185. - (void)setupUI{
  186. self.view.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
  187. self.titleTipLab.font = [MOTextTools regularFont:14];
  188. self.titleTipLab.textColor = kBaseTextColor_1;
  189. self.titleTipLab.text = NSLocalString(@"mimo_login_input_code");
  190. self.contentTipLab.font = [MOTextTools regularFont:14];
  191. self.contentTipLab.textColor = kBaseTextColor_3;
  192. self.contentTipLab.text = NSLocalString(@"mimo_login_send_code");
  193. self.phoneLab.font = [MOTextTools regularFont:14];
  194. self.phoneLab.textColor = kBaseTextColor_3;
  195. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  196. NSString *phoneNumStr = userInfoData.userMobile.num;
  197. if([phoneNumStr rangeOfString:@"*"].location == NSNotFound){
  198. phoneNumStr = [MOTools maskPhoneNumber:phoneNumStr];
  199. }
  200. self.phoneLab.text = [NSString stringWithFormat:@"%@ %@",userInfoData.userMobile.code,phoneNumStr];
  201. if(self.code.length != 0 && self.num.length != 0){
  202. NSString *phoneNumStr = self.num;
  203. if (self.vcType != MOEnterCodeReSetPasswordType && self.vcType != MOEnterChangeNewPhoneCode) {//如果是v2.0的忘记密码重置密码 && 更换手机号码场景,是自己输入手机号,不需要显示*
  204. if([phoneNumStr rangeOfString:@"*"].location == NSNotFound){
  205. phoneNumStr = [MOTools maskPhoneNumber:phoneNumStr];
  206. }
  207. }
  208. self.phoneLab.text = [NSString stringWithFormat:@"%@ %@",self.code,phoneNumStr];
  209. }
  210. else if (self.email.length != 0){
  211. self.phoneLab.text = self.email;
  212. } else {
  213. self.titleTipLab.text = NSLocalString(@"mimo_set_psw_first_tip");
  214. }
  215. if(self.vcType == MOSetPsw2NumType ||
  216. self.vcType == MOChangePsw2EnterOldPsw ||
  217. self.vcType == MOChangePsw2EnterNewPsw){
  218. CGFloat spacing = (SCREENWIDTH - 46.0 * 4 - 61 * 2.0 - 16.0 * 2.0) / (4 - 1);
  219. CGFloat width = 46.0 * 4.0 + spacing * 3.0 + 16.0 * 2.0;
  220. if(self.vcType == MOSetPsw2NumType ||
  221. self.vcType == MOChangePsw2EnterOldPsw ||
  222. self.vcType == MOChangePsw2EnterNewPsw){
  223. spacing = (SCREENWIDTH - 36.0 * 7 - 30.0 * 2.0 - 16.0 * 2.0) / (7 - 1);
  224. width = 36.0 * 7.0 + spacing * 6.0 + 16.0 * 2.0;
  225. }
  226. [self.view addSubview:self.oldSmsInputView];
  227. [self.oldSmsInputView mas_makeConstraints:^(MASConstraintMaker *make) {
  228. make.top.equalTo(self.phoneLab.mas_bottom).offset(17.0);
  229. make.width.equalTo(@(width));
  230. make.height.equalTo(@(kPOSMSInputBoxHeight));
  231. make.centerX.equalTo(self.view.mas_centerX);
  232. }];
  233. self.countdownLabel.hidden = YES;
  234. } else {
  235. [self.view addSubview:self.smsInputView];
  236. [self.smsInputView mas_makeConstraints:^(MASConstraintMaker *make) {
  237. make.top.equalTo(self.phoneLab.mas_bottom).offset(24);
  238. make.left.mas_equalTo(24);
  239. make.right.mas_equalTo(-24);
  240. make.height.mas_equalTo(kScaleWidth(64));
  241. }];
  242. }
  243. // [self smsBtn];
  244. [self.view addSubview:self.finishBtn];
  245. [self.finishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  246. make.left.mas_equalTo(20);
  247. make.right.mas_equalTo(-20);
  248. make.height.mas_equalTo(48);
  249. if(self.vcType == MOSetPsw2NumType ||
  250. self.vcType == MOChangePsw2EnterOldPsw ||
  251. self.vcType == MOChangePsw2EnterNewPsw){
  252. make.top.equalTo(self.oldSmsInputView.mas_bottom).offset(49);
  253. } else {
  254. make.top.equalTo(self.smsInputView.mas_bottom).offset(49);
  255. }
  256. }];
  257. [self.view addSubview:self.countdownLabel];
  258. [self.countdownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  259. make.top.equalTo(self.finishBtn.mas_bottom).offset(12);
  260. make.left.mas_equalTo(20);
  261. make.right.mas_equalTo(-24);
  262. }];
  263. [self.view addSubview:self.resendButton];
  264. [self.resendButton mas_makeConstraints:^(MASConstraintMaker *make) {
  265. make.centerY.equalTo(self.countdownLabel);
  266. make.left.mas_equalTo(20);
  267. }];
  268. }
  269. - (void)startTimer {
  270. if(self.vcType == MOSetPsw2NumType ||
  271. self.vcType == MOChangePsw2EnterOldPsw ||
  272. self.vcType == MOChangePsw2EnterNewPsw) {
  273. return;
  274. }
  275. self.countdownSeconds = kCountDownTime;
  276. self.resendButton.hidden = YES;
  277. self.countdownLabel.hidden = NO;
  278. self.countdownLabel.text = [NSString stringWithFormat:@"%@ %zds", NSLocalString(@"mimo_login_resend_code_countdown"), self.countdownSeconds];
  279. self.countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats:YES];
  280. }
  281. - (void)updateCountdown {
  282. self.countdownSeconds--;
  283. if (self.countdownSeconds <= 0) {
  284. [self stopTimer];
  285. self.countdownLabel.hidden = YES;
  286. self.resendButton.hidden = NO;
  287. } else {
  288. self.countdownLabel.text = [NSString stringWithFormat:@"%@ %zds", NSLocalString(@"mimo_login_resend_code_countdown"), self.countdownSeconds];
  289. }
  290. }
  291. - (void)stopTimer {
  292. [self.countdownTimer invalidate];
  293. self.countdownTimer = nil;
  294. }
  295. - (void)resendButtonAction {
  296. if(self.vcType == MOEnterCodeBindPhoneType){
  297. [self toGetSMSCodeWithBindPhoneAndBlock:nil];
  298. } else if (self.vcType == MOEnterChangeOldPhoneCode){
  299. [self toGetOldPhoneCodeAndBlock:nil];
  300. } else if (self.vcType == MOEnterChangeNewPhoneCode){
  301. [self toGetNewPhoneCodeAndBlock:nil];
  302. } else if (self.vcType == MOEnterCodeBindEmail){
  303. [self firstBindTheEmailAndBlock:nil];
  304. } else if (self.vcType == MOEnterCodeBindNewEmailOne){
  305. [self emailChangeToGetOldEmailCodeAndBlock:nil];
  306. } else if (self.vcType == MOEnterCodeChangeEmailAndNewEmailCode){
  307. [self emailChangeAndGetTheNewEmailCodeAndBlock:nil];
  308. } else if (self.vcType == MOEnterCodeSetPsw2Type){
  309. [self thePassword2SettingSendCodeAndBlock:nil];
  310. } else {
  311. [self toGetSMSCodeAndBlock:nil];
  312. }
  313. [self startTimer];
  314. }
  315. #pragma mark - Lazy
  316. - (MOInputCodeView *)smsInputView {
  317. if (!_smsInputView) {
  318. _smsInputView = [[MOInputCodeView alloc] init];
  319. WEAKSELF
  320. _smsInputView.inputCompleted = ^(NSString *code) {
  321. weakSelf.smsCode = code;
  322. weakSelf.finishBtn.alpha = 1.0;
  323. };
  324. }
  325. return _smsInputView;
  326. }
  327. - (MOSMSInputView *)oldSmsInputView {
  328. if (!_oldSmsInputView) {
  329. WEAKSELF
  330. if(self.vcType == MOSetPsw2NumType ||
  331. self.vcType == MOChangePsw2EnterOldPsw ||
  332. self.vcType == MOChangePsw2EnterNewPsw){
  333. CGFloat spacing = (SCREENWIDTH - 36.0 * 7 - 30.0 * 2.0 - 16.0 * 2.0) / (7 - 1);
  334. _oldSmsInputView = [[MOSMSInputView alloc] initWithFrame:CGRectMake(0, (KIsiPhoneX?302:282), (36.0 * 7.0 + spacing * 3.0 + 16.0 * 2.0), kPOSMSInputBoxHeight) AndBoxSize:CGSizeMake(36.0, 60.0) AndBoxNum:6 AndBoxSpace:spacing];
  335. _oldSmsInputView.isCiphertext = YES;
  336. }
  337. _oldSmsInputView.finishSMSCodeCallBack = ^(NSString * _Nonnull code) {
  338. weakSelf.smsCode = code;
  339. weakSelf.finishBtn.alpha = 1.0;
  340. };
  341. }
  342. return _oldSmsInputView;
  343. }
  344. - (UIButton *)finishBtn{
  345. if(!_finishBtn){
  346. _finishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  347. _finishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  348. [_finishBtn setTitle:NSLocalString(@"mimo_Finish") forState:UIControlStateNormal];
  349. NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
  350. UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 20.0 * 2), 48.0) Colors:loginColorArr GradientType:0];
  351. [_finishBtn setBackgroundImage:loginImage forState:UIControlStateNormal];
  352. _finishBtn.layer.cornerRadius = 12;
  353. _finishBtn.layer.masksToBounds = YES;
  354. _finishBtn.titleLabel.font = [MOTextTools mediumFont:16];
  355. [_finishBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  356. [_finishBtn addTarget:self action:@selector(finishBtnClick) forControlEvents:UIControlEventTouchUpInside];
  357. _finishBtn.alpha = 0.5;
  358. }
  359. return _finishBtn;
  360. }
  361. - (UILabel *)countdownLabel {
  362. if (!_countdownLabel) {
  363. _countdownLabel = [[UILabel alloc] init];
  364. _countdownLabel.textColor = [MOTools colorWithHexString:@"#999999"];
  365. _countdownLabel.font = [MOTextTools regularFont:14];
  366. _countdownLabel.text = NSLocalString(@"mimo_login_resend_code_countdown");
  367. _countdownLabel.numberOfLines = 0;
  368. }
  369. return _countdownLabel;
  370. }
  371. - (UIButton *)resendButton {
  372. if (!_resendButton) {
  373. _resendButton = [[UIButton alloc] init];
  374. _resendButton.titleLabel.font = [MOTextTools regularFont:14];
  375. [_resendButton setTitleColor:[MOTools colorWithHexString:@"#999999"] forState:UIControlStateNormal];
  376. [_resendButton setTitle:NSLocalString(@"mimo_login_resend_code") forState:UIControlStateNormal];
  377. [_resendButton addTarget:self action:@selector(resendButtonAction) forControlEvents:UIControlEventTouchUpInside];
  378. _resendButton.hidden = YES;
  379. }
  380. return _resendButton;
  381. }
  382. - (void)finishBtnClick{
  383. if(self.smsCode.length == 0){
  384. [MBProgressHUD showTipMessageInWindow:@"Please Enter"];
  385. return;
  386. }
  387. if(self.vcType == MOEnterCodeBindPhoneType){
  388. [self toBindPhoenAction];
  389. return;
  390. }
  391. else if (self.vcType == MOEnterChangeOldPhoneCode){
  392. //旧手机校验
  393. [self toCheckTheOldPhoneCode];
  394. return;
  395. }
  396. else if (self.vcType == MOEnterChangeNewPhoneCode){
  397. //新手机验证
  398. [self toCheckTheNewPhoneCode];
  399. return;
  400. }
  401. else if (self.vcType == MOEnterCodeBindEmail){
  402. //第一次绑定邮箱
  403. [self toCheckTheFirstEmailBind];
  404. return;
  405. }
  406. else if (self.vcType == MOEnterCodeBindNewEmailOne){
  407. //校验老的邮箱
  408. [self toCheckTheOldEmailCode];
  409. return;
  410. }
  411. else if (self.vcType == MOEnterCodeChangeEmailAndNewEmailCode){
  412. //校验新的邮箱
  413. [self toCheckTheNewEmailCode];
  414. return;
  415. }
  416. else if (self.vcType == MOEnterCodeSetPsw2Type){
  417. [self thePassword2SettingCheck];
  418. return;
  419. }
  420. else if (self.vcType == MOSetPsw2NumType){
  421. [self toSubmitThePassword2];
  422. return;
  423. }
  424. else if (self.vcType == MOChangePsw2EnterOldPsw){
  425. [self changePsw2AndCheckTheOldPsw];
  426. return;
  427. }
  428. else if (self.vcType == MOChangePsw2EnterNewPsw){
  429. [self changePsw2AndCheckTheNewPsw];
  430. return;
  431. }
  432. if(self.smsCode.length == 0){
  433. return;
  434. }
  435. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  436. NSString *code;
  437. NSString *num;
  438. //如果外部有传入, 就使用外部的
  439. if(self.code.length > 0){
  440. code = self.code;
  441. num = self.num;
  442. }
  443. else
  444. {
  445. code = userInfoData.userMobile.code;
  446. num = userInfoData.userMobile.num;
  447. }
  448. if(code.length == 0 ||
  449. num.length == 0){
  450. return;
  451. }
  452. //前置界面有做判空, 这里就不做判空了
  453. NSDictionary *mobileDict = @{@"code":code,
  454. @"num":num};
  455. //TODO: 请求参数需要修改
  456. WEAKSELF
  457. NSDictionary *dict = @{@"code":self.smsCode,
  458. @"mobile":mobileDict};
  459. [kHttpManager toVerifyTheSmsCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  460. if(kCode_Success){
  461. NSString *result = [MODataManager objectOrNilForKey:@"result" fromDictionary:data[@"data"]];
  462. MOSetPasswordVC *vc = [[MOSetPasswordVC alloc] init];
  463. vc.code = code;
  464. vc.num = num;
  465. vc.codeString = result;
  466. [weakSelf.navigationController pushViewController:vc animated:YES];
  467. }
  468. else{
  469. kShowNetError(data)
  470. }
  471. }];
  472. }
  473. #pragma mark - Mothed
  474. - (void)toBindPhoenAction{
  475. if(self.smsCode.length == 0){
  476. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_first_tip")];
  477. return;
  478. }
  479. [MBProgressHUD showActivityMessageInView:@""];
  480. WEAKSELF
  481. NSDictionary *mobileDict = @{@"code":self.code,
  482. @"num":self.num};
  483. NSDictionary *dict = @{@"mobile":mobileDict,
  484. @"code":self.smsCode};
  485. [kHttpManager toBingAndSubmitWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  486. [MBProgressHUD hideHUD];
  487. if(kCode_Success){
  488. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_success")];
  489. //更新个人信息缓存
  490. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  491. userInfoData.userStatusInfo.mobile = YES;
  492. userInfoData.userMobile.code = weakSelf.code;
  493. userInfoData.userMobile.num = weakSelf.num;
  494. [[MODataCache sharedYYCache] setObject:userInfoData forKey:kMineUserInfo];
  495. [[MORefreshViewManage shareManager] setNeedRefreshWithCode:@"MOMineVC"];
  496. [weakSelf performSelector:@selector(toPopVC) withObject:nil afterDelay:1.0];
  497. }
  498. else{
  499. kShowNetError(data)
  500. }
  501. }];
  502. }
  503. - (void)toPopVC{
  504. //查找扫码页面的索引
  505. NSInteger index = 0;
  506. for (UIViewController *subVC in self.navigationController.viewControllers)
  507. {
  508. if([subVC isKindOfClass:NSClassFromString(@"MOMineSetUpVC")])
  509. {
  510. index = [self.navigationController.viewControllers indexOfObject:subVC];
  511. break;
  512. }
  513. }
  514. if(index > 0){
  515. //返回到扫一扫的上一个界面
  516. UIViewController *vc = self.navigationController.viewControllers[index-1];
  517. [self.navigationController popToViewController:vc animated:YES];
  518. }
  519. else{
  520. [self.navigationController popViewControllerAnimated:YES];
  521. }
  522. }
  523. - (void)toGetSMSCodeAndBlock:(void (^)(id data, NSError *error))block{
  524. [MBProgressHUD showActivityMessageInView:@""];
  525. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  526. NSString *code;
  527. NSString *num;
  528. //如果外部有传入, 就使用外部的
  529. if(self.code.length > 0){
  530. code = self.code;
  531. num = self.num;
  532. }
  533. else
  534. {
  535. code = userInfoData.userMobile.code;
  536. num = userInfoData.userMobile.num;
  537. }
  538. if(code.length == 0 ||
  539. num.length == 0){
  540. return;
  541. }
  542. NSDictionary *dic = @{@"code":code,
  543. @"num":num};
  544. [kHttpManager toGetPasswordCode2WithParams:dic andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  545. [MBProgressHUD hideHUD];
  546. if(kCode_Success){
  547. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  548. }
  549. else{
  550. kShowNetError(data)
  551. }
  552. block ? block(data,error) : nil;
  553. }];
  554. }
  555. ///绑定手机
  556. - (void)toGetSMSCodeWithBindPhoneAndBlock:(void (^)(id data, NSError *error))block{
  557. [MBProgressHUD showActivityMessageInView:@""];
  558. if(self.code.length == 0 ||
  559. self.num.length == 0){
  560. return;
  561. }
  562. WEAKSELF
  563. NSDictionary *dic = @{@"code":self.code,
  564. @"num":self.num};
  565. [kHttpManager firstToBingCodeWithParams:dic andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  566. [MBProgressHUD hideHUD];
  567. if(kCode_Success){
  568. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  569. }
  570. else{
  571. kShowNetError(data)
  572. }
  573. block ? block(data,error) : nil;
  574. }];
  575. }
  576. - (void)toGetOldPhoneCodeAndBlock:(void (^)(id data, NSError *error))block{
  577. [MBProgressHUD showActivityMessageInView:@""];
  578. [kHttpManager toSendTheUserOldMobileChangeCodleWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  579. [MBProgressHUD hideHUD];
  580. if(kCode_Success){
  581. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  582. }
  583. else{
  584. kShowNetError(data)
  585. }
  586. block ? block(data,error) : nil;
  587. }];
  588. }
  589. - (void)toCheckTheOldPhoneCode{
  590. WEAKSELF
  591. if(self.smsCode.length == 0){
  592. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_first_tip")];
  593. return;
  594. }
  595. [MBProgressHUD showActivityMessageInView:@""];
  596. NSDictionary *dict = @{@"data":self.smsCode};
  597. [kHttpManager toCheckTheOldMobileCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  598. [MBProgressHUD hideHUD];
  599. if(kCode_Success){
  600. MOBingMobileVC *vc = [[MOBingMobileVC alloc] init];
  601. vc.isBingNewPhone = YES;
  602. NSString *credentialsStr = [MODataManager objectOrNilForKey:@"result" fromDictionary:data[@"data"]];
  603. vc.credentials = credentialsStr;
  604. [weakSelf.navigationController pushViewController:vc animated:YES];
  605. }
  606. else{
  607. kShowNetError(data)
  608. }
  609. }];
  610. }
  611. - (void)toGetNewPhoneCodeAndBlock:(void (^)(id data, NSError *error))block{
  612. [MBProgressHUD showActivityMessageInView:@""];
  613. NSDictionary *mobileDict = @{@"code":self.code,@"num":self.num};
  614. NSDictionary *dict = @{@"credentials":self.credentials,@"mobile":mobileDict};
  615. [kHttpManager toSendTheNewMobileCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  616. [MBProgressHUD hideHUD];
  617. if(kCode_Success){
  618. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  619. }
  620. else{
  621. kShowNetError(data)
  622. }
  623. block ? block(data,error) : nil;
  624. }];
  625. }
  626. - (void)toCheckTheNewPhoneCode{
  627. [MBProgressHUD showActivityMessageInView:@""];
  628. WEAKSELF
  629. NSDictionary *mobileDict = @{@"code":self.code,@"num":self.num};
  630. NSDictionary *dict = @{@"credentials":self.credentials,@"mobile":mobileDict,@"code":self.smsCode};
  631. [kHttpManager toBingTheNewMobileWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  632. [MBProgressHUD hideHUD];
  633. if(kCode_Success){
  634. //跳转绑定成功界面
  635. MOSuccessfulVC *vc = [[MOSuccessfulVC alloc] init];
  636. vc.code = weakSelf.code;
  637. vc.num = weakSelf.num;
  638. vc.isBingPhone = YES;
  639. [weakSelf.navigationController pushViewController:vc animated:YES];
  640. }
  641. else{
  642. kShowNetError(data)
  643. }
  644. }];
  645. }
  646. - (void)firstBindTheEmailAndBlock:(void (^)(id data, NSError *error))block{
  647. if(self.email.length == 0){
  648. return;
  649. }
  650. [MBProgressHUD showActivityMessageInView:@""];
  651. NSDictionary *dict = @{@"email":self.email};
  652. WEAKSELF
  653. [kHttpManager toBindEmailAndGetCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  654. [MBProgressHUD hideHUD];
  655. if(kCode_Success){
  656. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_send_tip")];
  657. }
  658. else{
  659. kShowNetError(data)
  660. }
  661. block ? block(data,error) : nil;
  662. }];
  663. }
  664. - (void)toCheckTheFirstEmailBind{
  665. [MBProgressHUD showActivityMessageInView:@""];
  666. NSDictionary *dict = @{@"email":self.email,
  667. @"code":self.smsCode};
  668. WEAKSELF
  669. [kHttpManager toSubmitTheEmailWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  670. [MBProgressHUD hideHUD];
  671. if(kCode_Success){
  672. //绑定成功
  673. MOSuccessfulVC *vc = [[MOSuccessfulVC alloc] init];
  674. vc.email = weakSelf.email;
  675. vc.vcType = MOSuccessfulTypeBindEmail;
  676. [weakSelf.navigationController pushViewController:vc animated:YES];
  677. }
  678. else{
  679. kShowNetError(data)
  680. }
  681. }];
  682. }
  683. - (void)emailChangeToGetOldEmailCodeAndBlock:(void (^)(id data, NSError *error))block{
  684. [MBProgressHUD showActivityMessageInView:@""];
  685. WEAKSELF
  686. [kHttpManager getTheOldEmailCodeWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  687. [MBProgressHUD hideHUD];
  688. if(kCode_Success){
  689. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_code_tip_two")];
  690. }
  691. else{
  692. kShowNetError(data)
  693. }
  694. block ? block(data,error) : nil;
  695. }];
  696. }
  697. - (void)toCheckTheOldEmailCode{
  698. [MBProgressHUD showActivityMessageInView:@""];
  699. NSDictionary *dict = @{@"data":self.smsCode};
  700. WEAKSELF
  701. [kHttpManager toCheckTheOldEmailCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  702. [MBProgressHUD hideHUD];
  703. if(kCode_Success){
  704. //输入新的邮箱
  705. NSString *credentials = [MODataManager objectOrNilForKey:@"result" fromDictionary:data[@"data"]];
  706. MOBindingEmailVC *vc = [[MOBindingEmailVC alloc] init];
  707. vc.isBindNewEmail = YES;
  708. vc.credentials = credentials;
  709. [weakSelf.navigationController pushViewController:vc animated:YES];
  710. }
  711. else{
  712. kShowNetError(data)
  713. }
  714. }];
  715. }
  716. - (void)emailChangeAndGetTheNewEmailCodeAndBlock:(void (^)(id data, NSError *error))block{
  717. [MBProgressHUD showActivityMessageInView:@""];
  718. NSDictionary *dict = @{@"credentials":self.credentials,@"email":self.email};
  719. WEAKSELF
  720. [kHttpManager getTheNewEmailCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  721. [MBProgressHUD hideHUD];
  722. if(kCode_Success){
  723. //验证码已经发送
  724. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_code_tip_two")];
  725. }
  726. else{
  727. kShowNetError(data)
  728. }
  729. block ? block(data,error) : nil;
  730. }];
  731. }
  732. - (void)toCheckTheNewEmailCode{
  733. [MBProgressHUD showActivityMessageInView:@""];
  734. NSDictionary *dict = @{@"email":self.email,
  735. @"credentials":self.credentials,
  736. @"code":self.smsCode};
  737. WEAKSELF
  738. [kHttpManager toBindTheNewEmailWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  739. [MBProgressHUD hideHUD];
  740. if(kCode_Success){
  741. //换绑成功
  742. MOSuccessfulVC *vc = [[MOSuccessfulVC alloc] init];
  743. vc.vcType = MOSuccessfulTypeChangeEmail;
  744. vc.email = weakSelf.email;
  745. [weakSelf.navigationController pushViewController:vc animated:YES];
  746. }
  747. else{
  748. kShowNetError(data)
  749. }
  750. }];
  751. }
  752. - (void)thePassword2SettingSendCodeAndBlock:(void (^)(id data, NSError *error))block{
  753. [MBProgressHUD showActivityMessageInView:@""];
  754. WEAKSELF
  755. NSDictionary *dict = @{@"type":@(self.psw2Type)};
  756. [kHttpManager thePassword2SettingSendCodeWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  757. [MBProgressHUD hideHUD];
  758. if(kCode_Success){
  759. if(weakSelf.psw2Type == 1){
  760. //手机
  761. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_content_tip")];
  762. }
  763. else{
  764. //邮箱
  765. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_mine_binding_email_code_tip_two")];
  766. }
  767. }
  768. else{
  769. kShowNetError(data)
  770. }
  771. block ? block(data,error) : nil;
  772. }];
  773. }
  774. - (void)thePassword2SettingCheck{
  775. [MBProgressHUD showActivityMessageInView:@""];
  776. NSDictionary *dict = @{@"type":@(self.psw2Type),
  777. @"code":self.smsCode};
  778. WEAKSELF
  779. [kHttpManager thePassword2SettingVerifyWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  780. [MBProgressHUD hideHUD];
  781. if(kCode_Success){
  782. //设置密码2
  783. NSString *credentials = [MODataManager objectOrNilForKey:@"result" fromDictionary:data[@"data"]];
  784. MOSetPasswordSMS *vc = [[MOSetPasswordSMS alloc] init];
  785. vc.credentials = credentials;
  786. vc.psw2Type = weakSelf.psw2Type;
  787. vc.vcType = MOSetPsw2NumType;
  788. vc.password2 = weakSelf.smsCode;
  789. [weakSelf.navigationController pushViewController:vc animated:YES];
  790. }
  791. else{
  792. kShowNetError(data)
  793. }
  794. }];
  795. }
  796. - (void)toSubmitThePassword2{
  797. //设置Password2
  798. [MBProgressHUD showActivityMessageInView:@""];
  799. NSString *thePsw2Str = [self.smsCode md5String];
  800. NSDictionary *dict = @{@"type":@(self.psw2Type),
  801. @"password":thePsw2Str,
  802. @"credentials":self.credentials};
  803. WEAKSELF
  804. [kHttpManager thePassword2SettingSubmitWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  805. [MBProgressHUD hideHUD];
  806. if(kCode_Success){
  807. //提交密码2
  808. MOSuccessfulVC *vc = [[MOSuccessfulVC alloc] init];
  809. vc.vcType = MOSuccessfulTypePsw2Submit;
  810. [weakSelf.navigationController pushViewController:vc animated:YES];
  811. }
  812. else{
  813. kShowNetError(data)
  814. }
  815. }];
  816. }
  817. - (void)changePsw2AndCheckTheOldPsw{
  818. //校验旧密码2
  819. [MBProgressHUD showActivityMessageInView:@""];
  820. NSString *thePsw2Str = [self.smsCode md5String];
  821. NSDictionary *dict = @{@"data":thePsw2Str};
  822. WEAKSELF
  823. [kHttpManager thePassword2ChangeVerifyWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  824. [MBProgressHUD hideHUD];
  825. if(kCode_Success){
  826. NSString *credentials = [MODataManager objectOrNilForKey:@"result" fromDictionary:data[@"data"]];
  827. MOSetPasswordSMS *vc = [[MOSetPasswordSMS alloc] init];
  828. vc.vcType = MOChangePsw2EnterNewPsw;
  829. vc.credentials = credentials;
  830. [weakSelf.navigationController pushViewController:vc animated:YES];
  831. }
  832. else{
  833. kShowNetError(data)
  834. }
  835. }];
  836. }
  837. - (void)changePsw2AndCheckTheNewPsw{
  838. //输入新密码2
  839. [MBProgressHUD showActivityMessageInView:@""];
  840. NSString *thePsw2Str = [self.smsCode md5String];
  841. NSDictionary *dict = @{@"password":thePsw2Str,
  842. @"credentials":self.credentials};
  843. WEAKSELF
  844. [kHttpManager thePassword2ChangeSubmitWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  845. [MBProgressHUD hideHUD];
  846. if(kCode_Success){
  847. MOSuccessfulVC *vc = [[MOSuccessfulVC alloc] init];
  848. vc.vcType = MOSuccessfulTypePsw2Change;
  849. [weakSelf.navigationController pushViewController:vc animated:YES];
  850. }
  851. else{
  852. kShowNetError(data)
  853. }
  854. }];
  855. }
  856. @end