ResetPassword_VC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //
  2. // ResetPassword_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2018/12/30.
  6. // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "ResetPassword_VC.h"
  9. #import "Header.h"
  10. @interface ResetPassword_VC ()<UITextFieldDelegate>
  11. @end
  12. @implementation ResetPassword_VC
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. self.navigationItem.title = @"重设密码";
  16. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor colorWithRed:66/255.0 green:66/255.0 blue:66/255.0 alpha:1]}];
  17. //设置导航栏左侧按钮
  18. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  19. [backBtn setImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
  20. backBtn.frame = CGRectMake(0, 0, 44, 44);
  21. [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
  22. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  23. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  24. [self setupUI];
  25. }
  26. #pragma mark -Set UI
  27. -(void)setupUI{
  28. /** 设置背景 */
  29. self.view.backgroundColor = [UIColor whiteColor];
  30. /** 设置返回 */
  31. // self.backBtn.frame = CGRectMake(10, 20, 30, 30);
  32. // [self.backBtn setBackgroundImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
  33. // [self.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
  34. // [self.view addSubview:self.backBtn];
  35. /**返回label */
  36. // self.backLabel.frame = CGRectMake(40, 20, 60, 30);
  37. // self.backLabel.text = @"返回";
  38. //// self.backLabel.textAlignment = NSTextAlignmentCenter;
  39. // self.backLabel.font = [UIFont systemFontOfSize:18];
  40. // [self.view addSubview:self.backLabel];
  41. /** 设置logo */
  42. [self.logoImageView setImage:[UIImage imageNamed:@"logo"]];
  43. self.logoImageView.frame = CGRectMake(WIDTH/2-55, HEIGHT/4-75, 110, 110);
  44. [self.view addSubview:self.logoImageView];
  45. /** 设置内容视图 */
  46. /**设置账户输入框 */
  47. self.accountTF.frame = CGRectMake(20, HEIGHT/2-64, WIDTH-40, 44);
  48. self.accountTF.placeholder = @"请输入注册手机号";
  49. self.accountTF.tintColor = [UIColor blueColor];
  50. self.accountTF.textColor = [UIColor blackColor];
  51. self.accountTF.font = [UIFont systemFontOfSize:18];
  52. self.accountTF.leftViewMode = UITextFieldViewModeAlways;
  53. self.accountTF.clearsOnBeginEditing = YES;
  54. self.accountTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  55. self.accountTF.autocorrectionType =UITextAutocorrectionTypeDefault;
  56. self.accountTF.delegate = self;
  57. //设置左边视图
  58. UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  59. userImage.contentMode = UIViewContentModeLeft;
  60. //??
  61. userImage.image = [UIImage imageNamed:@"hsh_login_user"];
  62. self.accountTF.leftView = userImage;
  63. [self.view addSubview:self.accountTF];
  64. UIView *accountLine = [[UIView alloc]init];
  65. //??
  66. accountLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  67. accountLine.backgroundColor = [UIColor grayColor];
  68. self.accountLine = accountLine;
  69. [self.accountTF addSubview:accountLine];
  70. /** 设置验证码输入框 */
  71. self.smsCodeTF.frame = CGRectMake(20, HEIGHT/2-20, WIDTH-40, 44);
  72. self.smsCodeTF.placeholder = @"请输入手机验证码";
  73. self.smsCodeTF.tintColor = [UIColor blueColor];
  74. self.smsCodeTF.textColor = [UIColor blackColor];
  75. self.smsCodeTF.font = [UIFont systemFontOfSize:18];
  76. self.smsCodeTF.leftViewMode = UITextFieldViewModeAlways;
  77. // self.smsCodeTF.clearsOnBeginEditing = YES;
  78. // self.smsCodeTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  79. self.smsCodeTF.autocorrectionType =UITextAutocorrectionTypeDefault;
  80. self.smsCodeTF.delegate = self;
  81. //设置左边视图
  82. UIImageView *smsImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  83. smsImage.contentMode = UIViewContentModeLeft;
  84. smsImage.image = [UIImage imageNamed:@"hsh_register_verification"];
  85. self.smsCodeTF.leftView = smsImage;
  86. [self.view addSubview:self.smsCodeTF];
  87. UIView *smsLine = [[UIView alloc]init];
  88. //??
  89. smsLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  90. smsLine.backgroundColor = [UIColor grayColor];
  91. self.smsLine = smsLine;
  92. [self.smsCodeTF addSubview:self.smsLine];
  93. /**设置重置密码button */
  94. self.resetPasswordBtn.frame = CGRectMake(self.smsCodeTF.frame.size.width-100, 5, 100, 34);
  95. self.resetPasswordBtn.layer.cornerRadius = 12;
  96. self.resetPasswordBtn.backgroundColor = [UIColor colorWithRed:113/255.0 green:154/255.90 blue:254/255.0 alpha:1];
  97. [self.resetPasswordBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  98. [self.resetPasswordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  99. self.resetPasswordBtn.titleLabel.textColor = [UIColor whiteColor];
  100. self.resetPasswordBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  101. self.resetPasswordBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
  102. [self.resetPasswordBtn addTarget:self action:@selector(getSMSCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  103. [self.smsCodeTF addSubview:self.resetPasswordBtn];
  104. /**设置密码输入框 */
  105. self.passwordTF.frame = CGRectMake(20, HEIGHT/2+22, WIDTH-40, 44);
  106. self.passwordTF.placeholder = @"请输入新密码";
  107. self.passwordTF.tintColor = [UIColor blueColor];
  108. self.passwordTF.textColor = [UIColor blackColor];
  109. self.passwordTF.font = [UIFont systemFontOfSize:18];
  110. self.passwordTF.leftViewMode = UITextFieldViewModeAlways;
  111. self.passwordTF.delegate = self;
  112. self.passwordTF.clearsOnBeginEditing = YES;
  113. self.passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  114. self.passwordTF.autocorrectionType =UITextAutocorrectionTypeDefault;
  115. self.passwordTF.secureTextEntry =YES;
  116. //设置左边视图
  117. UIImageView *passwordImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  118. passwordImage.contentMode = UIViewContentModeLeft;
  119. passwordImage.image = [UIImage imageNamed:@"hsh_login_password"];
  120. self.passwordTF.leftView = passwordImage;
  121. [self.view addSubview:self.passwordTF];
  122. UIView *passwordLine = [[UIView alloc]init];
  123. //??
  124. passwordLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  125. passwordLine.backgroundColor = [UIColor grayColor];
  126. self.passwordLine = passwordLine;
  127. [self.passwordTF addSubview:passwordLine];
  128. /** 设置确认密码 */
  129. self.confirmPasswordTf.frame = CGRectMake(20, HEIGHT/2+66, WIDTH-40, 44);
  130. self.confirmPasswordTf.placeholder = @"请再次确认密码";
  131. self.confirmPasswordTf.tintColor = [UIColor blueColor];
  132. self.confirmPasswordTf.textColor = [UIColor blackColor];
  133. self.confirmPasswordTf.font = [UIFont systemFontOfSize:18];
  134. self.confirmPasswordTf.leftViewMode = UITextFieldViewModeAlways;
  135. self.confirmPasswordTf.delegate = self;
  136. self.confirmPasswordTf.clearsOnBeginEditing = YES;
  137. self.confirmPasswordTf.clearButtonMode = UITextFieldViewModeWhileEditing;
  138. self.confirmPasswordTf.autocorrectionType =UITextAutocorrectionTypeDefault;
  139. self.confirmPasswordTf.secureTextEntry =YES;
  140. //设置左边视图
  141. UIImageView *confirmImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  142. confirmImage.contentMode = UIViewContentModeLeft;
  143. confirmImage.image = [UIImage imageNamed:@"hsh_login_password"];
  144. self.confirmPasswordTf.leftView = confirmImage;
  145. [self.view addSubview:self.confirmPasswordTf];
  146. UIView *confirmLine = [[UIView alloc]init];
  147. //??
  148. confirmLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  149. confirmLine.backgroundColor = [UIColor grayColor];
  150. self.confirmLine = confirmLine;
  151. [self.confirmPasswordTf addSubview:self.confirmLine];
  152. /**设置提交Button */
  153. self.registButton.frame = CGRectMake(20, HEIGHT-100, WIDTH-40, 44);
  154. self.registButton.layer.cornerRadius = 18;
  155. [self.registButton setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal];
  156. [self.registButton setTitle:@"提交" forState:UIControlStateNormal];
  157. [self.registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  158. self.registButton.titleLabel.font = [UIFont systemFontOfSize:18];
  159. self.registButton.titleLabel.textAlignment = NSTextAlignmentCenter;
  160. // self.loginButton.clipsToBounds = YES;
  161. [self.registButton addTarget:self action:@selector(comitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  162. [self.view addSubview:self.registButton];
  163. /** 布局 */
  164. [self make_layout];
  165. }
  166. -(void)make_layout{
  167. }
  168. #pragma mark - Event response
  169. -(void)backBtnClick{
  170. [self.navigationController popViewControllerAnimated:YES];
  171. }
  172. -(void)getSMSCodeBtnClick:(UIButton *)codeBtn{
  173. // if (self.accountTF.text==nil||self.accountTF.text.length<11||self.accountTF.text.length>11) {
  174. // ALERTSHOW(@"手机号有误,请重新输入");
  175. // }
  176. [self startTime];
  177. }
  178. -(void)startTime{
  179. // GCD类型
  180. __block int timeout=59; //倒计时时间
  181. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  182. dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  183. dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  184. dispatch_source_set_event_handler(_timer, ^{
  185. if(timeout<=0){ //倒计时结束,关闭
  186. dispatch_source_cancel(_timer);
  187. dispatch_async(dispatch_get_main_queue(), ^{
  188. //设置界面的按钮显示 根据自己需求设置(倒计时结束后调用)
  189. //设置按钮的样式
  190. [self.resetPasswordBtn setTitle:@"重新发送" forState:UIControlStateNormal];
  191. //设置不可点击
  192. self.resetPasswordBtn.userInteractionEnabled = YES;
  193. });
  194. }else{
  195. // int minutes = timeout / 60; //这里注释掉了,这个是用来测试多于60秒时计算分钟的。
  196. int seconds = timeout % 60;
  197. NSString *strTime = [NSString stringWithFormat:@"%ds", seconds];
  198. dispatch_async(dispatch_get_main_queue(), ^{
  199. //设置界面的按钮显示 根据自己需求设置
  200. // NSLog(@"____%@",strTime);
  201. [self.resetPasswordBtn setTitle:[NSString stringWithFormat:@"%@秒重发",strTime] forState:UIControlStateNormal];
  202. //设置可点击
  203. self.resetPasswordBtn.userInteractionEnabled = NO;
  204. });
  205. timeout--;
  206. }
  207. });
  208. dispatch_resume(_timer);
  209. //请求验证码
  210. [DataSourceManager getPhoneCodeWithPhone:self.accountTF.text completionBlock:^(NSDictionary *dic) {
  211. ALERTSHOW(@"验证码发送成功");
  212. }];
  213. }
  214. -(void)comitBtnClick:(UIButton *)comitBtn{
  215. [self show];
  216. //提交修改
  217. [DataSourceManager updatePasswordWithUrlPhone:self.accountTF.text code:self.smsCodeTF.text Password1:self.passwordTF.text Password2:self.confirmPasswordTf.text completionBlock:^(NSDictionary *dic) {
  218. ALERTSHOW(@"修改密码成功");
  219. }];
  220. }
  221. #pragma mark------用户名密码校验
  222. -(void)show{
  223. if (self.accountTF.text ==nil||self.accountTF.text.length<11||self.accountTF.text.length >11) {
  224. [self.loginButton setEnabled:NO];
  225. [self.registButton setEnabled:NO];
  226. ALERTSHOW(@"手机号输入有误");
  227. return;
  228. }
  229. if (self.passwordTF.text ==nil||self.passwordTF.text.length>8){
  230. [self.loginButton setEnabled:NO];
  231. [self.registButton setEnabled:NO];
  232. ALERTSHOW(@"密码输入有误");
  233. return;
  234. }
  235. if (![self.passwordTF.text isEqualToString:self.confirmPasswordTf.text]) {
  236. ALERTSHOW(@"两次输入密码不相同");
  237. return;
  238. }
  239. }
  240. #pragma mark - Delegate methods
  241. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  242. return YES;
  243. }
  244. //避免键盘遮挡,登录表单或按钮上移代码
  245. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  246. NSTimeInterval animationDuration = 0.30f;
  247. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  248. [UIView setAnimationDuration:animationDuration];
  249. //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
  250. self.view.frame = CGRectMake(0.0f, -50.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
  251. [UIView commitAnimations];
  252. return YES;
  253. }
  254. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  255. NSTimeInterval animationDuration = 0.30f;
  256. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  257. [UIView setAnimationDuration:animationDuration];
  258. //恢复屏幕
  259. self.view.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
  260. [UIView commitAnimations];
  261. [[UIApplication sharedApplication].keyWindow endEditing:YES];
  262. }
  263. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  264. [textField resignFirstResponder];
  265. return YES;
  266. }
  267. - (void)didReceiveMemoryWarning {
  268. [super didReceiveMemoryWarning];
  269. // Dispose of any resources that can be recreated.
  270. }
  271. /*
  272. #pragma mark - Navigation
  273. // In a storyboard-based application, you will often want to do a little preparation before navigation
  274. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  275. // Get the new view controller using [segue destinationViewController].
  276. // Pass the selected object to the new view controller.
  277. }
  278. */
  279. @end