LoginForgotC.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // LoginForgotC.m
  3. // westkissMob
  4. //
  5. // Created by 王猛 on 2022/9/6.
  6. //
  7. #import "LoginForgotC.h"
  8. #import "APPassForgetCodeV.h"
  9. #import "APPassForgetEmailV.h"
  10. #import "APPassForgetNewPassV.h"
  11. @interface LoginForgotC ()
  12. @property (nonatomic, copy) NSString *email;
  13. @property (nonatomic, copy) NSString *code;
  14. @property (nonatomic, copy) NSString *pass;
  15. // 0:emailV 1:codeV 2:passV
  16. @property (nonatomic, assign) NSInteger showType;
  17. @property (nonatomic , strong) UIScrollView *scrollview;
  18. @property (nonatomic, strong) APPassForgetEmailV *emailV;
  19. @property (nonatomic, strong) APPassForgetCodeV *codeV;
  20. @property (nonatomic, strong) APPassForgetNewPassV *passV;
  21. @end
  22. @implementation LoginForgotC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self addSubV];
  26. [self setVAction];
  27. self.showType = 0;
  28. [self setShowViewState];
  29. self.view.backgroundColor = _FFF8F9;
  30. }
  31. - (void)setVAction {
  32. __weak typeof(self) weakSelf = self;
  33. self.emailV.btnClick = ^(NSString *emailAddr){
  34. [weakSelf.view endEditing:true];
  35. weakSelf.email = emailAddr;
  36. [weakSelf showEmailTipAlert];
  37. };
  38. self.codeV.resendBtnClick = ^{
  39. [weakSelf.view endEditing:true];
  40. [weakSelf reqNet_forgotPassWord];
  41. };
  42. self.codeV.noReceiveClick = ^{
  43. [weakSelf.view endEditing:true];
  44. weakSelf.showType = 0;
  45. [weakSelf setShowViewState];
  46. };
  47. self.codeV.subBtnClick = ^(NSString *codeStr){
  48. [weakSelf.view endEditing:true];
  49. weakSelf.code = codeStr;
  50. weakSelf.showType = 2;
  51. [weakSelf setShowViewState];
  52. };
  53. self.passV.btnClick = ^(NSString * _Nonnull passStr) {
  54. [weakSelf.view endEditing:true];
  55. weakSelf.pass = passStr;
  56. [weakSelf reqNet_reSetPassWord];
  57. };
  58. }
  59. - (void)addSubV{
  60. self.customNavBar.hidden = true;
  61. self.navigationController.navigationBar.hidden = YES;
  62. [self.view addSubview:self.scrollview];
  63. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  64. [closeBtn setImage:[UIImage imageNamed:@"login_close_black"] forState:UIControlStateNormal];
  65. [closeBtn addTarget:self action:@selector(action_back) forControlEvents:UIControlEventTouchUpInside];
  66. [self.view addSubview:closeBtn];
  67. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(@(IPHONEX ? 44 : 20));
  69. make.centerX.equalTo(self.view);
  70. make.width.height.equalTo(@50);
  71. }];
  72. UIImage *logoImg = [UIImage imageNamed:@"name_icon"];
  73. UIImageView *bottomImgV = [[UIImageView alloc]initWithImage:logoImg];
  74. [self.view addSubview:bottomImgV];
  75. [bottomImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-25);
  77. make.centerX.equalTo(self.view);
  78. make.width.equalTo(@104);
  79. make.height.equalTo(@32);
  80. }];
  81. [self.scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(closeBtn.mas_bottom);
  83. make.leading.trailing.equalTo(self.view);
  84. make.bottom.equalTo(bottomImgV.mas_top);
  85. }];
  86. [self.scrollview addSubview:self.emailV];
  87. [self.scrollview addSubview:self.passV];
  88. [self.scrollview addSubview:self.codeV];
  89. [self.emailV mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.edges.equalTo(self.scrollview);
  91. make.width.equalTo(self.view);
  92. }];
  93. [self.passV mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.edges.equalTo(self.scrollview);
  95. make.width.equalTo(self.view);
  96. }];
  97. [self.codeV mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.edges.equalTo(self.scrollview);
  99. make.width.equalTo(self.view);
  100. }];
  101. }
  102. - (void)showEmailTipAlert {
  103. NSString *tipStr = [NSString stringWithFormat:@"Please check the verification code by %@.", self.email];
  104. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:tipStr preferredStyle:UIAlertControllerStyleAlert];
  105. __weak typeof(self) weakSelf = self;
  106. UIAlertAction *sureAc = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  107. [alert dismissViewControllerAnimated:true completion:nil];
  108. [weakSelf reqNet_forgotPassWord];
  109. }];
  110. [alert addAction:sureAc];
  111. [self presentViewController:alert animated:true completion:nil];
  112. }
  113. - (void)setShowViewState {
  114. switch (self.showType) {
  115. case 1:
  116. self.passV.hidden = true;
  117. self.codeV.hidden = false;
  118. self.emailV.hidden = true;
  119. break;
  120. case 2:
  121. self.passV.hidden = false;
  122. self.codeV.hidden = true;
  123. self.emailV.hidden = true;
  124. break;
  125. default:
  126. self.passV.hidden = true;
  127. self.codeV.hidden = true;
  128. self.emailV.hidden = false;
  129. break;
  130. }
  131. }
  132. -(void)action_back{
  133. if (self.showType == 1) {
  134. self.showType = 0;
  135. [self setShowViewState];
  136. return;
  137. }
  138. if (self.showType == 2) {
  139. self.showType = 1;
  140. [self setShowViewState];
  141. return;
  142. }
  143. [self.navigationController popViewControllerAnimated:YES];
  144. }
  145. -(void)action_submitClick{
  146. if (![Current_normalTool xxx_isValidateEmail:self.email]) {
  147. [self.view makeToast:@"Please prvide an email address." duration:2 position:CSToastPositionCenter];
  148. return;
  149. }
  150. [self reqNet_forgotPassWord];
  151. }
  152. #pragma mark - **************** reqNet ****************
  153. -(void)reqNet_forgotPassWord{
  154. if (self.email == nil || self.email.isEmpty) {
  155. return;
  156. }
  157. __weak typeof(self) weakSelf = self;
  158. [ASNetTools.shared postWithPath:postEmailCode param:@{@"email":self.email} success:^(id _Nonnull json) {
  159. if (weakSelf.showType != 1) {
  160. weakSelf.codeV.emailAddr = self.email;
  161. weakSelf.showType = 1;
  162. [weakSelf setShowViewState];
  163. }
  164. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  165. [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
  166. }];
  167. }
  168. -(void)reqNet_reSetPassWord{
  169. if (self.email == nil || self.email.isEmpty) {
  170. return;
  171. }
  172. __weak typeof(self) weakSelf = self;
  173. NSMutableDictionary *param = [NSMutableDictionary dictionary];
  174. [param setValue:self.email forKey:@"email"];
  175. [param setValue:self.code forKey:@"code"];
  176. [param setValue:self.pass forKey:@"newPassword"];
  177. [ASNetTools.shared postWithPath:postResetPass param:param success:^(id _Nonnull json) {
  178. [[UIApplication sharedApplication].windows.firstObject makeToast:@"Success"];
  179. [weakSelf.navigationController popViewControllerAnimated:YES];
  180. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  181. [weakSelf.view makeToast:msg duration:2 position:CSToastPositionCenter];
  182. if ([code isEqualToString:@"100"]) {
  183. weakSelf.showType = 1;
  184. weakSelf.pass = @"";
  185. [weakSelf.passV clearPass];
  186. [weakSelf setShowViewState];
  187. }
  188. }];
  189. }
  190. - (UIScrollView *)scrollview {
  191. if (!_scrollview) {
  192. _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  193. }
  194. return _scrollview;
  195. }
  196. - (APPassForgetCodeV *)codeV {
  197. if (!_codeV) {
  198. APPassForgetCodeV *v = [[APPassForgetCodeV alloc] initWithFrame:self.scrollview.bounds];
  199. _codeV = v;
  200. }
  201. return _codeV;
  202. }
  203. - (APPassForgetEmailV *)emailV {
  204. if (!_emailV) {
  205. APPassForgetEmailV *v = [[APPassForgetEmailV alloc] initWithFrame:self.scrollview.bounds];
  206. _emailV = v;
  207. }
  208. return _emailV;
  209. }
  210. - (APPassForgetNewPassV *)passV {
  211. if (!_passV) {
  212. APPassForgetNewPassV *v = [[APPassForgetNewPassV alloc] initWithFrame:self.scrollview.bounds];
  213. _passV = v;
  214. }
  215. return _passV;
  216. }
  217. @end