ModifypasswordViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. //
  2. // ModifypasswordViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/11.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "ModifypasswordViewController.h"
  9. #import "NewRegistCell.h"
  10. #import "NewInterfaceReplacement.h"
  11. #import "HuanXinHelper.h"
  12. @interface ModifypasswordViewController ()<UITableViewDelegate,UITableViewDataSource>
  13. {
  14. NSMutableArray *dataArray;
  15. UITableView *mainTableView;
  16. UITextField *phoneTextField;
  17. UITextField *verificationCodeTextField;
  18. UITextField *passWord1TextField;
  19. UITextField *passWord2TextField;
  20. UIButton *verificationCodeButton;
  21. UIView *view;
  22. UIView *popupsview;
  23. }
  24. @end
  25. @implementation ModifypasswordViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self setNavTitle:@"修改密码"];
  29. [self dataInitialization];
  30. [self loadsView];
  31. // Do any additional setup after loading the view.
  32. }
  33. #pragma mark - 数据初始化
  34. -(void)dataInitialization
  35. {
  36. phoneTextField = nil;
  37. verificationCodeTextField = nil;
  38. verificationCodeButton = nil;
  39. passWord1TextField = nil;
  40. passWord2TextField = nil;
  41. dataArray = NewMutableArrayInit;
  42. for (int i=0; i<4; i++) {
  43. NSDictionary *dataDic = [NSDictionary dictionary];
  44. switch (i) {
  45. case 0:
  46. dataDic = @{@"nameKey":@"手机号",@"imageKey":@"手机号码",@"placeholderKey":@"请输入手机号"};
  47. [dataArray addObject:dataDic];
  48. break;
  49. case 1:
  50. dataDic = @{@"nameKey":@"验证码",@"imageKey":@"短信",@"placeholderKey":@"请输入短信验证码"};
  51. [dataArray addObject:dataDic];
  52. break;
  53. case 2:
  54. dataDic = @{@"nameKey":@"新密码",@"imageKey":@"密码",@"placeholderKey":@"密码不少于6位数"};
  55. [dataArray addObject:dataDic];
  56. break;
  57. case 3:
  58. dataDic = @{@"nameKey":@"确认密码",@"imageKey":@"密码",@"placeholderKey":@"请重新输入新密码"};
  59. [dataArray addObject:dataDic];
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. }
  66. #pragma mark - UI初始化
  67. -(void)loadsView
  68. {
  69. [self.view addSubview:mainTableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, ViewStartY, SCREEN_WIDTH, SCREEN_HEIGHT-ViewStartY) backgroundColor:NewWhiteColor style:0 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  70. mainTableView.separatorStyle = NO; //newtableView隐藏线条
  71. UIView *view;
  72. mainTableView.tableFooterView = view = [NewControlPackage viewInitWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 84) backgroundColor:NewClearColor hidden:NO tag:101 userInteractionEnabled:YES];
  73. UIImageView *lineImge;
  74. [view addSubview:lineImge = [NewControlPackage imageViewInitWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-15, .6) image:nil highlightedImage:nil backgroundColor:NewCellLineColor tag:102 hidden:NO userInteractionEnabled:YES]];
  75. lineImge.hidden = YES;
  76. UIButton *confirm;
  77. [view addSubview:confirm = [NewControlPackage buttonInitWithTitle:@"提交" Frame:CGRectMake(20, 20+lineImge.height, SCREEN_WIDTH-40, 36) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewButtonColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(14) tag:105 target:self action:@selector(touchConfirm) hidden:NO userInteractionEnabled:YES]];
  78. ViewRadius(confirm, 8);
  79. }
  80. #pragma mark - UITableView Delegate
  81. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  82. return 1;
  83. }
  84. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  85. return dataArray.count;
  86. }
  87. - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  88. static NSString *Cell = @"Cell";
  89. NewRegistCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  90. if (cell == nil) {
  91. cell = [[NewRegistCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  92. }
  93. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  94. cell.accessoryType = UITableViewCellAccessoryNone;
  95. cell.image.image = NewImageNamed(dataArray[indexPath.row][@"imageKey"]);
  96. cell.title.text = dataArray[indexPath.row][@"nameKey"];
  97. if (passWord2TextField == nil) {
  98. //获取验证码frame
  99. float vcwidth = 66;
  100. float vcheight = cell.height-20;
  101. float vcx = SCREEN_WIDTH-vcwidth-20;
  102. float vcy = 10;
  103. //输入框frame
  104. float tx = 110;
  105. float ty = 2;
  106. float twidth = SCREEN_WIDTH-tx-20;
  107. float theight = cell.height-2;
  108. UITextField *textField;
  109. [cell.contentView addSubview:textField = [NewControlPackage textFieldInitWithFrame:CGRectMake(tx, ty, twidth, theight) backgroundImage:nil backgroundColor:NewClearColor textColor:NewGrayColor placeholder:dataArray[indexPath.row][@"placeholderKey"] hidden:NO tag:100+(int)indexPath.row font:NewFont(14) textAlignment:NSTextAlignmentLeft clearButtonMode:NO clearsOnBeginEditing:NO adjustsFontSizeToFitWidth:NO secureTextEntry:NO keyboardType:UIKeyboardTypeDefault returnKeyType:UIReturnKeyDefault userInteractionEnabled:YES]];
  110. [textField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
  111. if (indexPath.row == 0) {
  112. cell.areacode.hidden = NO;
  113. }else{
  114. cell.areacode.hidden = YES;
  115. }
  116. if (indexPath.row==0) {
  117. phoneTextField = textField;
  118. //phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
  119. textField.frame = CGRectMake(140, ty, twidth, theight);
  120. [textField setKeyboardType:UIKeyboardTypeNumberPad];
  121. }else if (indexPath.row==1) {
  122. verificationCodeTextField = textField;
  123. [cell.contentView addSubview:verificationCodeButton = [NewControlPackage buttonInitWithTitle:@"获取验证码" Frame:CGRectMake(vcx, vcy, vcwidth, vcheight) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewLightGrayColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(10) tag:99 target:self action:@selector(touchVerificationCode:) hidden:NO userInteractionEnabled:YES]];
  124. ViewRadius(verificationCodeButton, 10);
  125. }else if (indexPath.row==2) {
  126. passWord1TextField = textField;
  127. [passWord1TextField setSecureTextEntry:YES];
  128. }else if (indexPath.row==3) {
  129. passWord2TextField = textField;
  130. [passWord2TextField setSecureTextEntry:YES];
  131. }
  132. }
  133. return cell;
  134. }
  135. #pragma mark - 作字符输入限制
  136. - (void)textFieldEditingChanged:(UITextField *)textField
  137. {
  138. if (textField == phoneTextField) {
  139. if ([textField.text length]>11) {
  140. textField.text=[textField.text substringToIndex:11];//手机号码11位
  141. }
  142. }else if (textField == verificationCodeTextField) {
  143. if ([textField.text length]>6) {
  144. textField.text=[textField.text substringToIndex:6];//验证码6位
  145. }
  146. }else if (textField == passWord1TextField) {
  147. if ([textField.text length]>20) {
  148. textField.text=[textField.text substringToIndex:20];//新密码最多20位
  149. }
  150. }else if (textField == passWord2TextField) {
  151. if ([textField.text length]>20) {
  152. textField.text=[textField.text substringToIndex:20];//新密码最多20位
  153. }
  154. }
  155. }
  156. #pragma mark - 获取验证码
  157. - (void)touchVerificationCode:(UIButton *)sender
  158. {
  159. if (![self verification:@"校验手机号"]) {
  160. return;
  161. }
  162. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  163. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  164. [parameters safeSetObject:phoneTextField.text forKey:@"mobile"];//手机号码
  165. [parameters safeSetObject:@"false" forKey:@"sign"];//是否已注册
  166. [parameters safeSetObject:[UserEntity sharedInstance].type forKey:@"type"];//0-个人 1-单位
  167. [NetworkRequestManager requestGetWithInterfacePrefix:JT_getResetMCode parameters:parameters onSuccess:^(id requestdict) {
  168. [MBProgressHUD hideHUDForView:self.view];
  169. if ([requestdict[@"error"] count] !=0) {
  170. for (NSDictionary *dic in requestdict[@"error"]) {
  171. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  172. }
  173. }else{
  174. [MBProgressHUD showSuccess:@"短信已发送" toView:self.view];
  175. sender.frame = CGRectMake(sender.left, sender.top, 80, sender.height);
  176. [self verificationCode:60 sender:sender];
  177. }
  178. } onFailure:^{
  179. [MBProgressHUD hideHUDForView:self.view];
  180. }];
  181. }
  182. - (void)verificationCode:(NSInteger)code sender:(UIButton *)sender{
  183. NSString *str=[NSString stringWithFormat:@"%d秒后重新发送",(int)code];
  184. [sender setTitle:str forState:UIControlStateNormal];
  185. sender.enabled=NO;
  186. if (code==0) {
  187. sender.enabled=YES;
  188. [sender setTitle:@"获取验证码" forState:UIControlStateNormal];
  189. sender.frame = CGRectMake(sender.left, sender.top, 66, sender.height);
  190. return;
  191. }
  192. code--;
  193. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  194. [self verificationCode:code sender:sender];
  195. });
  196. }
  197. #pragma mark - 提交
  198. - (void)touchConfirm
  199. {
  200. if (![self verification:nil]) {
  201. return;
  202. }
  203. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  204. [parameters safeSetObject:verificationCodeTextField.text forKey:@"resetCode"];//验证码
  205. [parameters safeSetObject:phoneTextField.text forKey:@"mobile"];//手机号码
  206. [parameters safeSetObject:[UserEntity sharedInstance].type forKey:@"type"];//用户类型
  207. [parameters safeSetObject:passWord2TextField.text forKey:@"newPwd"];//新密码
  208. [NetworkRequestManager requestPostWithInterfacePrefix:JT_resetPwd parameters:parameters onSuccess:^(id requestdict) {
  209. [MBProgressHUD hideHUDForView:self.view];
  210. if ([requestdict[@"error"] count] !=0) {
  211. for (NSDictionary *dic in requestdict[@"error"]) {
  212. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  213. }
  214. }else{
  215. [self popview];
  216. }
  217. } onFailure:^{
  218. }];
  219. };
  220. #pragma mark ----- 修改密码成功弹窗-------
  221. - (void)popview{
  222. UITapGestureRecognizer*tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewclick:)];
  223. view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  224. view.userInteractionEnabled = YES;
  225. [view addGestureRecognizer:tapGes];
  226. view.hidden = NO;
  227. view.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5];
  228. [[AppDelegate shareDelegate].window addSubview:view];
  229. popupsview = [[UIView alloc] initWithFrame:CGRectMake(25, 148, SCREEN_WIDTH-50, fitScreenHeight(178))];
  230. popupsview.backgroundColor = NewWhiteColor;
  231. ViewRadius(popupsview, 10);
  232. popupsview.hidden = NO;
  233. [[AppDelegate shareDelegate].window addSubview:popupsview];
  234. UIImageView *image = [UIImageView new];
  235. [image setImage:[UIImage imageNamed:@"成功"]];
  236. [popupsview addSubview:image];
  237. image.sd_layout
  238. .centerXEqualToView(popupsview)
  239. .topSpaceToView(popupsview, 12)
  240. .heightIs(49)
  241. .widthIs(49);
  242. UILabel *prompt = [UILabel new];
  243. prompt.text = @"密码修改成功";
  244. [prompt setSingleLineAutoResizeWithMaxWidth:0];
  245. prompt.font = NewFont(14);
  246. prompt.textColor = [UIColor colorWithString:@"#3C3C3C"];
  247. [popupsview addSubview:prompt];
  248. prompt.sd_layout
  249. .centerXEqualToView(popupsview)
  250. .heightIs(15)
  251. .topSpaceToView(image, 10);
  252. UIButton *loginBT = [UIButton new];
  253. [loginBT setTitle:@"去登录" forState:UIControlStateNormal];
  254. [loginBT setTitleColor:NewWhiteColor forState:UIControlStateNormal];
  255. loginBT.titleLabel.font = NewFont(12);
  256. [loginBT setBackgroundColor:NewButtonColor];
  257. NewTouchUpInside(loginBT, loginBTclick:);
  258. [popupsview addSubview:loginBT];
  259. ViewRadius(loginBT, 8);
  260. loginBT.sd_layout
  261. .centerXEqualToView(popupsview)
  262. .topSpaceToView(prompt, 22)
  263. .heightIs(31)
  264. .widthIs(89);
  265. UIButton *XX = [UIButton new];
  266. [XX setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
  267. NewTouchUpInside(XX, XXclick:);
  268. // [popupsview addSubview:XX];
  269. XX.sd_layout
  270. .rightSpaceToView(popupsview, 10)
  271. .heightIs(fitScreenHeight(10))
  272. .widthIs(fitScreenWidth(10))
  273. .topSpaceToView(popupsview, 10);
  274. }
  275. //点击空白灰色背景
  276. - (void)viewclick:(UITapGestureRecognizer *)tag{
  277. // view.hidden = YES;
  278. // popupsview.hidden = YES;
  279. }
  280. #pragma mark -----去登录按钮-----
  281. - (void)loginBTclick:(UIButton *)sender {
  282. NSLog(@"去登陆");
  283. view.hidden = YES;
  284. popupsview.hidden = YES;
  285. // [[NewInterfaceReplacement sharedInstance] replacementLogin];
  286. //退出云信账号、解绑阿里云推送账号、删除用户单例类以及本地缓存保存的数据
  287. [UserHelper exitLogin];
  288. //退出环信账号
  289. [[HuanXinHelper sharedInstance] exitlogon];
  290. //销毁之前的单利对象
  291. [NewBasicTabbarController objectDealloc];
  292. //给予系统0.5秒清除本地数据
  293. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  294. // 跳转登录界面
  295. NewLoginViewController *startVc = [[NewLoginViewController alloc] init];
  296. startVc.string = @"退出登录";
  297. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:startVc];
  298. [AppDelegate shareDelegate].window.rootViewController = navi;
  299. });
  300. }
  301. #pragma mark -----取消按钮
  302. -(void)XXclick:(UIButton *)sender {
  303. view.hidden = YES;
  304. popupsview.hidden = YES;
  305. }
  306. - (BOOL)verification:(NSString *)status
  307. {
  308. if ([status isEqualToString:@"校验手机号"]) {
  309. if (phoneTextField.text.length <= 0) {
  310. [self.view makeToast:@"请输入手机号码" duration:1.0 position:CSToastPositionCenter];
  311. return NO;
  312. }else if (phoneTextField.text.length < 11){
  313. [self.view makeToast:@"手机号码输入有误" duration:1.0 position:CSToastPositionCenter];
  314. return NO;
  315. }
  316. }else{
  317. if (phoneTextField.text.length <= 0) {
  318. [self.view makeToast:@"手机号码输入有误" duration:1.5 position:CSToastPositionCenter];
  319. return NO;
  320. }
  321. if (verificationCodeTextField.text.length <= 0) {
  322. [self.view makeToast:@"验证码输入有误" duration:1.5 position:CSToastPositionCenter];
  323. return NO;
  324. }
  325. if (passWord1TextField.text.length<6||passWord2TextField.text.length<6) {
  326. [self.view makeToast:@"新密码不能少于6位数" duration:1.5 position:CSToastPositionCenter];
  327. return NO;
  328. }
  329. if (passWord1TextField.text.length <= 0) {
  330. [self.view makeToast:@"新密码输入有误" duration:1.5 position:CSToastPositionCenter];
  331. return NO;
  332. }
  333. if (passWord2TextField.text.length <= 0) {
  334. [self.view makeToast:@"确认新密码输入有误" duration:1.5 position:CSToastPositionCenter];
  335. return NO;
  336. }
  337. if (![passWord1TextField.text isEqualToString:passWord2TextField.text]) {
  338. [self.view makeToast:@"设置密码和确认密码不同" duration:1.5 position:CSToastPositionCenter];
  339. return NO;
  340. }
  341. }
  342. return YES;
  343. }
  344. - (void)didReceiveMemoryWarning {
  345. [super didReceiveMemoryWarning];
  346. // Dispose of any resources that can be recreated.
  347. }
  348. /*
  349. #pragma mark - Navigation
  350. // In a storyboard-based application, you will often want to do a little preparation before navigation
  351. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  352. // Get the new view controller using [segue destinationViewController].
  353. // Pass the selected object to the new view controller.
  354. }
  355. */
  356. @end