forgetPwdVC.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. //
  2. // forgetPwdVC.m
  3. // shiku_im
  4. //
  5. // Created by flyeagleTang on 14-6-7.
  6. // Copyright (c) 2014年 Reese. All rights reserved.
  7. //
  8. #import "forgetPwdVC.h"
  9. #import "JXTelAreaListVC.h"
  10. #import "JXUserObject.h"
  11. #import "loginVC.h"
  12. #import "MD5Util.h"
  13. #define HEIGHT 50
  14. @interface forgetPwdVC () <UITextFieldDelegate>
  15. {
  16. UIButton *_areaCodeBtn;
  17. NSTimer* timer;
  18. JXUserObject *_user;
  19. UIImageView * _imgCodeImg;
  20. UITextField *_imgCode; //图片验证码
  21. UIButton * _graphicButton;
  22. }
  23. @end
  24. @implementation forgetPwdVC
  25. - (id)init
  26. {
  27. self = [super init];
  28. if (self) {
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad
  33. {
  34. [super viewDidLoad];
  35. if (self.isModify) {
  36. // self.title = Localized(@"JX_UpdatePassWord");
  37. }else{
  38. // self.title = Localized(@"JX_ForgetPassWord");
  39. }
  40. _user = [JXUserObject sharedInstance];
  41. _seconds = 0;
  42. self.isGotoBack = YES;
  43. self.heightFooter = 0;
  44. self.heightHeader = JX_SCREEN_TOP;
  45. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  46. [self createHeadAndFoot];
  47. self.tableBody.backgroundColor = [UIColor whiteColor];
  48. UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, JX_SCREEN_WIDTH-30, 300)];
  49. baseView.backgroundColor = [UIColor whiteColor];
  50. baseView.layer.cornerRadius = 7.f;
  51. baseView.layer.masksToBounds = YES;
  52. [self.tableBody addSubview:baseView];
  53. CGFloat W = baseView.frame.size.width;
  54. int n = INSETS;
  55. /*
  56. JXLabel* lb;
  57. lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 50-n, 60, 30)];
  58. lb.textColor = [UIColor blackColor];
  59. lb.backgroundColor = [UIColor clearColor];
  60. lb.text = @"手机号";
  61. [self.tableBody addSubview:lb];
  62. [lb release];
  63. lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 100-n, 60, 30)];
  64. lb.textColor = [UIColor blackColor];
  65. lb.backgroundColor = [UIColor clearColor];
  66. lb.text = @"验证码";
  67. [self.tableBody addSubview:lb];
  68. [lb release];
  69. lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 150-n, 60, 30)];
  70. lb.textColor = [UIColor blackColor];
  71. lb.backgroundColor = [UIColor clearColor];
  72. lb.text = @"新密码";
  73. [self.tableBody addSubview:lb];
  74. [lb release];
  75. lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 200-n, 60, 30)];
  76. lb.textColor = [UIColor blackColor];
  77. lb.backgroundColor = [UIColor clearColor];
  78. lb.text = @"确认";
  79. [self.tableBody addSubview:lb];
  80. [lb release];*/
  81. UILabel *titleLable = [[UILabel alloc] init];
  82. titleLable.text = @"修改密码";
  83. titleLable.textColor = [UIColor blackColor];
  84. titleLable.font = [UIFont systemFontOfSize:30 weight:(UIFontWeightRegular)];
  85. [titleLable sizeToFit];
  86. titleLable.frame = CGRectMake(JX_SCREEN_WIDTH/2- titleLable.frame.size.width/2, 0, titleLable.frame.size.width, titleLable.frame.size.height);
  87. [titleLable sizeToFit];
  88. [self.tableBody addSubview:titleLable];
  89. n = n+titleLable.frame.size.height+INSETS;
  90. //区号
  91. if (!_phone) {
  92. _phone = [UIFactory createTextFieldWith:CGRectMake(15, n, W-30, HEIGHT) delegate:self returnKeyType:UIReturnKeyNext secureTextEntry:NO placeholder:Localized(@"JX_InputPhone") font:g_factory.font16];
  93. _phone.clearButtonMode = UITextFieldViewModeWhileEditing;
  94. _phone.borderStyle = UITextBorderStyleNone;
  95. [baseView addSubview:_phone];
  96. [self showLine:_phone];
  97. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 67, HEIGHT)];
  98. _phone.leftView = leftView;
  99. _phone.leftViewMode = UITextFieldViewModeAlways;
  100. NSString *areaStr;
  101. if (![g_default objectForKey:kMY_USER_AREACODE]) {
  102. areaStr = @"+86";
  103. } else {
  104. areaStr = [NSString stringWithFormat:@"+%@",[g_default objectForKey:kMY_USER_AREACODE]];
  105. }
  106. _areaCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 41, HEIGHT)];
  107. [_areaCodeBtn setTitle:areaStr forState:UIControlStateNormal];
  108. _areaCodeBtn.titleLabel.font = SYSFONT(15);
  109. [_areaCodeBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
  110. //[_areaCodeBtn setImage:[UIImage imageNamed:@"down_arrow_black"] forState:UIControlStateNormal];
  111. _areaCodeBtn.custom_acceptEventInterval = 1.0f;
  112. //[_areaCodeBtn addTarget:self action:@selector(areaCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  113. [self resetBtnEdgeInsets:_areaCodeBtn];
  114. [leftView addSubview:_areaCodeBtn];
  115. UIView *verticalLine = [[UIView alloc] initWithFrame:CGRectMake(_areaCodeBtn.frame.size.width+7, HEIGHT/2 - 8, LINE_WH, 16)];
  116. verticalLine.backgroundColor = [UIColor clearColor]; //THE_LINE_COLOR;
  117. [leftView addSubview:verticalLine];
  118. }
  119. n = n+HEIGHT;
  120. // _code = [[UITextField alloc] initWithFrame:CGRectMake(INSETS,n,188,HEIGHT)];
  121. // _code.delegate = self;
  122. // _code.autocorrectionType = UITextAutocorrectionTypeNo;
  123. // _code.autocapitalizationType = UITextAutocapitalizationTypeNone;
  124. // _code.enablesReturnKeyAutomatically = YES;
  125. // _code.borderStyle = UITextBorderStyleRoundedRect;
  126. // _code.returnKeyType = UIReturnKeyDone;
  127. // _code.clearButtonMode = UITextFieldViewModeWhileEditing;
  128. // _code.placeholder = Localized(@"JX_InputMessageCode");
  129. // [self.tableBody addSubview:_code];
  130. //// [_code release];
  131. //
  132. // _send = [UIFactory createButtonWithTitle:Localized(@"JX_Send")
  133. // titleFont:g_factory.font14
  134. // titleColor:[UIColor whiteColor]
  135. // normal:@"feaBtn_backImg_sel"
  136. // highlight:@"feaBtn_backImg_sel" ];
  137. // [_send addTarget:self action:@selector(onSend) forControlEvents:UIControlEventTouchUpInside];
  138. // _send.frame = CGRectMake(JX_SCREEN_WIDTH-27-105+INSETS*2, n, 105, HEIGHT);
  139. // [self.tableBody addSubview:_send];
  140. if (!self.isModify) {
  141. //图片验证码
  142. // self.imgCodeView = [self customItemWith:Localized(@"JX_imageCode") currentY:currentY allLengthTop:YES bottomLine:YES labelWidth:_labelWidth];
  143. _imgCode = [UIFactory createTextFieldWith:CGRectMake(15, n, W-30-70-15-35-4, HEIGHT) delegate:self returnKeyType:UIReturnKeyNext secureTextEntry:NO placeholder:Localized(@"JX_inputImgCode") font:g_factory.font16];
  144. _imgCode.clearButtonMode = UITextFieldViewModeWhileEditing;
  145. _imgCode.borderStyle = UITextBorderStyleNone;
  146. [baseView addSubview:_imgCode];
  147. [self showLine:_imgCode];
  148. _imgCode.layer.masksToBounds = YES;
  149. _imgCode.layer.cornerRadius = 4;
  150. // _imgCode = [[UITextField alloc] initWithFrame:CGRectMake(_labelWidth+20+5, 15, self.tableBody.frame.size.width-_labelWidth-20-5, 20)];
  151. // _imgCode.font = SYSFONT(15);
  152. // _imgCode.placeholder = Localized(@"JX_inputImgCode");
  153. // _imgCode.delegate = self;
  154. // [self.imgCodeView addSubview:_imgCode];
  155. [self createLeftViewWithImage:[UIImage imageNamed:@"verify"] superView:_imgCode];
  156. _imgCodeImg = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgCode.frame)+INSETS, 0, 70, 35)];
  157. _imgCodeImg.center = CGPointMake(_imgCodeImg.center.x, _imgCode.center.y);
  158. _imgCodeImg.userInteractionEnabled = YES;
  159. [baseView addSubview:_imgCodeImg];
  160. // _imgCodeImg.image = [UIImage imageNamed:@"refreshImgCode"];
  161. // UITapGestureRecognizer * tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getImgCodeImgGes:)];
  162. // [_imgCodeImg addGestureRecognizer:tapGes];
  163. _graphicButton = [UIButton buttonWithType:UIButtonTypeCustom];
  164. _graphicButton.frame = CGRectMake(CGRectGetMaxX(_imgCodeImg.frame)+4, 7, 35, 35);
  165. _graphicButton.center = CGPointMake(_graphicButton.center.x,_imgCode.center.y);
  166. [_graphicButton setBackgroundImage:[UIImage imageNamed:@"refreshGraphic"] forState:UIControlStateNormal];
  167. [_graphicButton setBackgroundImage:[UIImage imageNamed:@"refreshGraphic"] forState:UIControlStateHighlighted];
  168. [_graphicButton addTarget:self action:@selector(refreshGraphicAction:) forControlEvents:UIControlEventTouchUpInside];
  169. [baseView addSubview:_graphicButton];
  170. n = n+HEIGHT;
  171. _code = [[UITextField alloc] initWithFrame:CGRectMake(15, n, W-110-30, HEIGHT)];
  172. _code.delegate = self;
  173. _code.autocorrectionType = UITextAutocorrectionTypeNo;
  174. _code.autocapitalizationType = UITextAutocapitalizationTypeNone;
  175. _code.enablesReturnKeyAutomatically = YES;
  176. _code.font = g_factory.font16;
  177. // _code.borderStyle = UITextBorderStyleRoundedRect;
  178. _code.returnKeyType = UIReturnKeyDone;
  179. _code.clearButtonMode = UITextFieldViewModeWhileEditing;
  180. _code.placeholder = Localized(@"JX_InputMessageCode");
  181. [baseView addSubview:_code];
  182. [self showLine:_code];
  183. [self createLeftViewWithImage:[UIImage imageNamed:@"code"] superView:_code];
  184. _send = [UIFactory createButtonWithTitle:@"获取验证码"
  185. titleFont:g_factory.font16
  186. titleColor:HEXCOLOR(0x2A98FF)
  187. normal:nil
  188. highlight:nil ];
  189. [_send addTarget:self action:@selector(sendSMS) forControlEvents:UIControlEventTouchUpInside];
  190. // _send.backgroundColor = g_theme.themeColor;
  191. _send.titleLabel.font = SYSFONT(16);
  192. _send.frame = CGRectMake(W-110-30, n+HEIGHT/2-HEIGHT/2, 105, HEIGHT);
  193. _send.layer.cornerRadius = 7.f;
  194. _send.layer.masksToBounds = YES;
  195. [baseView addSubview:_send];
  196. [self showLine:_send];
  197. n = n+HEIGHT;
  198. }
  199. if (self.isModify) {
  200. _oldPwd = [[UITextField alloc] initWithFrame:CGRectMake(15,n,W-30,HEIGHT)];
  201. _oldPwd.delegate = self;
  202. _oldPwd.autocorrectionType = UITextAutocorrectionTypeNo;
  203. _oldPwd.autocapitalizationType = UITextAutocapitalizationTypeNone;
  204. _oldPwd.enablesReturnKeyAutomatically = YES;
  205. // _oldPwd.borderStyle = UITextBorderStyleRoundedRect;
  206. _oldPwd.returnKeyType = UIReturnKeyDone;
  207. _oldPwd.clearButtonMode = UITextFieldViewModeWhileEditing;
  208. _oldPwd.placeholder = Localized(@"JX_InputOldPassWord");
  209. _oldPwd.secureTextEntry = YES;
  210. _oldPwd.font = g_factory.font16;
  211. [baseView addSubview:_oldPwd];
  212. [self showLine:_oldPwd];
  213. [self createLeftViewWithImage:[UIImage imageNamed:@"password"] superView:_oldPwd];
  214. n = n+HEIGHT;
  215. }
  216. if (!self.isPayPWD) {
  217. _pwd = [[UITextField alloc] initWithFrame:CGRectMake(15,n,W-30,HEIGHT)];
  218. _pwd.delegate = self;
  219. _pwd.autocorrectionType = UITextAutocorrectionTypeNo;
  220. _pwd.autocapitalizationType = UITextAutocapitalizationTypeNone;
  221. _pwd.enablesReturnKeyAutomatically = YES;
  222. // _pwd.borderStyle = UITextBorderStyleRoundedRect;
  223. _pwd.returnKeyType = UIReturnKeyDone;
  224. _pwd.clearButtonMode = UITextFieldViewModeWhileEditing;
  225. _pwd.placeholder = Localized(@"JX_InputNewPassWord");
  226. _pwd.secureTextEntry = YES;
  227. _pwd.font = g_factory.font16;
  228. [baseView addSubview:_pwd];
  229. [self showLine:_pwd];
  230. [self createLeftViewWithImage:[UIImage imageNamed:@"password"] superView:_pwd];
  231. n = n+HEIGHT;
  232. _repeat = [[UITextField alloc] initWithFrame:CGRectMake(15,n,W-30,HEIGHT)];
  233. _repeat.delegate = self;
  234. _repeat.autocorrectionType = UITextAutocorrectionTypeNo;
  235. _repeat.autocapitalizationType = UITextAutocapitalizationTypeNone;
  236. _repeat.enablesReturnKeyAutomatically = YES;
  237. // _repeat.borderStyle = UITextBorderStyleRoundedRect;
  238. _repeat.returnKeyType = UIReturnKeyDone;
  239. _repeat.clearButtonMode = UITextFieldViewModeWhileEditing;
  240. _repeat.placeholder = Localized(@"JX_ConfirmNewPassWord");
  241. _repeat.secureTextEntry = YES;
  242. _repeat.font = g_factory.font16;
  243. [self createLeftViewWithImage:[UIImage imageNamed:@"password"] superView:_repeat];
  244. [baseView addSubview:_repeat];
  245. [self showLine:_repeat];
  246. n = n+HEIGHT;
  247. }
  248. n += 30;
  249. UIButton* _btn = [UIFactory createCommonButton:Localized(@"JX_UpdatePassWord") target:self action:@selector(onClick:)];
  250. [_btn.titleLabel setFont:g_factory.font16];
  251. _btn.layer.masksToBounds = YES;
  252. _btn.layer.cornerRadius = 20.f;
  253. _btn.frame = CGRectMake(15, n, W-30, 40);
  254. [baseView addSubview:_btn];
  255. CGRect frame = baseView.frame;
  256. frame.size.height = CGRectGetMaxY(_btn.frame)+30;
  257. baseView.frame = frame;
  258. _phone.text = g_myself.phone;
  259. if (self.isModify) {
  260. _phone.enabled = NO;
  261. }else{
  262. if (_phone.text.length > 0) {
  263. [self getImgCodeImg];
  264. }
  265. }
  266. }
  267. - (void)didReceiveMemoryWarning
  268. {
  269. [super didReceiveMemoryWarning];
  270. // Dispose of any resources that can be recreated.
  271. }
  272. -(void)refreshGraphicAction:(UIButton *)button{
  273. [self getImgCodeImg];
  274. }
  275. -(void)getImgCodeImg{
  276. if(_phone.text.length > 0){
  277. // if ([self checkPhoneNum]) {
  278. //请求图片验证码
  279. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  280. NSString * codeUrl = [g_server getImgCode:_phone.text areaCode:areaCode];
  281. NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:codeUrl] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
  282. [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
  283. if (!connectionError) {
  284. UIImage * codeImage = [UIImage imageWithData:data];
  285. if (codeImage != nil) {
  286. _imgCodeImg.image = codeImage;
  287. }else{
  288. [g_App showAlert:Localized(@"JX_ImageCodeFailed")];
  289. }
  290. }else{
  291. NSLog(@"%@",connectionError);
  292. [g_App showAlert:connectionError.localizedDescription];
  293. }
  294. }];
  295. // [_imgCodeImg sd_setImageWithURL:[NSURL URLWithString:codeUrl] placeholderImage:[UIImage imageNamed:@"refreshImgCode"] options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  296. // if (!error) {
  297. // _imgCodeImg.image = image;
  298. // }else{
  299. // NSLog(@"%@",error);
  300. // }
  301. // }];
  302. }else{
  303. }
  304. }
  305. #pragma mark------验证
  306. -(void)onClick:(UIButton *)btn{
  307. btn.enabled = NO;
  308. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  309. btn.enabled = YES;
  310. });
  311. if([_phone.text length]<= 0){
  312. [g_App showAlert:Localized(@"JX_InputPhone")];
  313. return;
  314. }
  315. if (!self.isModify) {
  316. if([_code.text length]<4){
  317. //_code.text = @"1315";
  318. [g_App showAlert:Localized(@"JX_InputMessageCode")];
  319. return;
  320. }
  321. }
  322. if (self.isModify && [_oldPwd.text length] <= 0){
  323. [g_App showAlert:Localized(@"JX_InputPassWord")];
  324. return;
  325. }
  326. if (!self.isPayPWD) {
  327. if([_pwd.text length]<=0){
  328. [g_App showAlert:Localized(@"JX_InputPassWord")];
  329. return;
  330. }
  331. if ([_pwd.text length] < 6) {
  332. [g_App showAlert:Localized(@"JX_TurePasswordAlert")];
  333. return;
  334. }
  335. if([_repeat.text length]<=0){
  336. [g_App showAlert:Localized(@"JX_ConfirmPassWord")];
  337. return;
  338. }
  339. if(![_pwd.text isEqualToString:_repeat.text]){
  340. [g_App showAlert:Localized(@"JX_PasswordFiled")];
  341. return;
  342. }
  343. if ([_pwd.text isEqualToString:_oldPwd.text]) {
  344. [g_App showAlert:Localized(@"JX_PasswordOriginal")];
  345. return;
  346. }
  347. }
  348. // if([_smsCode length]<=0){
  349. // //忽略短信验证
  350. // //_smsCode = _code.text;
  351. // [g_App showAlert:@"请输入验证码"];
  352. // return;
  353. // }
  354. [self.view endEditing:YES];
  355. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  356. if (self.isModify){
  357. [_wait start];
  358. #ifdef IS_MsgEncrypt
  359. [g_server userGetRandomStr:self];
  360. #else
  361. [g_server updatePwd:_phone.text areaCode:areaCode oldPwd:_oldPwd.text newPwd:_pwd.text checkCode:nil toView:self];
  362. #endif
  363. }else{
  364. [_wait start];
  365. if (self.isPayPWD) {
  366. long time = (long)[[NSDate date] timeIntervalSince1970];
  367. time = time *1000 + g_server.timeDifference;
  368. NSString *salt = [NSString stringWithFormat:@"%ld",time];
  369. NSString *mac = [self getResetPayPWDMacWithSalt:salt];
  370. [g_server authkeysResetPayPasswordWithSalt:salt mac:mac toView:self];
  371. }else {
  372. [g_server resetPwd:_phone.text areaCode:areaCode randcode:_code.text newPwd:_pwd.text toView:self];
  373. }
  374. // BOOL b = YES;
  375. //
  376. // b = [_code.text isEqualToString:_smsCode];
  377. //
  378. // if(b){
  379. //
  380. // }
  381. // else
  382. // [g_App showAlert:Localized(@"inputPhoneVC_MsgCodeNotOK")];
  383. // [g_App showAlert:@"短信验证码不对"];
  384. }
  385. }
  386. - (NSString *)getResetPayPWDMacWithSalt:(NSString *)salt {
  387. NSMutableString *str = [NSMutableString string];
  388. [str appendString:APIKEY];
  389. [str appendString:g_myself.userId];
  390. [str appendString:g_server.access_token];
  391. [str appendString:salt];
  392. NSData *key = [MD5Util getMD5DataWithString:_code.text];
  393. NSData *macData = [g_securityUtil getHMACMD5:[str dataUsingEncoding:NSUTF8StringEncoding] key:key];
  394. NSString *mac = [macData base64EncodedStringWithOptions:0];
  395. return mac;
  396. }
  397. //验证手机号格式
  398. - (void)sendSMS{
  399. [_phone resignFirstResponder];
  400. [_imgCode resignFirstResponder];
  401. [_code resignFirstResponder];
  402. _send.enabled = NO;
  403. if (_imgCode.text.length < 3) {
  404. [g_App showAlert:Localized(@"JX_inputImgCode")];
  405. _send.enabled = YES;
  406. return;
  407. }
  408. [self onSend];
  409. // if([self isMobileNumber:_phone.text]){
  410. // //验证手机号码是否已注册
  411. // // [g_server verifyPhone:[NSString stringWithFormat:@"%@%@",[_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""],_phoneNumTextField.text] toView:self];
  412. //
  413. // //请求验证码
  414. //
  415. //
  416. // }else {
  417. // _send.enabled = YES;
  418. // }
  419. }
  420. //验证手机号码格式
  421. - (BOOL)isMobileNumber:(NSString *)number{
  422. if ([_phone.text length] == 0) {
  423. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:Localized(@"JX_Tip") message:Localized(@"JX_InputPhone") delegate:nil cancelButtonTitle:Localized(@"JX_Confirm") otherButtonTitles:nil, nil];
  424. [alert show];
  425. // [alert release];
  426. return NO;
  427. }
  428. if ([_areaCodeBtn.titleLabel.text isEqualToString:@"+86"]) {
  429. NSString *regex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
  430. NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
  431. BOOL isMatch = [pred evaluateWithObject:number];
  432. if (!isMatch) {
  433. [g_App showAlert:Localized(@"inputPhoneVC_InputTurePhone")];
  434. // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:Localized(@"JXVerifyAccountVC_Prompt") message:Localized(@"JXVerifyAccountVC_PhoneNumberError") delegate:nil cancelButtonTitle:Localized(@"JXVerifyAccountVC_OK") otherButtonTitles:nil, nil];
  435. // [alert show];
  436. // [alert release];
  437. return NO;
  438. }
  439. }
  440. return YES;
  441. }
  442. -(void)onSend{
  443. if (!_send.selected) {
  444. [_wait start];
  445. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  446. // _user = [JXUserObject sharedInstance];
  447. _user.areaCode = areaCode;
  448. [g_server sendSMS:[NSString stringWithFormat:@"%@",_phone.text] areaCode:areaCode isRegister:NO imgCode:_imgCode.text toView:self];
  449. }
  450. }
  451. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  452. [_wait stop];
  453. if([aDownload.action isEqualToString:act_SendSMS]){
  454. _send.enabled = YES;
  455. _send.selected = YES;
  456. _send.userInteractionEnabled = NO;
  457. _send.backgroundColor = [UIColor grayColor];
  458. _smsCode = [[dict objectForKey:@"code"] copy];
  459. [_send setTitle:@"60s" forState:UIControlStateSelected];
  460. [_send setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  461. _seconds = 60;
  462. timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showTime:) userInfo:_send repeats:YES];
  463. }
  464. if([aDownload.action isEqualToString:act_PwdUpdate] || [aDownload.action isEqualToString:act_PwdUpdateV1]){
  465. [g_App showAlert:Localized(@"JX_UpdatePassWordOK")];
  466. g_myself.password = [g_server getMD5String:_pwd.text];
  467. [g_default setObject:[g_server getMD5String:_pwd.text] forKey:kMY_USER_PASSWORD];
  468. [g_default synchronize];
  469. [self actionQuit];
  470. [self relogin];
  471. }
  472. if([aDownload.action isEqualToString:act_PwdReset] || [aDownload.action isEqualToString:act_PwdResetV1]){
  473. [g_App showAlert:Localized(@"JX_UpdatePassWordOK")];
  474. g_myself.password = [g_server getMD5String:_pwd.text];
  475. [g_default setObject:[g_server getMD5String:_pwd.text] forKey:kMY_USER_PASSWORD];
  476. [g_default synchronize];
  477. [self actionQuit];
  478. }
  479. if ([aDownload.action isEqualToString:act_UserGetRandomStr]) {
  480. NSString *checkCode = nil;
  481. #ifdef IS_MsgEncrypt
  482. NSString *userRandomStr = [dict objectForKey:@"userRandomStr"];
  483. SecKeyRef privateKey = [g_securityUtil getRSAKeyWithBase64Str:g_msgUtil.rsaPrivateKey isPrivateKey:YES];
  484. NSData *randomData = [[NSData alloc] initWithBase64EncodedString:userRandomStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
  485. NSData *codeData = [g_securityUtil decryptMessageRSA:randomData withPrivateKey:privateKey];
  486. checkCode = [[NSString alloc] initWithData:codeData encoding:NSUTF8StringEncoding];
  487. #endif
  488. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  489. [g_server updatePwd:_phone.text areaCode:areaCode oldPwd:_oldPwd.text newPwd:_pwd.text checkCode:checkCode toView:self];
  490. }
  491. if ([aDownload.action isEqualToString:act_AuthkeysResetPayPassword]) {
  492. if ([self.delegate respondsToSelector:@selector(forgetPwdSuccess)]) {
  493. [self actionQuit];
  494. [self.delegate forgetPwdSuccess];
  495. }
  496. }
  497. }
  498. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  499. if([aDownload.action isEqualToString:act_SendSMS]){
  500. [_send setTitle:Localized(@"JX_SendAngin") forState:UIControlStateNormal];
  501. _send.enabled = YES;
  502. }else if ([aDownload.action isEqualToString:act_PwdUpdate] || [aDownload.action isEqualToString:act_PwdUpdateV1]) {
  503. NSString *error = [dict objectForKey:@"resultMsg"];
  504. [g_App showAlert:[NSString stringWithFormat:@"%@",error]];
  505. return hide_error;
  506. }
  507. [_wait stop];
  508. return show_error;
  509. }
  510. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  511. [_wait stop];
  512. _send.enabled = YES;
  513. return show_error;
  514. }
  515. -(void) didServerConnectStart:(JXConnection*)aDownload{
  516. [_wait stop];
  517. }
  518. -(void)showTime:(NSTimer*)sender{
  519. UIButton *but = (UIButton*)[timer userInfo];
  520. _seconds--;
  521. [but setTitle:[NSString stringWithFormat:@"%ds",_seconds] forState:UIControlStateSelected];
  522. if(_seconds<=0){
  523. but.selected = NO;
  524. but.userInteractionEnabled = YES;
  525. but.backgroundColor = g_theme.themeColor;
  526. [_send setTitle:Localized(@"JX_SendAngin") forState:UIControlStateNormal];
  527. if (timer) {
  528. timer = nil;
  529. [sender invalidate];
  530. }
  531. _seconds = 60;
  532. }
  533. }
  534. -(void)textFieldDidEndEditing:(UITextField *)textField{
  535. if (textField == _phone) {
  536. [self getImgCodeImg];
  537. }
  538. }
  539. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  540. if (_phone == textField) {
  541. return [self validateNumber:string];
  542. }
  543. return YES;
  544. }
  545. - (BOOL)validateNumber:(NSString*)number {
  546. // 只能使用字母和数字
  547. NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet];
  548. NSString *filtered = [[number componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
  549. return [number isEqualToString:filtered];
  550. }
  551. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  552. {
  553. [self.view endEditing:YES];
  554. return YES;
  555. }
  556. - (void)areaCodeBtnClick:(UIButton *)but{
  557. [self.view endEditing:YES];
  558. JXTelAreaListVC *telAreaListVC = [[JXTelAreaListVC alloc] init];
  559. telAreaListVC.telAreaDelegate = self;
  560. telAreaListVC.didSelect = @selector(didSelectTelArea:);
  561. // [g_window addSubview:telAreaListVC.view];
  562. [g_navigation pushViewController:telAreaListVC animated:YES];
  563. }
  564. - (void)didSelectTelArea:(NSString *)areaCode{
  565. [_areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@",areaCode] forState:UIControlStateNormal];
  566. [self resetBtnEdgeInsets:_areaCodeBtn];
  567. }
  568. - (void)resetBtnEdgeInsets:(UIButton *)btn{
  569. [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width-2, 0, btn.imageView.frame.size.width+2)];
  570. [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width+2, 0, -btn.titleLabel.frame.size.width-2)];
  571. }
  572. -(void)relogin{
  573. [g_default removeObjectForKey:kMY_USER_PASSWORD];
  574. [g_default removeObjectForKey:kMY_USER_TOKEN];
  575. [share_defaults removeObjectForKey:kMY_ShareExtensionToken];
  576. // [g_default setObject:nil forKey:kMY_USER_TOKEN];
  577. g_server.access_token = nil;
  578. [g_notify postNotificationName:kSystemLogoutNotifaction object:nil];
  579. [[JXXMPP sharedInstance] logout];
  580. NSLog(@"XMPP ---- forgetPwdVC relogin");
  581. loginVC* vc = [loginVC alloc];
  582. vc.isAutoLogin = NO;
  583. vc.isSwitchUser= NO;
  584. vc = [vc init];
  585. [g_mainVC.view removeFromSuperview];
  586. g_mainVC = nil;
  587. [self.view removeFromSuperview];
  588. self.view = nil;
  589. g_navigation.rootViewController = vc;
  590. // g_navigation.lastVC = nil;
  591. // [g_navigation.subViews removeAllObjects];
  592. // [g_navigation pushViewController:vc];
  593. // g_App.window.rootViewController = vc;
  594. // [g_App.window makeKeyAndVisible];
  595. // loginVC* vc = [loginVC alloc];
  596. // vc.isAutoLogin = NO;
  597. // vc.isSwitchUser= NO;
  598. // vc = [vc init];
  599. // [g_window addSubview:vc.view];
  600. // [self actionQuit];
  601. // [_wait performSelector:@selector(stop) withObject:nil afterDelay:1];
  602. [_wait stop];
  603. #if TAR_IM
  604. #ifdef Meeting_Version
  605. [g_meeting stopMeeting];
  606. #endif
  607. #endif
  608. }
  609. - (void)createLeftViewWithImage:(UIImage *)image superView:(UITextField *)textField {
  610. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 27, HEIGHT)];
  611. textField.leftView = leftView;
  612. textField.leftViewMode = UITextFieldViewModeAlways;
  613. UIImageView *leIgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, HEIGHT/2-10, 20, 20)];
  614. leIgView.image = image;
  615. leIgView.contentMode = UIViewContentModeScaleAspectFit;
  616. [leftView addSubview:leIgView];
  617. }
  618. - (void)showLine:(UIView *)view {
  619. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, view.frame.size.height-LINE_WH, view.frame.size.width, LINE_WH)];
  620. line.backgroundColor = THE_LINE_COLOR;
  621. [view addSubview:line];
  622. }
  623. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  624. [self.view endEditing:YES];
  625. }
  626. @end