RegiestViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. //
  2. // LoginViewController.m
  3. // AICity
  4. //
  5. // Created by 刘伟伟 on 2023/7/13.
  6. // Copyright © 2023 wei.z. All rights reserved.
  7. //
  8. #import "RegiestViewController.h"
  9. #import "CommonBarView.h"
  10. #import "AppDelegate.h"
  11. #import "CTTabbarController.h"
  12. #import "ComonWKWebViewController.h"
  13. @interface RegiestViewController ()<UITextViewDelegate>
  14. @property(nonatomic,strong)UIImageView *loadNetView;
  15. @property(nonatomic,strong)inputView3 *phone;
  16. @property(nonatomic,strong)inputView3 *pass;
  17. @property(nonatomic,strong)inputView3 *pass2;
  18. @property(nonatomic,strong)CommonBarView *customerbar;
  19. @end
  20. @implementation RegiestViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. // [self.view addSubview:self.customerbar];
  25. [self setupUI];
  26. self.view.backgroundColor = rgba(18, 23, 41, 1);
  27. //https://www.apple.com/v/home/bc/images/logos/iphone-tradein/logo_tradein__d1fpktgipvki_large.png
  28. self.loadNetView = [UIImageView new];
  29. [self.loadNetView sd_setImageWithURL:[NSURL URLWithString:@"https://www.apple.com/v/home/bc/images/logos/iphone-tradein/logo_tradein__d1fpktgipvki_large.png"]];
  30. UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closekeyboard)];
  31. [self.view addGestureRecognizer:g];
  32. }
  33. -(void)closekeyboard{
  34. [self.view endEditing:true];
  35. }
  36. -(UIStatusBarStyle)preferredStatusBarStyle{
  37. return UIStatusBarStyleLightContent;
  38. }
  39. -(void)loginAct{
  40. UIButton *selbtn = [self.view viewWithTag:130];
  41. if(!selbtn.isSelected){
  42. [MBProgressHUD showMessage:@"请仔细阅读并同意《用户协议》和《隐私政策》"];
  43. return;
  44. }
  45. // validateContent
  46. if(![self validateContent:self.phone.tf.text]){
  47. [MBProgressHUD showMessage:@"用户名最小长度4字符,最大长度16字符,大小写、数字"];
  48. return;
  49. }
  50. if(![self validateContent:self.pass.tf.text]){
  51. [MBProgressHUD showMessage:@"密码最小长度4字符,最大长度16字符,大小写、数字"];
  52. return;
  53. }
  54. if(![self validateContent:self.pass2.tf.text]){
  55. [MBProgressHUD showMessage:@"密码最小长度4字符,最大长度16字符,大小写、数字"];
  56. return;
  57. }
  58. if(![self.pass.tf.text isEqualToString:self.pass2.tf.text]){
  59. [MBProgressHUD showMessage:@"两次密码输入不一致"];
  60. return;
  61. }
  62. [RequestTool post:@"user/register" params:@{@"account":self.phone.tf.text,@"password":self.pass.tf.text} success:^(id responseObject) {
  63. NSLog(@"user/register-%@",responseObject);
  64. if([responseObject[@"code"] intValue] == 0 || [responseObject[@"code"] intValue] == 200){
  65. [MBProgressHUD showMessage:@"注册成功,请登录"];
  66. [self dismissViewControllerAnimated:YES completion:nil];
  67. }else{
  68. [MBProgressHUD showMessage:responseObject[@"msg"]];
  69. }
  70. } failure:^(NSError *error) {
  71. NSLog(@"%@",error);
  72. }];
  73. }
  74. -(void)setupUI{
  75. [self.view addSubview:self.customerbar];
  76. UILabel *n = [UILabel new];
  77. // n.text = @"注册登录";
  78. n.font = [UIFont systemFontOfSize:24];
  79. n.textColor = rgba(255, 255, 255, 1);
  80. [self.view addSubview:n];
  81. [n mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(self.view).offset(40);
  83. make.top.equalTo(self.view).offset(152);
  84. }];
  85. inputView3 *phone = [inputView3 new];
  86. self.phone = phone;
  87. phone.type = 0;
  88. [self.view addSubview:phone];
  89. [phone mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.right.equalTo(self.view);
  91. make.top.equalTo(n.mas_bottom).offset(96);
  92. make.height.mas_equalTo(@35);
  93. }];
  94. inputView3 *pass = [inputView3 new];
  95. self.pass = pass;
  96. pass.type = 1;
  97. pass.tapBlock = ^{
  98. };
  99. [self.view addSubview:pass];
  100. [pass mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.right.equalTo(self.view);
  102. make.top.equalTo(phone.mas_bottom).offset(37);
  103. make.height.mas_equalTo(@35);
  104. }];
  105. inputView3 *pass2 = [inputView3 new];
  106. self.pass2 = pass2;
  107. pass2.type = 2;
  108. pass2.tapBlock = ^{
  109. };
  110. [self.view addSubview:pass2];
  111. [pass2 mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.right.equalTo(self.view);
  113. make.top.equalTo(pass.mas_bottom).offset(37);
  114. make.height.mas_equalTo(@35);
  115. }];
  116. // UILabel *lab = [UILabel new];
  117. // lab.text = @"还没有账号,点击注册?";
  118. // lab.textColor = rgba(255, 255, 255, 0.4);
  119. // lab.font = [UIFont systemFontOfSize:12];
  120. // [self.view addSubview:lab];
  121. // lab.hidden = true;
  122. // [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  123. // make.right.equalTo(self.view).offset(-40);
  124. // make.top.equalTo(pass.mas_bottom).offset(8);
  125. // }];
  126. UIButton *btn = [UIButton new];
  127. [btn setBackgroundImage:[UIImage imageNamed:@"Rectangle 19465"] forState:UIControlStateNormal];
  128. [btn setTitle:@"注册" forState:UIControlStateNormal];
  129. [btn setTitleColor:rgba(18, 23, 41, 0.5) forState:UIControlStateNormal];
  130. btn.titleLabel.font = [UIFont systemFontOfSize:16];
  131. [btn addTarget:self action:@selector(loginAct) forControlEvents:UIControlEventTouchUpInside];
  132. [self.view addSubview:btn];
  133. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.equalTo(self.view).offset(40);
  135. make.right.equalTo(self.view).offset(-40);
  136. make.height.mas_equalTo(@48);
  137. make.top.equalTo(pass2.mas_bottom).offset(56);
  138. }];
  139. NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:@"已仔细阅读并同意"];
  140. [attributedStr addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.4) range:NSMakeRange(0, attributedStr.length)];
  141. [attributedStr addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr.length)];
  142. NSMutableAttributedString *attributedStr2 = [[NSMutableAttributedString alloc] initWithString:@"《用户协议》"];
  143. [attributedStr2 addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 1) range:NSMakeRange(0, attributedStr2.length)];
  144. [attributedStr2 addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr2.length)];
  145. NSURL *baiduURL = [NSURL URLWithString:@"privateProtocal://www.com"];
  146. [attributedStr2 addAttribute:NSLinkAttributeName value:baiduURL range:NSMakeRange(0, attributedStr2.length)];
  147. NSMutableAttributedString *attributedStr3 = [[NSMutableAttributedString alloc] initWithString:@"和"];
  148. [attributedStr3 addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.4) range:NSMakeRange(0, attributedStr3.length)];
  149. [attributedStr3 addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr3.length)];
  150. NSMutableAttributedString *attributedStr4 = [[NSMutableAttributedString alloc] initWithString:@"《隐私政策》"];
  151. [attributedStr4 addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 1) range:NSMakeRange(0, attributedStr4.length)];
  152. [attributedStr4 addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr4.length)];
  153. NSURL *baiduURL2 = [NSURL URLWithString:@"privacyPolicy://www.com"];
  154. [attributedStr4 addAttribute:NSLinkAttributeName value:baiduURL2 range:NSMakeRange(0, attributedStr4.length)];
  155. [attributedStr appendAttributedString:attributedStr2];
  156. [attributedStr appendAttributedString:attributedStr3];
  157. [attributedStr appendAttributedString:attributedStr4];
  158. UITextView *lab2 = [UITextView new];
  159. lab2.backgroundColor = [UIColor clearColor];
  160. lab2.attributedText = attributedStr;
  161. lab2.textAlignment = NSTextAlignmentCenter;
  162. lab2.linkTextAttributes = @{NSForegroundColorAttributeName:rgba(255, 255, 255, 1)};
  163. lab2.delegate = self;
  164. lab2.editable = NO;
  165. lab2.scrollEnabled = NO;
  166. // lab2.selectable = NO;
  167. // lab.textColor = rgba(255, 255, 255, 0.4);
  168. // lab.font = [UIFont systemFontOfSize:12];
  169. [self.view addSubview:lab2];
  170. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.centerX.equalTo(self.view).offset(7);
  172. make.top.equalTo(btn.mas_bottom).offset(12);
  173. make.width.mas_equalTo(@270);
  174. // make.height.mas_equalTo(@15);
  175. }];
  176. UIButton *selbtn = [UIButton new];
  177. selbtn.tag = 130;
  178. [selbtn setBackgroundImage:[UIImage imageNamed:@"login_cirle"] forState:UIControlStateNormal];
  179. [selbtn setBackgroundImage:[UIImage imageNamed:@"login_chick"] forState:UIControlStateSelected];
  180. [self.view addSubview:selbtn];
  181. [selbtn addTarget:self action:@selector(changeSelState) forControlEvents:UIControlEventTouchUpInside];
  182. [selbtn mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.right.equalTo(lab2.mas_left).offset(-2);
  184. make.size.mas_equalTo(CGSizeMake(12, 12));
  185. make.centerY.equalTo(lab2);
  186. }];
  187. UIButton *selbtn2 = [UIButton new];
  188. [self.view addSubview:selbtn2];
  189. [selbtn2 addTarget:self action:@selector(changeSelState) forControlEvents:UIControlEventTouchUpInside];
  190. [selbtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
  191. make.size.mas_equalTo(CGSizeMake(30, 30));
  192. make.center.equalTo(selbtn);
  193. }];
  194. }
  195. - (BOOL)validateContent:(NSString *) textString
  196. {
  197. NSString* number=@"^[a-zA-Z0-9]{4,16}$";
  198. NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",number];
  199. return [numberPre evaluateWithObject:textString];
  200. }
  201. -(void)changeSelState{
  202. UIButton *selbtn = [self.view viewWithTag:130];
  203. selbtn.selected = !selbtn.isSelected;
  204. }
  205. -(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(nonnull NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction
  206. {
  207. if ([[URL scheme] isEqualToString:@"privateProtocal"]) {
  208. NSLog(@"看天用户协议");
  209. //用户协议
  210. ComonWKWebViewController *vc =[[ComonWKWebViewController alloc] init];
  211. vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
  212. vc.title = @"用户协议";
  213. vc.url = @"https://backend.jsnoopyay.com/user_agreement.html";
  214. [self presentViewController:vc animated:YES completion:nil];
  215. return NO;
  216. } else if ([[URL scheme] isEqualToString:@"privacyPolicy"]) {
  217. NSLog(@"隐私协议");
  218. //隐私协议
  219. ComonWKWebViewController *vc =[[ComonWKWebViewController alloc] init];
  220. vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
  221. vc.title = @"隐私协议";
  222. vc.url = @"https://backend.jsnoopyay.com/private.html";
  223. [self presentViewController:vc animated:YES completion:nil];
  224. return NO;
  225. }
  226. return YES;
  227. }
  228. //-(CommonBarView *)customerbar{
  229. // if(!_customerbar){
  230. // CGFloat h=0;
  231. // if(@available(iOS 13.0, *)){
  232. // UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
  233. // CGRect f=sc.statusBarFrame;
  234. // h=f.size.height;
  235. // }else{
  236. // h=[UIApplication sharedApplication].statusBarFrame.size.height;
  237. // }
  238. // if(h>=40){
  239. // h=30;
  240. // }
  241. // _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
  242. // _customerbar.bgView.backgroundColor = [UIColor clearColor];
  243. // _customerbar.label.text=@"手机号登录";
  244. // _customerbar.bgView.alpha = 1;
  245. // _customerbar.label.textColor = rgba(255, 255, 255, 1);
  246. // }
  247. // return _customerbar;
  248. //}
  249. -(void)backAction{
  250. [self dismissViewControllerAnimated:true completion:nil];
  251. }
  252. -(CommonBarView *)customerbar{
  253. if(!_customerbar){
  254. CGFloat h=0;
  255. if(@available(iOS 13.0, *)){
  256. UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
  257. CGRect f=sc.statusBarFrame;
  258. h=f.size.height;
  259. }else{
  260. h=[UIApplication sharedApplication].statusBarFrame.size.height;
  261. }
  262. if(h>=40){
  263. h=30;
  264. }
  265. _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
  266. _customerbar.bgView.backgroundColor = [UIColor clearColor];
  267. _customerbar.label.text=@"注册";
  268. _customerbar.bgView.alpha = 1;
  269. _customerbar.label.textColor = rgba(255, 255, 255, 1);
  270. // _customerbar.leftButton.hidden = true;
  271. // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back"] forState:UIControlStateNormal];
  272. // [_customerbar.rightButton setImage:[UIImage imageNamed:@"Frame 9411"] forState:UIControlStateNormal];
  273. // [_customerbar.rightButton setTitle:@"编辑" forState:UIControlStateNormal];
  274. // [_customerbar.rightButton setImage:[self imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected];
  275. // [_customerbar.rightButton setTitle:@"取消" forState:UIControlStateSelected];
  276. // [_customerbar.rightButton setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
  277. // _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
  278. [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  279. // [_customerbar.rightButton addTarget:self action:@selector(changeSelState:) forControlEvents:UIControlEventTouchUpInside];
  280. // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
  281. // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  282. // make.centerY.equalTo(_customerbar.leftButton);
  283. // make.right.equalTo(_customerbar).offset(-15);
  284. // make.size.mas_equalTo(CGSizeMake(23, 23));
  285. // }];
  286. }
  287. return _customerbar;
  288. }
  289. @end
  290. @interface inputView3()
  291. @property(nonatomic,strong)NSTimer *mytime;
  292. @property(nonatomic,assign)int second;
  293. @end
  294. @implementation inputView3
  295. - (instancetype)init
  296. {
  297. self = [super init];
  298. if (self) {
  299. self.second = 60;
  300. }
  301. return self;
  302. }
  303. //0手机号 1密码
  304. -(void)setType:(int)type{
  305. _type = type;
  306. [self initView:type];
  307. }
  308. - (void)initView:(int)type{
  309. UIImageView *iv = [UIImageView new];
  310. if(type == 0){
  311. iv.image = [UIImage imageNamed:@"Casino22"];
  312. }else{
  313. iv.image = [UIImage imageNamed:@"Casino2"];
  314. }
  315. [self addSubview:iv];
  316. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  317. make.left.equalTo(self).offset(40);
  318. make.top.equalTo(self);
  319. make.size.mas_equalTo(CGSizeMake(20, 20));
  320. }];
  321. UITextField *tf =[UITextField new];
  322. self.tf = tf;
  323. NSString *str=@"";
  324. if(type == 0){
  325. str=@"用户名";
  326. }else if(type == 1){
  327. str=@"请输入密码";
  328. tf.secureTextEntry = YES;
  329. }else if(type == 2){
  330. str=@"确认密码";
  331. tf.secureTextEntry = YES;
  332. }
  333. NSMutableAttributedString *attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:str];
  334. [attributedPlaceholder addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.2) range:NSMakeRange(0, attributedPlaceholder.length)];
  335. [attributedPlaceholder addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:14.0] range:NSMakeRange(0, attributedPlaceholder.length)];
  336. tf.attributedPlaceholder = attributedPlaceholder;
  337. tf.textColor = [UIColor whiteColor];
  338. tf.font = [UIFont italicSystemFontOfSize:14.0];
  339. [tf addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  340. [self addSubview:tf];
  341. [tf mas_makeConstraints:^(MASConstraintMaker *make) {
  342. make.left.equalTo(iv.mas_right).offset(12);
  343. make.centerY.equalTo(iv);
  344. make.size.mas_equalTo(CGSizeMake(200, 20));
  345. }];
  346. // if(type == 0){
  347. // UILabel *lab = [UILabel new];
  348. // lab.text = @"+86";
  349. // lab.textColor = rgba(255, 255, 255, 0.4);
  350. // lab.font = [UIFont systemFontOfSize:14];
  351. // [self addSubview:lab];
  352. // [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  353. // make.left.equalTo(iv.mas_right).offset(12);
  354. // make.centerY.equalTo(iv);
  355. // }];
  356. //
  357. // [tf mas_makeConstraints:^(MASConstraintMaker *make) {
  358. // make.left.equalTo(lab.mas_right).offset(8);
  359. // make.centerY.equalTo(iv);
  360. // make.size.mas_equalTo(CGSizeMake(200, 20));
  361. // }];
  362. // }else{
  363. // [tf mas_makeConstraints:^(MASConstraintMaker *make) {
  364. // make.left.equalTo(iv.mas_right).offset(12);
  365. // make.centerY.equalTo(iv);
  366. // make.size.mas_equalTo(CGSizeMake(200, 20));
  367. // }];
  368. //
  369. // UIButton *showP =[UIButton new];
  370. // [showP setTitle:@"获取验证码" forState:UIControlStateNormal];
  371. // [showP setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal];
  372. // showP.titleLabel.font = [UIFont systemFontOfSize:14];
  373. // [showP addTarget:self action:@selector(getCode:) forControlEvents:UIControlEventTouchUpInside];
  374. // [self addSubview:showP];
  375. // [showP mas_makeConstraints:^(MASConstraintMaker *make) {
  376. // make.right.equalTo(self).offset(-40);
  377. // make.centerY.equalTo(iv);
  378. // make.size.mas_equalTo(CGSizeMake(80, 20));
  379. // }];
  380. // }
  381. UIView *line = [UIView new];
  382. line.backgroundColor = rgba(255, 255, 255, 0.2);
  383. [self addSubview:line];
  384. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  385. make.left.equalTo(iv);
  386. make.right.equalTo(self).offset(-40);
  387. make.bottom.equalTo(self);
  388. make.height.mas_equalTo(@1);
  389. }];
  390. }
  391. - (void)textFieldDidChange:(UITextField *)textField
  392. {
  393. if(textField.text.length>16){
  394. textField.text = [textField.text substringToIndex:16];
  395. }
  396. }
  397. //-(void)getCode:(UIButton *)showP{
  398. // if(self.mytime){
  399. // return;
  400. // }
  401. // self.mytime = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
  402. // [showP setTitle:[NSString stringWithFormat:@"%ds",self.second] forState:UIControlStateNormal];
  403. // self.second -=1;
  404. // if(self.second <= -1){
  405. // [self.mytime invalidate];
  406. // self.mytime = nil;
  407. // self.second = 60;
  408. // [showP setTitle:@"获取验证码" forState:UIControlStateNormal];
  409. // }
  410. // }];
  411. //
  412. // if(self.tapBlock){
  413. // self.tapBlock();
  414. // }
  415. //}
  416. @end