| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- //
- // RegisterViewController.m
- // 千模
- //
- // Created by MUMEI on 2018/5/18.
- // Copyright © 2018年 MUMEI. All rights reserved.
- //
- #import "RegisterViewController.h"
- #import "LoginViewController.h"
- #import "AgreementViewController.h"
- #import "privateViewController.h"
- #import "AppDelegate.h"
- #define SET_WIFI_TIMES 60
- @interface RegisterViewController () <UITextFieldDelegate> {
- UILabel *_dcLab; //倒计时lab
- NSTimer *_timer; //倒计时定时器
- UITextField *input;
- UIButton *deleteBtn;
- UIButton *getCodeBtn;
- UILabel *getCodeLabel;
- NSString *pkCode;
- NSString *phoneNum;
- NSString *password;
- NSString *repassword;
- NSString *nickName;
- NSString *code;
- BOOL isGetCode;
- BOOL canUsePhone;
- int dcTimes;
- }
- @property(weak, nonatomic) IBOutlet UITableView *tableView;
- @property(weak, nonatomic) IBOutlet UIButton *registerBtn;
- @property(weak, nonatomic) IBOutlet NSLayoutConstraint *tableHeight;
- @property(weak, nonatomic) IBOutlet UILabel *agrementLabel;
- @property(weak, nonatomic) IBOutlet UILabel *privateLabel;
- @end
- @implementation RegisterViewController {
- NSString *randomCode;
- BOOL isRight;
- BOOL isSel;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- if ([UIScreen spt_currentScreenMode] == LESScreenModeIPhoneX) {
- self.tableHeight.constant = 400;
- }
- 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 = @"新用户注册";
- self.tableView.scrollEnabled = NO;
- UITapGestureRecognizer *argeementTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toArgeement:)];
- [self.agrementLabel addGestureRecognizer:argeementTap];
- self.agrementLabel.userInteractionEnabled = YES;
- UITapGestureRecognizer *privateTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toPrivate:)];
- [self.privateLabel addGestureRecognizer:privateTap];
- self.privateLabel.userInteractionEnabled = YES;
- // Do any additional setup after loading the view.
- }
- - (void)backClick {
- LoginViewController *lVc = [[LoginViewController alloc] init];
- [self.navigationController pushViewController:lVc animated:NO];
- }
- - (void)successBack {
- LoginViewController *lVc = [[LoginViewController alloc] init];
- lVc.registerAccount = phoneNum;
- lVc.registerPwd = password;
- [self.navigationController pushViewController:lVc animated:NO];
- }
- - (IBAction)toSel:(UIButton *)sender {
- sender.selected = !sender.selected;
- isSel = !isSel;
- }
- - (void)toArgeement:(UITapGestureRecognizer *)recognizer {
- AgreementViewController *aVc = [[AgreementViewController alloc] init];
- [self.navigationController pushViewController:aVc animated:YES];
- }
- - (void)toPrivate:(UITapGestureRecognizer *)recognizer {
- privateViewController *pVc = [[privateViewController alloc] init];
- [self.navigationController pushViewController:pVc animated:YES];
- }
- - (void)viewWillAppear:(BOOL)animated {
- dcTimes = SET_WIFI_TIMES;
- }
- - (IBAction)toRegister:(id)sender {
- // if([password isEqualToString:repassword]&&password.length!=0&&repassword.length!=0&&nickName.length!=0&&phoneNum.length!=0&&pkCode.length!=0&&code.length!=0&&[code isEqualToString:randomCode]){
- // if(isSel){
- // [self doRegister];
- // }else{
- // [MBProgressHUD showTextHUD:@"请勾选阅读协议" inView:self.view hideAfterDelay:1];
- // }
- //
- // }else{
- // [MBProgressHUD showInfo:@"请填写正确资料"];
- // }
- [self check];
- }
- - (void)check {
- if (nickName.length == 0) {
- [MBProgressHUD showOnlyText:@"请填写正确昵称" controller:self];
- return;
- }
- if (phoneNum.length == 0) {
- [MBProgressHUD showOnlyText:@"请填写正确手机号" controller:self];
- return;
- }
- if (password.length < 6) {
- [MBProgressHUD showOnlyText:@"请填写至少6位数密码" controller:self];
- return;
- }
- if (repassword.length < 6) {
- [MBProgressHUD showOnlyText:@"请填写至少6位数密码" controller:self];
- return;
- }
- if (code.length == 0) {
- [MBProgressHUD showOnlyText:@"请填写正确验证码" controller:self];
- return;
- }
- if (![code isEqualToString:randomCode]) {
- [MBProgressHUD showOnlyText:@"请填写正确验证码" controller:self];
- return;
- }
- if (![password isEqualToString:repassword]) {
- [MBProgressHUD showOnlyText:@"两次输入密码必须一致" controller:self];
- return;
- }
- if (isSel) {
- [self doRegister];
- } else {
- [MBProgressHUD showTextHUD:@"请勾选阅读协议" inView:self.view hideAfterDelay:1];
- }
- }
- - (void)havePhone {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:phoneNum, @"Phone", nil];
- [YanCNetWorkManager requestPostWithURLStr:Url_testPhone(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
- NSString *desc = [dataDic objectForKey:@"desc"];
- if ([desc isEqualToString:@"未注册"]) {
- canUsePhone = YES;
- 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 if ([desc isEqualToString:@"已注册"]) {
- [MBProgressHUD showInfo:@"手机号已注册"];
- }
- } else {
- [MBProgressHUD showInfo:@"请求失败!"];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- - (void)doRegister {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- NSDictionary *dic = @{@"mobile": phoneNum, @"pass": password, @"pet": nickName, @"qrcode": pkCode ? pkCode : @""};
- [YanCNetWorkManager requestPostWithURLStr:Url_doRegister(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
- [MBProgressHUD showInfo:@"注册成功"];
- AppDelegate *app = [[UIApplication sharedApplication] delegate];
- app.firstLogin = YES;
- [self successBack];
- } else if ([dataDic[@"msg"] isEqualToString:@"fail"]) {
- NSString *str = dataDic[@"desc"];
- [MBProgressHUD showTextHUD:str inView:self.view hideAfterDelay:1];
- } else {
- [MBProgressHUD showInfo:@"注册失败"];
- }
- [self.tableView reloadData];
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- - (void)getNum {
- int a = arc4random() % 100000;
- randomCode = [NSString stringWithFormat:@"%06d", a];
- // NSString *content = [NSString stringWithFormat:@"【千模科技】验证码%@,快注册,你的人生即将开挂,更快挣钱,更多代言和影视表演机会都在千模。非本人操作,请勿理会。", randomCode];
- NSString *str = [NSString stringWithFormat:@"%@/model?action=sendsms&phone=%@&code=%@", PublicUrl, phoneNum, 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);
- }];
- }
- #pragma mark tableViewDelegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 0.1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 50;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 6;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
- }
- input = [[UITextField alloc] initWithFrame:CGRectMake(100, 5, 200, 40)];
- input.backgroundColor = [UIColor clearColor];
- input.delegate = self;
- [input addTarget:self action:@selector(textFieldwithText:) forControlEvents:UIControlEventEditingChanged];
- [input setTextAlignment:NSTextAlignmentLeft];
- [cell addSubview:input];
- deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 20 - 17, 16, 17, 17)];
- [deleteBtn setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
- [deleteBtn addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];
- getCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 20 - 97, 10, 97, 30)];
- [getCodeBtn setImage:[UIImage imageNamed:@"yanzhengma"] forState:UIControlStateNormal];
- getCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 80, 20)];
- getCodeLabel.text = @"获取验证码";
- getCodeLabel.textAlignment = NSTextAlignmentCenter;
- getCodeLabel.font = [UIFont systemFontOfSize:14];
- getCodeLabel.textColor = RGBValueColor(0xfe407f, 1.0);
- [getCodeBtn addSubview:getCodeLabel];
- [getCodeBtn addTarget:self action:@selector(getCode) forControlEvents:UIControlEventTouchUpInside];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- switch (indexPath.row) {
- case 0:
- input.tag = 101;
- cell.textLabel.text = @"昵称";
- // [cell addSubview:deleteBtn];
- [input setPlaceholder:@"请输入昵称"];
- break;
- case 1:
- input.tag = 102;
- input.keyboardType = UIKeyboardTypeNumberPad;
- cell.textLabel.text = @"邀请码";
- [input setPlaceholder:@"请输入邀请码(非必填)"];
- break;
- case 2:
- input.tag = 103;
- input.keyboardType = UIKeyboardTypeNumberPad;
- cell.textLabel.text = @"手机号";
- [cell addSubview:deleteBtn];
- [input setPlaceholder:@"请输入手机号"];
- break;
- case 3:
- input.tag = 104;
- input.secureTextEntry = YES;
- cell.textLabel.text = @"设置密码";
- [input setPlaceholder:@"请输入正确的密码"];
- break;
- case 4:
- input.tag = 105;
- input.secureTextEntry = YES;
- cell.textLabel.text = @"重新确认";
- [input setPlaceholder:@"再次重复输入密码"];
- break;
- case 5:
- input.tag = 106;
- input.keyboardType = UIKeyboardTypeNumberPad;
- cell.textLabel.text = @"验证码";
- [cell addSubview:getCodeBtn];
- [input setPlaceholder:@"请输入手机验证码"];
- break;
- }
- return cell;
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
- if (theTextField == input) {
- [input resignFirstResponder];
- }
- return YES;
- }
- - (void)delete {
- phoneNum = @"";
- [self.tableView reloadData];
- }
- - (void)getCode {
- if ([Helper valiMobile:phoneNum]) {
- [self havePhone];
- } else {
- [MBProgressHUD showInfo:@"请填写正确手机号"];
- }
- // if (canUsePhone) {
- // 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];
- // }
- // }else{
- // [MBProgressHUD showTextHUD:@"请填写正确手机号" inView:self.view hideAfterDelay:1];
- // }
- }
- - (void)timeInvalidates {
- dcTimes = SET_WIFI_TIMES;
- [_timer invalidate];
- _timer = nil;
- }
- - (void)downTimes:(NSTimer *)time {
- if (dcTimes > 0) {
- getCodeLabel.text = [NSString stringWithFormat:@"%ds", dcTimes];
- dcTimes--;
- } else {
- getCodeLabel.text = @"重新获取";
- dcTimes = SET_WIFI_TIMES;
- //调用取消搜索
- [self timeInvalidates];
- [_timer fire];
- //[self stopSearch];
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- }
- - (void)textFieldwithText:(UITextField *)textField {
- switch (textField.tag - 100) {
- case 1:
- nickName = textField.text;
- break;
- case 2:
- pkCode = textField.text;
- break;
- case 3:
- phoneNum = textField.text;
- break;
- case 4:
- password = textField.text;
- break;
- case 5:
- repassword = textField.text;
- break;
- case 6:
- code = textField.text;
- break;
- default:
- break;
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|