| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- //
- // ForgetViewController.m
- // 千模
- //
- // Created by MUMEI on 2018/8/17.
- // Copyright © 2018年 MUMEI. All rights reserved.
- //
- #import "ForgetViewController.h"
- #import "LoginViewController.h"
- #import "NewPwdViewController.h"
- #define SET_WIFI_TIMES 60
- @interface ForgetViewController ()<UITextFieldDelegate>
- {
- UILabel * _dcLab; //倒计时lab
- NSTimer * _timer; //倒计时定时器
- NSString *phoneNum;
- NSString *password;
- NSString * randomCode;
- NSString *code;
- BOOL isGetCode;
- BOOL isRight;
- int dbTimes;
- }
- @property (weak, nonatomic) IBOutlet UITextField *phoneText;
- @property (weak, nonatomic) IBOutlet UITextField *codeText;
- @property (weak, nonatomic) IBOutlet UILabel *getCodeLabel;
- @property (weak, nonatomic) IBOutlet UIImageView *nextImage;
- @end
- @implementation ForgetViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(0, 0, 40, 40);
- [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
- [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
- self.navigationItem.title = @"忘记密码";
- UITapGestureRecognizer *toCode = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toGetCode:)];
- [_getCodeLabel addGestureRecognizer:toCode];
- _getCodeLabel.userInteractionEnabled = YES;
-
- UITapGestureRecognizer *toNext = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toNextVc:)];
- [_nextImage addGestureRecognizer:toNext];
- _nextImage.userInteractionEnabled = YES;
- self.phoneText.keyboardType = UIKeyboardTypeNumberPad;
- self.codeText.keyboardType = UIKeyboardTypeNumberPad;
- // Do any additional setup after loading the view from its nib.
- }
- - (void)viewWillAppear:(BOOL)animated{
- dbTimes = SET_WIFI_TIMES;
- self.codeText.text = @"";
- }
- - (void)toGetCode:(UITapGestureRecognizer*)recognizer{
- if ([Helper valiMobile:self.phoneText.text]) {
- if ([_getCodeLabel.text isEqualToString:@"获取验证码"]) {
- _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
- target:self
- selector:@selector(downTimes:)
- userInfo:nil
- repeats:YES];
- [_timer fire];
- [self getNum];
- }else if ([_getCodeLabel.text isEqualToString:@"重新获取"]){
- _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
- target:self
- selector:@selector(downTimes:)
- userInfo:nil
- repeats:YES];
- [_timer fire];
- [self getNum];
- }
-
- }else{
- [MBProgressHUD showTextHUD:@"请填写正确手机号" inView:self.view hideAfterDelay:1];
- }
- }
- - (void)toNextVc:(UITapGestureRecognizer*)recognizer{
- if (self.phoneText.text.length!=0&&self.codeText.text.length!=0&&[self.codeText.text isEqualToString:randomCode]) {
- NewPwdViewController * newVc = [[NewPwdViewController alloc]init];
- newVc.phone = self.phoneText.text;
- [self.navigationController pushViewController:newVc animated:YES];
- }else{
- [MBProgressHUD showTextHUD:@"请填写正确资料" inView:self.view hideAfterDelay:1];
- }
- }
- -(void)backClick{
- LoginViewController *lVc = [[LoginViewController alloc]init];
- [self.navigationController pushViewController:lVc animated:NO];
- }
- -(void) getNum {
- int a = arc4random() % 100000;
- randomCode = [NSString stringWithFormat:@"%06d", a];
- NSString *str = [NSString stringWithFormat:@"%@/model?action=sendsms&phone=%@&code=%@", PublicUrl, self.phoneText.text, randomCode];
-
- AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
- manager.responseSerializer = [AFHTTPResponseSerializer serializer];
- [manager GET:str
- parameters:nil
- success:^(NSURLSessionDataTask *task, id responseObject) {
- NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- isRight = [result containsString:@"success"];
- NSLog(@"%@", result);
- }
- failure:^(NSURLSessionDataTask *task, NSError *error) {
- NSLog(@"%@", error);
- }];
- }
- - (void)timeInvalidates
- {
- dbTimes = SET_WIFI_TIMES;
- [_timer invalidate];
- _timer = nil;
- }
- - (void)downTimes:(NSTimer*)time
- {
- if (dbTimes > 0) {
- _getCodeLabel.text = [NSString stringWithFormat:@"%ds", dbTimes];
-
- dbTimes--;
- } else {
- _getCodeLabel.text = @"重新获取";
- dbTimes = SET_WIFI_TIMES;
- //调用取消搜索
- [self timeInvalidates];
- [_timer fire];
- //[self stopSearch];
-
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|