YOUPAILPYoungForgetPWD.m 20 KB

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