RegisterViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. //
  2. // RegisterViewController.m
  3. // 千模
  4. //
  5. // Created by MUMEI on 2018/5/18.
  6. // Copyright © 2018年 MUMEI. All rights reserved.
  7. //
  8. #import "RegisterViewController.h"
  9. #import "LoginViewController.h"
  10. #import "AgreementViewController.h"
  11. #import "privateViewController.h"
  12. #import "AppDelegate.h"
  13. #define SET_WIFI_TIMES 60
  14. @interface RegisterViewController () <UITextFieldDelegate> {
  15. UILabel *_dcLab; //倒计时lab
  16. NSTimer *_timer; //倒计时定时器
  17. UITextField *input;
  18. UIButton *deleteBtn;
  19. UIButton *getCodeBtn;
  20. UILabel *getCodeLabel;
  21. NSString *pkCode;
  22. NSString *phoneNum;
  23. NSString *password;
  24. NSString *repassword;
  25. NSString *nickName;
  26. NSString *code;
  27. BOOL isGetCode;
  28. BOOL canUsePhone;
  29. int dcTimes;
  30. }
  31. @property(weak, nonatomic) IBOutlet UITableView *tableView;
  32. @property(weak, nonatomic) IBOutlet UIButton *registerBtn;
  33. @property(weak, nonatomic) IBOutlet NSLayoutConstraint *tableHeight;
  34. @property(weak, nonatomic) IBOutlet UILabel *agrementLabel;
  35. @property(weak, nonatomic) IBOutlet UILabel *privateLabel;
  36. @end
  37. @implementation RegisterViewController {
  38. NSString *randomCode;
  39. BOOL isRight;
  40. BOOL isSel;
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. if ([UIScreen spt_currentScreenMode] == LESScreenModeIPhoneX) {
  45. self.tableHeight.constant = 400;
  46. }
  47. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. btn.frame = CGRectMake(0, 0, 40, 40);
  49. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  50. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  51. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  52. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  53. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  54. nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  55. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  56. self.navigationItem.title = @"新用户注册";
  57. self.tableView.scrollEnabled = NO;
  58. UITapGestureRecognizer *argeementTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toArgeement:)];
  59. [self.agrementLabel addGestureRecognizer:argeementTap];
  60. self.agrementLabel.userInteractionEnabled = YES;
  61. UITapGestureRecognizer *privateTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toPrivate:)];
  62. [self.privateLabel addGestureRecognizer:privateTap];
  63. self.privateLabel.userInteractionEnabled = YES;
  64. // Do any additional setup after loading the view.
  65. }
  66. - (void)backClick {
  67. LoginViewController *lVc = [[LoginViewController alloc] init];
  68. [self.navigationController pushViewController:lVc animated:NO];
  69. }
  70. - (void)successBack {
  71. LoginViewController *lVc = [[LoginViewController alloc] init];
  72. lVc.registerAccount = phoneNum;
  73. lVc.registerPwd = password;
  74. [self.navigationController pushViewController:lVc animated:NO];
  75. }
  76. - (IBAction)toSel:(UIButton *)sender {
  77. sender.selected = !sender.selected;
  78. isSel = !isSel;
  79. }
  80. - (void)toArgeement:(UITapGestureRecognizer *)recognizer {
  81. AgreementViewController *aVc = [[AgreementViewController alloc] init];
  82. [self.navigationController pushViewController:aVc animated:YES];
  83. }
  84. - (void)toPrivate:(UITapGestureRecognizer *)recognizer {
  85. privateViewController *pVc = [[privateViewController alloc] init];
  86. [self.navigationController pushViewController:pVc animated:YES];
  87. }
  88. - (void)viewWillAppear:(BOOL)animated {
  89. dcTimes = SET_WIFI_TIMES;
  90. }
  91. - (IBAction)toRegister:(id)sender {
  92. // 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]){
  93. // if(isSel){
  94. // [self doRegister];
  95. // }else{
  96. // [MBProgressHUD showTextHUD:@"请勾选阅读协议" inView:self.view hideAfterDelay:1];
  97. // }
  98. //
  99. // }else{
  100. // [MBProgressHUD showInfo:@"请填写正确资料"];
  101. // }
  102. [self check];
  103. }
  104. - (void)check {
  105. if (nickName.length == 0) {
  106. [MBProgressHUD showOnlyText:@"请填写正确昵称" controller:self];
  107. return;
  108. }
  109. if (phoneNum.length == 0) {
  110. [MBProgressHUD showOnlyText:@"请填写正确手机号" controller:self];
  111. return;
  112. }
  113. if (password.length < 6) {
  114. [MBProgressHUD showOnlyText:@"请填写至少6位数密码" controller:self];
  115. return;
  116. }
  117. if (repassword.length < 6) {
  118. [MBProgressHUD showOnlyText:@"请填写至少6位数密码" controller:self];
  119. return;
  120. }
  121. if (code.length == 0) {
  122. [MBProgressHUD showOnlyText:@"请填写正确验证码" controller:self];
  123. return;
  124. }
  125. if (![code isEqualToString:randomCode]) {
  126. [MBProgressHUD showOnlyText:@"请填写正确验证码" controller:self];
  127. return;
  128. }
  129. if (![password isEqualToString:repassword]) {
  130. [MBProgressHUD showOnlyText:@"两次输入密码必须一致" controller:self];
  131. return;
  132. }
  133. if (isSel) {
  134. [self doRegister];
  135. } else {
  136. [MBProgressHUD showTextHUD:@"请勾选阅读协议" inView:self.view hideAfterDelay:1];
  137. }
  138. }
  139. - (void)havePhone {
  140. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  141. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:phoneNum, @"Phone", nil];
  142. [YanCNetWorkManager requestPostWithURLStr:Url_testPhone(PublicUrl) parameters:dic finish:^(id dataDic) {
  143. [MBProgressHUD hideHUDForView:self.view animated:YES];
  144. NSString *issuccess = dataDic[@"msg"];
  145. if ([issuccess isEqualToString:@"success"]) {
  146. NSString *desc = [dataDic objectForKey:@"desc"];
  147. if ([desc isEqualToString:@"未注册"]) {
  148. canUsePhone = YES;
  149. if ([getCodeLabel.text isEqualToString:@"获取验证码"]) {
  150. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  151. target:self
  152. selector:@selector(downTimes:)
  153. userInfo:nil
  154. repeats:YES];
  155. [_timer fire];
  156. [self getNum];
  157. } else if ([getCodeLabel.text isEqualToString:@"重新获取"]) {
  158. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  159. target:self
  160. selector:@selector(downTimes:)
  161. userInfo:nil
  162. repeats:YES];
  163. [_timer fire];
  164. [self getNum];
  165. }
  166. } else if ([desc isEqualToString:@"已注册"]) {
  167. [MBProgressHUD showInfo:@"手机号已注册"];
  168. }
  169. } else {
  170. [MBProgressHUD showInfo:@"请求失败!"];
  171. }
  172. } enError:^(NSError *error) {
  173. [MBProgressHUD hideHUDForView:self.view animated:YES];
  174. }];
  175. }
  176. - (void)doRegister {
  177. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  178. NSDictionary *dic = @{@"mobile": phoneNum, @"pass": password, @"pet": nickName, @"qrcode": pkCode ? pkCode : @""};
  179. [YanCNetWorkManager requestPostWithURLStr:Url_doRegister(PublicUrl) parameters:dic finish:^(id dataDic) {
  180. [MBProgressHUD hideHUDForView:self.view animated:YES];
  181. NSString *issuccess = dataDic[@"msg"];
  182. if ([issuccess isEqualToString:@"success"]) {
  183. [MBProgressHUD showInfo:@"注册成功"];
  184. AppDelegate *app = [[UIApplication sharedApplication] delegate];
  185. app.firstLogin = YES;
  186. [self successBack];
  187. } else if ([dataDic[@"msg"] isEqualToString:@"fail"]) {
  188. NSString *str = dataDic[@"desc"];
  189. [MBProgressHUD showTextHUD:str inView:self.view hideAfterDelay:1];
  190. } else {
  191. [MBProgressHUD showInfo:@"注册失败"];
  192. }
  193. [self.tableView reloadData];
  194. } enError:^(NSError *error) {
  195. [MBProgressHUD hideHUDForView:self.view animated:YES];
  196. }];
  197. }
  198. - (void)getNum {
  199. int a = arc4random() % 100000;
  200. randomCode = [NSString stringWithFormat:@"%06d", a];
  201. // NSString *content = [NSString stringWithFormat:@"【千模科技】验证码%@,快注册,你的人生即将开挂,更快挣钱,更多代言和影视表演机会都在千模。非本人操作,请勿理会。", randomCode];
  202. NSString *str = [NSString stringWithFormat:@"%@/model?action=sendsms&phone=%@&code=%@", PublicUrl, phoneNum, randomCode];
  203. AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  204. manager.responseSerializer = [AFHTTPResponseSerializer serializer];
  205. [manager GET:str
  206. parameters:nil
  207. success:^(NSURLSessionDataTask *task, id responseObject) {
  208. NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  209. isRight = [result containsString:@"success"];
  210. NSLog(@"%@", result);
  211. }
  212. failure:^(NSURLSessionDataTask *task, NSError *error) {
  213. NSLog(@"%@", error);
  214. }];
  215. }
  216. #pragma mark tableViewDelegate
  217. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  218. return 1;
  219. }
  220. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  221. return 0.1;
  222. }
  223. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  224. return 50;
  225. }
  226. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  227. return 6;
  228. }
  229. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  230. static NSString *CellIdentifier = @"Cell";
  231. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  232. if (!cell) {
  233. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
  234. }
  235. input = [[UITextField alloc] initWithFrame:CGRectMake(100, 5, 200, 40)];
  236. input.backgroundColor = [UIColor clearColor];
  237. input.delegate = self;
  238. [input addTarget:self action:@selector(textFieldwithText:) forControlEvents:UIControlEventEditingChanged];
  239. [input setTextAlignment:NSTextAlignmentLeft];
  240. [cell addSubview:input];
  241. deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 20 - 17, 16, 17, 17)];
  242. [deleteBtn setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
  243. [deleteBtn addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];
  244. getCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 20 - 97, 10, 97, 30)];
  245. [getCodeBtn setImage:[UIImage imageNamed:@"yanzhengma"] forState:UIControlStateNormal];
  246. getCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 80, 20)];
  247. getCodeLabel.text = @"获取验证码";
  248. getCodeLabel.textAlignment = NSTextAlignmentCenter;
  249. getCodeLabel.font = [UIFont systemFontOfSize:14];
  250. getCodeLabel.textColor = RGBValueColor(0xfe407f, 1.0);
  251. [getCodeBtn addSubview:getCodeLabel];
  252. [getCodeBtn addTarget:self action:@selector(getCode) forControlEvents:UIControlEventTouchUpInside];
  253. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  254. switch (indexPath.row) {
  255. case 0:
  256. input.tag = 101;
  257. cell.textLabel.text = @"昵称";
  258. // [cell addSubview:deleteBtn];
  259. [input setPlaceholder:@"请输入昵称"];
  260. break;
  261. case 1:
  262. input.tag = 102;
  263. input.keyboardType = UIKeyboardTypeNumberPad;
  264. cell.textLabel.text = @"邀请码";
  265. [input setPlaceholder:@"请输入邀请码(非必填)"];
  266. break;
  267. case 2:
  268. input.tag = 103;
  269. input.keyboardType = UIKeyboardTypeNumberPad;
  270. cell.textLabel.text = @"手机号";
  271. [cell addSubview:deleteBtn];
  272. [input setPlaceholder:@"请输入手机号"];
  273. break;
  274. case 3:
  275. input.tag = 104;
  276. input.secureTextEntry = YES;
  277. cell.textLabel.text = @"设置密码";
  278. [input setPlaceholder:@"请输入正确的密码"];
  279. break;
  280. case 4:
  281. input.tag = 105;
  282. input.secureTextEntry = YES;
  283. cell.textLabel.text = @"重新确认";
  284. [input setPlaceholder:@"再次重复输入密码"];
  285. break;
  286. case 5:
  287. input.tag = 106;
  288. input.keyboardType = UIKeyboardTypeNumberPad;
  289. cell.textLabel.text = @"验证码";
  290. [cell addSubview:getCodeBtn];
  291. [input setPlaceholder:@"请输入手机验证码"];
  292. break;
  293. }
  294. return cell;
  295. }
  296. - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  297. if (theTextField == input) {
  298. [input resignFirstResponder];
  299. }
  300. return YES;
  301. }
  302. - (void)delete {
  303. phoneNum = @"";
  304. [self.tableView reloadData];
  305. }
  306. - (void)getCode {
  307. if ([Helper valiMobile:phoneNum]) {
  308. [self havePhone];
  309. } else {
  310. [MBProgressHUD showInfo:@"请填写正确手机号"];
  311. }
  312. // if (canUsePhone) {
  313. // if([getCodeLabel.text isEqualToString:@"获取验证码"]){
  314. // _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  315. // target:self
  316. // selector:@selector(downTimes:)
  317. // userInfo:nil
  318. // repeats:YES];
  319. // [_timer fire];
  320. // [self getNum];
  321. // }else if ([getCodeLabel.text isEqualToString:@"重新获取"]){
  322. // _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  323. // target:self
  324. // selector:@selector(downTimes:)
  325. // userInfo:nil
  326. // repeats:YES];
  327. // [_timer fire];
  328. // [self getNum];
  329. // }
  330. // }else{
  331. // [MBProgressHUD showTextHUD:@"该手机号已注册" inView:self.view hideAfterDelay:1];
  332. // }
  333. // }else{
  334. // [MBProgressHUD showTextHUD:@"请填写正确手机号" inView:self.view hideAfterDelay:1];
  335. // }
  336. }
  337. - (void)timeInvalidates {
  338. dcTimes = SET_WIFI_TIMES;
  339. [_timer invalidate];
  340. _timer = nil;
  341. }
  342. - (void)downTimes:(NSTimer *)time {
  343. if (dcTimes > 0) {
  344. getCodeLabel.text = [NSString stringWithFormat:@"%ds", dcTimes];
  345. dcTimes--;
  346. } else {
  347. getCodeLabel.text = @"重新获取";
  348. dcTimes = SET_WIFI_TIMES;
  349. //调用取消搜索
  350. [self timeInvalidates];
  351. [_timer fire];
  352. //[self stopSearch];
  353. }
  354. }
  355. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  356. }
  357. - (void)textFieldwithText:(UITextField *)textField {
  358. switch (textField.tag - 100) {
  359. case 1:
  360. nickName = textField.text;
  361. break;
  362. case 2:
  363. pkCode = textField.text;
  364. break;
  365. case 3:
  366. phoneNum = textField.text;
  367. break;
  368. case 4:
  369. password = textField.text;
  370. break;
  371. case 5:
  372. repassword = textField.text;
  373. break;
  374. case 6:
  375. code = textField.text;
  376. break;
  377. default:
  378. break;
  379. }
  380. }
  381. - (void)didReceiveMemoryWarning {
  382. [super didReceiveMemoryWarning];
  383. // Dispose of any resources that can be recreated.
  384. }
  385. @end