// // LoginViewController.m // AICity // // Created by 刘伟伟 on 2023/7/13. // Copyright © 2023 wei.z. All rights reserved. // #import "RegiestViewController.h" #import "CommonBarView.h" #import "AppDelegate.h" #import "CTTabbarController.h" #import "ComonWKWebViewController.h" @interface RegiestViewController () @property(nonatomic,strong)UIImageView *loadNetView; @property(nonatomic,strong)inputView3 *phone; @property(nonatomic,strong)inputView3 *pass; @property(nonatomic,strong)inputView3 *pass2; @property(nonatomic,strong)CommonBarView *customerbar; @end @implementation RegiestViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // [self.view addSubview:self.customerbar]; [self setupUI]; self.view.backgroundColor = rgba(18, 23, 41, 1); //https://www.apple.com/v/home/bc/images/logos/iphone-tradein/logo_tradein__d1fpktgipvki_large.png self.loadNetView = [UIImageView new]; [self.loadNetView sd_setImageWithURL:[NSURL URLWithString:@"https://www.apple.com/v/home/bc/images/logos/iphone-tradein/logo_tradein__d1fpktgipvki_large.png"]]; UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closekeyboard)]; [self.view addGestureRecognizer:g]; } -(void)closekeyboard{ [self.view endEditing:true]; } -(UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; } -(void)loginAct{ UIButton *selbtn = [self.view viewWithTag:130]; if(!selbtn.isSelected){ [MBProgressHUD showMessage:@"请仔细阅读并同意《用户协议》和《隐私政策》"]; return; } // validateContent if(![self validateContent:self.phone.tf.text]){ [MBProgressHUD showMessage:@"用户名最小长度4字符,最大长度16字符,大小写、数字"]; return; } if(![self validateContent:self.pass.tf.text]){ [MBProgressHUD showMessage:@"密码最小长度4字符,最大长度16字符,大小写、数字"]; return; } if(![self validateContent:self.pass2.tf.text]){ [MBProgressHUD showMessage:@"密码最小长度4字符,最大长度16字符,大小写、数字"]; return; } if(![self.pass.tf.text isEqualToString:self.pass2.tf.text]){ [MBProgressHUD showMessage:@"两次密码输入不一致"]; return; } [RequestTool post:@"user/register" params:@{@"account":self.phone.tf.text,@"password":self.pass.tf.text} success:^(id responseObject) { NSLog(@"user/register-%@",responseObject); if([responseObject[@"code"] intValue] == 0 || [responseObject[@"code"] intValue] == 200){ [MBProgressHUD showMessage:@"注册成功,请登录"]; [self dismissViewControllerAnimated:YES completion:nil]; }else{ [MBProgressHUD showMessage:responseObject[@"msg"]]; } } failure:^(NSError *error) { NSLog(@"%@",error); }]; } -(void)setupUI{ [self.view addSubview:self.customerbar]; UILabel *n = [UILabel new]; // n.text = @"注册登录"; n.font = [UIFont systemFontOfSize:24]; n.textColor = rgba(255, 255, 255, 1); [self.view addSubview:n]; [n mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(40); make.top.equalTo(self.view).offset(152); }]; inputView3 *phone = [inputView3 new]; self.phone = phone; phone.type = 0; [self.view addSubview:phone]; [phone mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.equalTo(n.mas_bottom).offset(96); make.height.mas_equalTo(@35); }]; inputView3 *pass = [inputView3 new]; self.pass = pass; pass.type = 1; pass.tapBlock = ^{ }; [self.view addSubview:pass]; [pass mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.equalTo(phone.mas_bottom).offset(37); make.height.mas_equalTo(@35); }]; inputView3 *pass2 = [inputView3 new]; self.pass2 = pass2; pass2.type = 2; pass2.tapBlock = ^{ }; [self.view addSubview:pass2]; [pass2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.equalTo(pass.mas_bottom).offset(37); make.height.mas_equalTo(@35); }]; // UILabel *lab = [UILabel new]; // lab.text = @"还没有账号,点击注册?"; // lab.textColor = rgba(255, 255, 255, 0.4); // lab.font = [UIFont systemFontOfSize:12]; // [self.view addSubview:lab]; // lab.hidden = true; // [lab mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.equalTo(self.view).offset(-40); // make.top.equalTo(pass.mas_bottom).offset(8); // }]; UIButton *btn = [UIButton new]; [btn setBackgroundImage:[UIImage imageNamed:@"Rectangle 19465"] forState:UIControlStateNormal]; [btn setTitle:@"注册" forState:UIControlStateNormal]; [btn setTitleColor:rgba(18, 23, 41, 0.5) forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:16]; [btn addTarget:self action:@selector(loginAct) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(40); make.right.equalTo(self.view).offset(-40); make.height.mas_equalTo(@48); make.top.equalTo(pass2.mas_bottom).offset(56); }]; NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:@"已仔细阅读并同意"]; [attributedStr addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.4) range:NSMakeRange(0, attributedStr.length)]; [attributedStr addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr.length)]; NSMutableAttributedString *attributedStr2 = [[NSMutableAttributedString alloc] initWithString:@"《用户协议》"]; [attributedStr2 addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 1) range:NSMakeRange(0, attributedStr2.length)]; [attributedStr2 addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr2.length)]; NSURL *baiduURL = [NSURL URLWithString:@"privateProtocal://www.com"]; [attributedStr2 addAttribute:NSLinkAttributeName value:baiduURL range:NSMakeRange(0, attributedStr2.length)]; NSMutableAttributedString *attributedStr3 = [[NSMutableAttributedString alloc] initWithString:@"和"]; [attributedStr3 addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.4) range:NSMakeRange(0, attributedStr3.length)]; [attributedStr3 addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr3.length)]; NSMutableAttributedString *attributedStr4 = [[NSMutableAttributedString alloc] initWithString:@"《隐私政策》"]; [attributedStr4 addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 1) range:NSMakeRange(0, attributedStr4.length)]; [attributedStr4 addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:12.0] range:NSMakeRange(0, attributedStr4.length)]; NSURL *baiduURL2 = [NSURL URLWithString:@"privacyPolicy://www.com"]; [attributedStr4 addAttribute:NSLinkAttributeName value:baiduURL2 range:NSMakeRange(0, attributedStr4.length)]; [attributedStr appendAttributedString:attributedStr2]; [attributedStr appendAttributedString:attributedStr3]; [attributedStr appendAttributedString:attributedStr4]; UITextView *lab2 = [UITextView new]; lab2.backgroundColor = [UIColor clearColor]; lab2.attributedText = attributedStr; lab2.textAlignment = NSTextAlignmentCenter; lab2.linkTextAttributes = @{NSForegroundColorAttributeName:rgba(255, 255, 255, 1)}; lab2.delegate = self; lab2.editable = NO; lab2.scrollEnabled = NO; // lab2.selectable = NO; // lab.textColor = rgba(255, 255, 255, 0.4); // lab.font = [UIFont systemFontOfSize:12]; [self.view addSubview:lab2]; [lab2 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view).offset(7); make.top.equalTo(btn.mas_bottom).offset(12); make.width.mas_equalTo(@270); // make.height.mas_equalTo(@15); }]; UIButton *selbtn = [UIButton new]; selbtn.tag = 130; [selbtn setBackgroundImage:[UIImage imageNamed:@"login_cirle"] forState:UIControlStateNormal]; [selbtn setBackgroundImage:[UIImage imageNamed:@"login_chick"] forState:UIControlStateSelected]; [self.view addSubview:selbtn]; [selbtn addTarget:self action:@selector(changeSelState) forControlEvents:UIControlEventTouchUpInside]; [selbtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(lab2.mas_left).offset(-2); make.size.mas_equalTo(CGSizeMake(12, 12)); make.centerY.equalTo(lab2); }]; UIButton *selbtn2 = [UIButton new]; [self.view addSubview:selbtn2]; [selbtn2 addTarget:self action:@selector(changeSelState) forControlEvents:UIControlEventTouchUpInside]; [selbtn2 mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(30, 30)); make.center.equalTo(selbtn); }]; } - (BOOL)validateContent:(NSString *) textString { NSString* number=@"^[a-zA-Z0-9]{4,16}$"; NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",number]; return [numberPre evaluateWithObject:textString]; } -(void)changeSelState{ UIButton *selbtn = [self.view viewWithTag:130]; selbtn.selected = !selbtn.isSelected; } -(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(nonnull NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction { if ([[URL scheme] isEqualToString:@"privateProtocal"]) { NSLog(@"看天用户协议"); //用户协议 ComonWKWebViewController *vc =[[ComonWKWebViewController alloc] init]; vc.modalPresentationStyle = UIModalPresentationOverFullScreen; vc.title = @"用户协议"; vc.url = @"https://backend.jsnoopyay.com/user_agreement.html"; [self presentViewController:vc animated:YES completion:nil]; return NO; } else if ([[URL scheme] isEqualToString:@"privacyPolicy"]) { NSLog(@"隐私协议"); //隐私协议 ComonWKWebViewController *vc =[[ComonWKWebViewController alloc] init]; vc.modalPresentationStyle = UIModalPresentationOverFullScreen; vc.title = @"隐私协议"; vc.url = @"https://backend.jsnoopyay.com/private.html"; [self presentViewController:vc animated:YES completion:nil]; return NO; } return YES; } //-(CommonBarView *)customerbar{ // if(!_customerbar){ // CGFloat h=0; // if(@available(iOS 13.0, *)){ // UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager; // CGRect f=sc.statusBarFrame; // h=f.size.height; // }else{ // h=[UIApplication sharedApplication].statusBarFrame.size.height; // } // if(h>=40){ // h=30; // } // _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)]; // _customerbar.bgView.backgroundColor = [UIColor clearColor]; // _customerbar.label.text=@"手机号登录"; // _customerbar.bgView.alpha = 1; // _customerbar.label.textColor = rgba(255, 255, 255, 1); // } // return _customerbar; //} -(void)backAction{ [self dismissViewControllerAnimated:true completion:nil]; } -(CommonBarView *)customerbar{ if(!_customerbar){ CGFloat h=0; if(@available(iOS 13.0, *)){ UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager; CGRect f=sc.statusBarFrame; h=f.size.height; }else{ h=[UIApplication sharedApplication].statusBarFrame.size.height; } if(h>=40){ h=30; } _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)]; _customerbar.bgView.backgroundColor = [UIColor clearColor]; _customerbar.label.text=@"注册"; _customerbar.bgView.alpha = 1; _customerbar.label.textColor = rgba(255, 255, 255, 1); // _customerbar.leftButton.hidden = true; // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back"] forState:UIControlStateNormal]; // [_customerbar.rightButton setImage:[UIImage imageNamed:@"Frame 9411"] forState:UIControlStateNormal]; // [_customerbar.rightButton setTitle:@"编辑" forState:UIControlStateNormal]; // [_customerbar.rightButton setImage:[self imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected]; // [_customerbar.rightButton setTitle:@"取消" forState:UIControlStateSelected]; // [_customerbar.rightButton setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal]; // _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14]; [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; // [_customerbar.rightButton addTarget:self action:@selector(changeSelState:) forControlEvents:UIControlEventTouchUpInside]; // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside]; // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) { // make.centerY.equalTo(_customerbar.leftButton); // make.right.equalTo(_customerbar).offset(-15); // make.size.mas_equalTo(CGSizeMake(23, 23)); // }]; } return _customerbar; } @end @interface inputView3() @property(nonatomic,strong)NSTimer *mytime; @property(nonatomic,assign)int second; @end @implementation inputView3 - (instancetype)init { self = [super init]; if (self) { self.second = 60; } return self; } //0手机号 1密码 -(void)setType:(int)type{ _type = type; [self initView:type]; } - (void)initView:(int)type{ UIImageView *iv = [UIImageView new]; if(type == 0){ iv.image = [UIImage imageNamed:@"Casino22"]; }else{ iv.image = [UIImage imageNamed:@"Casino2"]; } [self addSubview:iv]; [iv mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(40); make.top.equalTo(self); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; UITextField *tf =[UITextField new]; self.tf = tf; NSString *str=@""; if(type == 0){ str=@"用户名"; }else if(type == 1){ str=@"请输入密码"; tf.secureTextEntry = YES; }else if(type == 2){ str=@"确认密码"; tf.secureTextEntry = YES; } NSMutableAttributedString *attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:str]; [attributedPlaceholder addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.2) range:NSMakeRange(0, attributedPlaceholder.length)]; [attributedPlaceholder addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:14.0] range:NSMakeRange(0, attributedPlaceholder.length)]; tf.attributedPlaceholder = attributedPlaceholder; tf.textColor = [UIColor whiteColor]; tf.font = [UIFont italicSystemFontOfSize:14.0]; [tf addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; [self addSubview:tf]; [tf mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(iv.mas_right).offset(12); make.centerY.equalTo(iv); make.size.mas_equalTo(CGSizeMake(200, 20)); }]; // if(type == 0){ // UILabel *lab = [UILabel new]; // lab.text = @"+86"; // lab.textColor = rgba(255, 255, 255, 0.4); // lab.font = [UIFont systemFontOfSize:14]; // [self addSubview:lab]; // [lab mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(iv.mas_right).offset(12); // make.centerY.equalTo(iv); // }]; // // [tf mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(lab.mas_right).offset(8); // make.centerY.equalTo(iv); // make.size.mas_equalTo(CGSizeMake(200, 20)); // }]; // }else{ // [tf mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(iv.mas_right).offset(12); // make.centerY.equalTo(iv); // make.size.mas_equalTo(CGSizeMake(200, 20)); // }]; // // UIButton *showP =[UIButton new]; // [showP setTitle:@"获取验证码" forState:UIControlStateNormal]; // [showP setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal]; // showP.titleLabel.font = [UIFont systemFontOfSize:14]; // [showP addTarget:self action:@selector(getCode:) forControlEvents:UIControlEventTouchUpInside]; // [self addSubview:showP]; // [showP mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.equalTo(self).offset(-40); // make.centerY.equalTo(iv); // make.size.mas_equalTo(CGSizeMake(80, 20)); // }]; // } UIView *line = [UIView new]; line.backgroundColor = rgba(255, 255, 255, 0.2); [self addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(iv); make.right.equalTo(self).offset(-40); make.bottom.equalTo(self); make.height.mas_equalTo(@1); }]; } - (void)textFieldDidChange:(UITextField *)textField { if(textField.text.length>16){ textField.text = [textField.text substringToIndex:16]; } } //-(void)getCode:(UIButton *)showP{ // if(self.mytime){ // return; // } // self.mytime = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) { // [showP setTitle:[NSString stringWithFormat:@"%ds",self.second] forState:UIControlStateNormal]; // self.second -=1; // if(self.second <= -1){ // [self.mytime invalidate]; // self.mytime = nil; // self.second = 60; // [showP setTitle:@"获取验证码" forState:UIControlStateNormal]; // } // }]; // // if(self.tapBlock){ // self.tapBlock(); // } //} @end