YOUPAILPYoungForgetPWD.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // YOUPAILPYoungForgetPWD.m
  3. // livePro
  4. //
  5. // Created by leo on 2019/12/27.
  6. // Copyright © 2019 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAILPYoungForgetPWD.h"
  9. #import "YMCaptchaPopupView.h"
  10. @interface YOUPAILPYoungForgetPWD ()<UIScrollViewDelegate,UITextViewDelegate>
  11. @property(nonatomic,strong)UITextField* youpaipphoneTextField,*youpaippwdTextField;
  12. @property(nonatomic,assign)NSInteger youpaipphoneLength;
  13. @property(nonatomic,strong)UITextField* youpaipcodeTextField;
  14. @property(nonatomic,strong)UIButton* youpaiploginBtn;
  15. @property(nonatomic,strong)UIButton* youpaipverifyBtn;
  16. @property(nonatomic,strong)dispatch_source_t youpaipcodeTimer;
  17. @end
  18. @implementation YOUPAILPYoungForgetPWD
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.title = @"关闭未成年模式";
  22. self.youpaipphoneLength = 0;
  23. [self youpaifsetupView];
  24. self.view.backgroundColor = [UIColor whiteColor];
  25. }
  26. - (void)youpaifsetupView{
  27. UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight)];
  28. scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight-NavBarHeight+1);
  29. scrollView.bounces = YES;
  30. scrollView.showsHorizontalScrollIndicator = NO;
  31. scrollView.showsVerticalScrollIndicator = NO;
  32. scrollView.delegate = self;
  33. [self.view addSubview:scrollView];
  34. UITextField* phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(27, 27, KScreenWidth-54, 56)];
  35. self.youpaipphoneTextField = phoneTextField;
  36. phoneTextField.layer.cornerRadius = 28.0f;
  37. phoneTextField.clipsToBounds = YES;
  38. phoneTextField.backgroundColor = LZF7F8FAColor;
  39. phoneTextField.textColor = LZ273145Color;
  40. phoneTextField.tintColor = LZ7C69FEColor;
  41. UIView *phoneTipV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28+53+12, 56)];
  42. UILabel* phoneTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, 0, 53, 56)];
  43. phoneTipLabel.text = @"手机号";
  44. phoneTipLabel.textColor = LZ273145Color;
  45. phoneTipLabel.font = LCFont17;
  46. phoneTipLabel.textAlignment = NSTextAlignmentLeft;
  47. [phoneTipV addSubview:phoneTipLabel];
  48. phoneTextField.leftView = phoneTipV;
  49. phoneTextField.leftViewMode = UITextFieldViewModeAlways;
  50. phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  51. [[phoneTextField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal];
  52. phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
  53. [phoneTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
  54. NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号码"];
  55. [attrStr addAttribute:NSFontAttributeName value:LCFont17 range:NSMakeRange(0, attrStr.length)];
  56. [attrStr addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStr.length)];
  57. phoneTextField.attributedPlaceholder = attrStr;
  58. phoneTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
  59. [scrollView addSubview:phoneTextField];
  60. UITextField* codeTextField = [[UITextField alloc]initWithFrame:CGRectMake(27, CGRectGetMaxY(phoneTextField.frame) + 14.0f, KScreenWidth-54, 56)];
  61. self.youpaipcodeTextField = codeTextField;
  62. codeTextField.layer.cornerRadius = 28.0f;
  63. codeTextField.clipsToBounds = YES;
  64. codeTextField.backgroundColor = LZF7F8FAColor;
  65. codeTextField.textColor = LZ273145Color;
  66. codeTextField.tintColor = LZ7C69FEColor;
  67. UIView *codeTipLV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28+53+12, 56)];
  68. UILabel* codeTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, 0, 53, 56)];
  69. codeTipLabel.text = @"验证码";
  70. codeTipLabel.textColor = LZ273145Color;
  71. codeTipLabel.font =LCFont17;
  72. codeTipLabel.textAlignment = NSTextAlignmentLeft;
  73. [codeTipLV addSubview:codeTipLabel];
  74. codeTextField.leftView = codeTipLV;
  75. codeTextField.leftViewMode = UITextFieldViewModeAlways;
  76. UIView* rightview = [[UIView alloc]initWithFrame:CGRectMake(0, 0,107, 56)];
  77. UIButton* verifyBtn = [[UIButton alloc]initWithFrame:CGRectMake(14.0f, 14.0f, 79.0f, 28.0f)];
  78. self.youpaipverifyBtn = verifyBtn;
  79. verifyBtn.layer.cornerRadius = 14.0f;
  80. verifyBtn.layer.masksToBounds = YES;
  81. verifyBtn.backgroundColor = LZD3D1D7Color;
  82. verifyBtn.titleLabel.font = LCFont12;
  83. [verifyBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)];
  84. [verifyBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)];
  85. verifyBtn.userInteractionEnabled = NO;
  86. [verifyBtn addTarget:self action:@selector(youpaifverifyBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  87. [rightview addSubview:verifyBtn];
  88. codeTextField.rightView = rightview;
  89. codeTextField.rightViewMode = UITextFieldViewModeAlways;
  90. codeTextField.keyboardType = UIKeyboardTypeNumberPad;
  91. [codeTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
  92. NSMutableAttributedString* attrStrCode = [[NSMutableAttributedString alloc]initWithString:@"短信验证码"];
  93. [attrStrCode addAttribute:NSFontAttributeName value:LCFont17 range:NSMakeRange(0, attrStrCode.length)];
  94. [attrStrCode addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStrCode.length)];
  95. codeTextField.attributedPlaceholder = attrStrCode;
  96. codeTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
  97. [scrollView addSubview:codeTextField];
  98. UIButton* loginBtn = [[UIButton alloc]init];
  99. self.youpaiploginBtn = loginBtn;
  100. loginBtn.userInteractionEnabled = NO;
  101. loginBtn.backgroundColor = LZD3D1D7Color;
  102. loginBtn.layer.cornerRadius = 28.0;
  103. loginBtn.layer.masksToBounds = YES;
  104. loginBtn.titleLabel.font = LCFont17;
  105. [loginBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)];
  106. [loginBtn setTitle:@"关闭未成年模式" forState:(UIControlStateNormal)];
  107. [loginBtn addTarget:self action:@selector(youpaifloginBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  108. [scrollView addSubview:loginBtn];
  109. [loginBtn makeConstraints:^(MASConstraintMaker *make) {
  110. make.top.offset(KScreenHeight-100-SafeHeight-56.0f-NavBarHeight);
  111. make.centerX.equalTo(self.view.mas_centerX);
  112. make.size.mas_equalTo(CGSizeMake(KScreenWidth-54.0f, 56.0f));
  113. }];
  114. }
  115. //监听输入的手机号码自动添加空格
  116. -(void)textFieldDidEditing:(UITextField *)textField{
  117. if ([self.youpaipphoneTextField.text isEqualToString:@""] || [self.youpaipcodeTextField.text isEqualToString:@""]|| [self.youpaippwdTextField.text isEqualToString:@""]){
  118. self.youpaiploginBtn.backgroundColor = LZD3D1D7Color;
  119. [self.youpaiploginBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  120. [self.youpaiploginBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  121. self.youpaiploginBtn.userInteractionEnabled = NO;
  122. }else{
  123. [self.youpaiploginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  124. [self.youpaiploginBtn setBackgroundImage:[LCTools ColorImage:self.youpaiploginBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  125. self.youpaiploginBtn.userInteractionEnabled = YES;;
  126. }
  127. if (textField == self.youpaipphoneTextField) {
  128. if (textField.text.length > self.youpaipphoneLength) {
  129. if (textField.text.length == 4 || textField.text.length == 9 ) {//输入
  130. NSMutableString * str = [[NSMutableString alloc ] initWithString:textField.text];
  131. [str insertString:@" " atIndex:(textField.text.length-1)];
  132. textField.text = str;
  133. }if (textField.text.length >= 13 ) {//输入完成
  134. textField.text = [textField.text substringToIndex:13];
  135. self.youpaipverifyBtn.userInteractionEnabled = YES;
  136. [self.youpaipverifyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  137. [self.youpaipverifyBtn setBackgroundImage:[LCTools ColorImage:self.youpaipverifyBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  138. }
  139. self.youpaipphoneLength = textField.text.length;
  140. }else if (textField.text.length < self.youpaipphoneLength){//删除
  141. if (textField.text.length == 4 || textField.text.length == 9) {
  142. textField.text = [NSString stringWithFormat:@"%@",textField.text];
  143. textField.text = [textField.text substringToIndex:(textField.text.length-1)];
  144. }
  145. [self.youpaipverifyBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  146. self.youpaipverifyBtn.userInteractionEnabled = NO;
  147. [self.youpaipverifyBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  148. self.youpaipphoneLength = textField.text.length;
  149. }
  150. }
  151. }
  152. - (void)youpaifverifyBtnClick{
  153. NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  154. if ([ZCRegularHelper regularPhoneNumber:phoneText]) {//首先手机格式保证正确
  155. YMCaptchaPopupView *view = [[YMCaptchaPopupView alloc] init];
  156. view.cancelButtonTappedBlock = ^{};
  157. @weakify(self)
  158. view.confirmButtonTappedBlock = ^(NSString * _Nonnull input) {
  159. @strongify(self)
  160. @weakify(self)
  161. [LCHttpHelper requestWithURLString:PhoneCode parameters:@{@"captcha":input, @"mobile":phoneText,@"type":@"forget"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  162. @strongify(self)
  163. NSDictionary* dict = (NSDictionary*)responseObject;
  164. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  165. if (code==0) {//成功
  166. [ZCHUDHelper showTitle:@"验证码已发送"];
  167. __block int timeout=120;
  168. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  169. dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  170. dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  171. dispatch_source_set_event_handler(_timer, ^{
  172. if(timeout<=0){
  173. dispatch_source_cancel(_timer);
  174. dispatch_async(dispatch_get_main_queue(), ^{
  175. [self.youpaipverifyBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  176. self.youpaipverifyBtn.userInteractionEnabled = YES;
  177. });
  178. }else{
  179. NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout];
  180. dispatch_async(dispatch_get_main_queue(), ^{
  181. //设置界面的按钮显示 根据自己需求设置
  182. [self.youpaipverifyBtn setTitle:strTime forState:UIControlStateNormal];
  183. self.youpaipverifyBtn.userInteractionEnabled = NO;
  184. });
  185. timeout--;
  186. }
  187. });
  188. dispatch_resume(_timer);
  189. }
  190. } failure:^(NSError *error) {
  191. }];
  192. };
  193. UIView *currentVCView = [LCTools getCurrentVC].view;
  194. if (currentVCView != nil && ![currentVCView isEqual:NSNull.null]) {
  195. [view showInView:currentVCView];
  196. }
  197. }
  198. }
  199. - (void)youpaifloginBtnClick{
  200. NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  201. if ([ZCRegularHelper regularPhoneNumber:phoneText]) {
  202. if ([ZCRegularHelper regularVerifyCode4:self.youpaipcodeTextField.text]) {
  203. NSMutableDictionary* params = [NSMutableDictionary dictionary];
  204. [params setObject:phoneText forKey:@"mobile"];
  205. [params setObject:self.youpaipcodeTextField.text forKey:@"phone_code"];
  206. // [params setObject:self.pwdTextField.text forKey:@"password"];
  207. //password
  208. [LCHttpHelper requestWithURLString:VerifyMobileCode parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  209. NSDictionary* dict = (NSDictionary*)responseObject;
  210. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  211. if (code==0) {//成功
  212. [_youpaipdelegate youpaifswitchYounModel:0];
  213. [self.navigationController popToRootViewControllerAnimated:YES];
  214. }
  215. } failure:^(NSError *error) {
  216. }];
  217. }
  218. }
  219. }
  220. -(void)youpaifshowBtnClick:(UIButton*)btn{
  221. if (btn.selected) {
  222. btn.selected = NO;
  223. [btn setImage:[UIImage imageNamed:@"vqu_images_sign_input3"] forState:(UIControlStateNormal)];
  224. self.youpaippwdTextField.secureTextEntry = YES;
  225. }else{
  226. btn.selected = YES;
  227. [btn setImage:[UIImage imageNamed:@"vqu_images_sign_input2"] forState:(UIControlStateNormal)];
  228. self.youpaippwdTextField.secureTextEntry = NO;
  229. }
  230. }
  231. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  232. [self.view endEditing:YES];
  233. }
  234. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  235. [self.view endEditing:YES];
  236. }
  237. /*
  238. #pragma mark - Navigation
  239. // In a storyboard-based application, you will often want to do a little preparation before navigation
  240. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  241. // Get the new view controller using [segue destinationViewController].
  242. // Pass the selected object to the new view controller.
  243. }
  244. */
  245. @end