123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- //
- // forgetPwdVC.m
- // shiku_im
- //
- // Created by flyeagleTang on 14-6-7.
- // Copyright (c) 2014年 Reese. All rights reserved.
- //
- #import "forgetPwdVC.h"
- #import "JXTelAreaListVC.h"
- #import "JXUserObject.h"
- #import "loginVC.h"
- #import "MD5Util.h"
- #define HEIGHT 50
- @interface forgetPwdVC () <UITextFieldDelegate>
- {
- UIButton *_areaCodeBtn;
- NSTimer* timer;
- JXUserObject *_user;
- UIImageView * _imgCodeImg;
- UITextField *_imgCode; //图片验证码
- UIButton * _graphicButton;
- }
- @end
- @implementation forgetPwdVC
- - (id)init
- {
- self = [super init];
- if (self) {
-
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- if (self.isModify) {
- // self.title = Localized(@"JX_UpdatePassWord");
- }else{
- // self.title = Localized(@"JX_ForgetPassWord");
- }
-
-
- _user = [JXUserObject sharedInstance];
- _seconds = 0;
- self.isGotoBack = YES;
- self.heightFooter = 0;
- self.heightHeader = JX_SCREEN_TOP;
- //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
- [self createHeadAndFoot];
- self.tableBody.backgroundColor = [UIColor whiteColor];
-
- UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, JX_SCREEN_WIDTH-30, 300)];
- baseView.backgroundColor = [UIColor whiteColor];
- baseView.layer.cornerRadius = 7.f;
- baseView.layer.masksToBounds = YES;
- [self.tableBody addSubview:baseView];
-
-
- CGFloat W = baseView.frame.size.width;
-
- int n = INSETS;
-
- /*
- JXLabel* lb;
- lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 50-n, 60, 30)];
- lb.textColor = [UIColor blackColor];
- lb.backgroundColor = [UIColor clearColor];
- lb.text = @"手机号";
- [self.tableBody addSubview:lb];
- [lb release];
-
- lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 100-n, 60, 30)];
- lb.textColor = [UIColor blackColor];
- lb.backgroundColor = [UIColor clearColor];
- lb.text = @"验证码";
- [self.tableBody addSubview:lb];
- [lb release];
-
- lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 150-n, 60, 30)];
- lb.textColor = [UIColor blackColor];
- lb.backgroundColor = [UIColor clearColor];
- lb.text = @"新密码";
- [self.tableBody addSubview:lb];
- [lb release];
-
- lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 200-n, 60, 30)];
- lb.textColor = [UIColor blackColor];
- lb.backgroundColor = [UIColor clearColor];
- lb.text = @"确认";
- [self.tableBody addSubview:lb];
- [lb release];*/
-
- UILabel *titleLable = [[UILabel alloc] init];
- titleLable.text = @"修改密码";
- titleLable.textColor = [UIColor blackColor];
- titleLable.font = [UIFont systemFontOfSize:30 weight:(UIFontWeightRegular)];
- [titleLable sizeToFit];
- titleLable.frame = CGRectMake(JX_SCREEN_WIDTH/2- titleLable.frame.size.width/2, 0, titleLable.frame.size.width, titleLable.frame.size.height);
- [titleLable sizeToFit];
- [self.tableBody addSubview:titleLable];
- n = n+titleLable.frame.size.height+INSETS;
- //区号
- if (!_phone) {
- _phone = [UIFactory createTextFieldWith:CGRectMake(15, n, W-30, HEIGHT) delegate:self returnKeyType:UIReturnKeyNext secureTextEntry:NO placeholder:Localized(@"JX_InputPhone") font:g_factory.font16];
- _phone.clearButtonMode = UITextFieldViewModeWhileEditing;
- _phone.borderStyle = UITextBorderStyleNone;
- [baseView addSubview:_phone];
-
- [self showLine:_phone];
- UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 67, HEIGHT)];
- _phone.leftView = leftView;
- _phone.leftViewMode = UITextFieldViewModeAlways;
- NSString *areaStr;
- if (![g_default objectForKey:kMY_USER_AREACODE]) {
- areaStr = @"+86";
- } else {
- areaStr = [NSString stringWithFormat:@"+%@",[g_default objectForKey:kMY_USER_AREACODE]];
- }
- _areaCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 41, HEIGHT)];
- [_areaCodeBtn setTitle:areaStr forState:UIControlStateNormal];
- _areaCodeBtn.titleLabel.font = SYSFONT(15);
- [_areaCodeBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
- //[_areaCodeBtn setImage:[UIImage imageNamed:@"down_arrow_black"] forState:UIControlStateNormal];
- _areaCodeBtn.custom_acceptEventInterval = 1.0f;
- //[_areaCodeBtn addTarget:self action:@selector(areaCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self resetBtnEdgeInsets:_areaCodeBtn];
- [leftView addSubview:_areaCodeBtn];
- UIView *verticalLine = [[UIView alloc] initWithFrame:CGRectMake(_areaCodeBtn.frame.size.width+7, HEIGHT/2 - 8, LINE_WH, 16)];
- verticalLine.backgroundColor = [UIColor clearColor]; //THE_LINE_COLOR;
- [leftView addSubview:verticalLine];
-
- }
- n = n+HEIGHT;
-
- // _code = [[UITextField alloc] initWithFrame:CGRectMake(INSETS,n,188,HEIGHT)];
- // _code.delegate = self;
- // _code.autocorrectionType = UITextAutocorrectionTypeNo;
- // _code.autocapitalizationType = UITextAutocapitalizationTypeNone;
- // _code.enablesReturnKeyAutomatically = YES;
- // _code.borderStyle = UITextBorderStyleRoundedRect;
- // _code.returnKeyType = UIReturnKeyDone;
- // _code.clearButtonMode = UITextFieldViewModeWhileEditing;
- // _code.placeholder = Localized(@"JX_InputMessageCode");
- // [self.tableBody addSubview:_code];
- //// [_code release];
- //
- // _send = [UIFactory createButtonWithTitle:Localized(@"JX_Send")
- // titleFont:g_factory.font14
- // titleColor:[UIColor whiteColor]
- // normal:@"feaBtn_backImg_sel"
- // highlight:@"feaBtn_backImg_sel" ];
- // [_send addTarget:self action:@selector(onSend) forControlEvents:UIControlEventTouchUpInside];
- // _send.frame = CGRectMake(JX_SCREEN_WIDTH-27-105+INSETS*2, n, 105, HEIGHT);
- // [self.tableBody addSubview:_send];
-
- if (!self.isModify) {
- //图片验证码
- // self.imgCodeView = [self customItemWith:Localized(@"JX_imageCode") currentY:currentY allLengthTop:YES bottomLine:YES labelWidth:_labelWidth];
- _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];
- _imgCode.clearButtonMode = UITextFieldViewModeWhileEditing;
- _imgCode.borderStyle = UITextBorderStyleNone;
- [baseView addSubview:_imgCode];
-
- [self showLine:_imgCode];
-
- _imgCode.layer.masksToBounds = YES;
- _imgCode.layer.cornerRadius = 4;
- // _imgCode = [[UITextField alloc] initWithFrame:CGRectMake(_labelWidth+20+5, 15, self.tableBody.frame.size.width-_labelWidth-20-5, 20)];
- // _imgCode.font = SYSFONT(15);
- // _imgCode.placeholder = Localized(@"JX_inputImgCode");
- // _imgCode.delegate = self;
- // [self.imgCodeView addSubview:_imgCode];
- [self createLeftViewWithImage:[UIImage imageNamed:@"verify"] superView:_imgCode];
- _imgCodeImg = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgCode.frame)+INSETS, 0, 70, 35)];
- _imgCodeImg.center = CGPointMake(_imgCodeImg.center.x, _imgCode.center.y);
- _imgCodeImg.userInteractionEnabled = YES;
- [baseView addSubview:_imgCodeImg];
-
- // _imgCodeImg.image = [UIImage imageNamed:@"refreshImgCode"];
- // UITapGestureRecognizer * tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getImgCodeImgGes:)];
- // [_imgCodeImg addGestureRecognizer:tapGes];
-
- _graphicButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _graphicButton.frame = CGRectMake(CGRectGetMaxX(_imgCodeImg.frame)+4, 7, 35, 35);
- _graphicButton.center = CGPointMake(_graphicButton.center.x,_imgCode.center.y);
- [_graphicButton setBackgroundImage:[UIImage imageNamed:@"refreshGraphic"] forState:UIControlStateNormal];
- [_graphicButton setBackgroundImage:[UIImage imageNamed:@"refreshGraphic"] forState:UIControlStateHighlighted];
- [_graphicButton addTarget:self action:@selector(refreshGraphicAction:) forControlEvents:UIControlEventTouchUpInside];
- [baseView addSubview:_graphicButton];
- n = n+HEIGHT;
-
-
- _code = [[UITextField alloc] initWithFrame:CGRectMake(15, n, W-110-30, HEIGHT)];
- _code.delegate = self;
- _code.autocorrectionType = UITextAutocorrectionTypeNo;
- _code.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _code.enablesReturnKeyAutomatically = YES;
- _code.font = g_factory.font16;
- // _code.borderStyle = UITextBorderStyleRoundedRect;
- _code.returnKeyType = UIReturnKeyDone;
- _code.clearButtonMode = UITextFieldViewModeWhileEditing;
- _code.placeholder = Localized(@"JX_InputMessageCode");
- [baseView addSubview:_code];
-
- [self showLine:_code];
-
- [self createLeftViewWithImage:[UIImage imageNamed:@"code"] superView:_code];
- _send = [UIFactory createButtonWithTitle:@"获取验证码"
- titleFont:g_factory.font16
- titleColor:HEXCOLOR(0x2A98FF)
- normal:nil
- highlight:nil ];
- [_send addTarget:self action:@selector(sendSMS) forControlEvents:UIControlEventTouchUpInside];
- // _send.backgroundColor = g_theme.themeColor;
- _send.titleLabel.font = SYSFONT(16);
- _send.frame = CGRectMake(W-110-30, n+HEIGHT/2-HEIGHT/2, 105, HEIGHT);
- _send.layer.cornerRadius = 7.f;
- _send.layer.masksToBounds = YES;
- [baseView addSubview:_send];
- [self showLine:_send];
- n = n+HEIGHT;
- }
-
-
- if (self.isModify) {
- _oldPwd = [[UITextField alloc] initWithFrame:CGRectMake(15,n,W-30,HEIGHT)];
- _oldPwd.delegate = self;
- _oldPwd.autocorrectionType = UITextAutocorrectionTypeNo;
- _oldPwd.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _oldPwd.enablesReturnKeyAutomatically = YES;
- // _oldPwd.borderStyle = UITextBorderStyleRoundedRect;
- _oldPwd.returnKeyType = UIReturnKeyDone;
- _oldPwd.clearButtonMode = UITextFieldViewModeWhileEditing;
- _oldPwd.placeholder = Localized(@"JX_InputOldPassWord");
- _oldPwd.secureTextEntry = YES;
- _oldPwd.font = g_factory.font16;
- [baseView addSubview:_oldPwd];
- [self showLine:_oldPwd];
- [self createLeftViewWithImage:[UIImage imageNamed:@"password"] superView:_oldPwd];
- n = n+HEIGHT;
-
- }
-
- if (!self.isPayPWD) {
-
- _pwd = [[UITextField alloc] initWithFrame:CGRectMake(15,n,W-30,HEIGHT)];
- _pwd.delegate = self;
- _pwd.autocorrectionType = UITextAutocorrectionTypeNo;
- _pwd.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _pwd.enablesReturnKeyAutomatically = YES;
- // _pwd.borderStyle = UITextBorderStyleRoundedRect;
- _pwd.returnKeyType = UIReturnKeyDone;
- _pwd.clearButtonMode = UITextFieldViewModeWhileEditing;
- _pwd.placeholder = Localized(@"JX_InputNewPassWord");
- _pwd.secureTextEntry = YES;
- _pwd.font = g_factory.font16;
- [baseView addSubview:_pwd];
-
- [self showLine:_pwd];
-
- [self createLeftViewWithImage:[UIImage imageNamed:@"password"] superView:_pwd];
- n = n+HEIGHT;
-
- _repeat = [[UITextField alloc] initWithFrame:CGRectMake(15,n,W-30,HEIGHT)];
- _repeat.delegate = self;
- _repeat.autocorrectionType = UITextAutocorrectionTypeNo;
- _repeat.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _repeat.enablesReturnKeyAutomatically = YES;
- // _repeat.borderStyle = UITextBorderStyleRoundedRect;
- _repeat.returnKeyType = UIReturnKeyDone;
- _repeat.clearButtonMode = UITextFieldViewModeWhileEditing;
- _repeat.placeholder = Localized(@"JX_ConfirmNewPassWord");
- _repeat.secureTextEntry = YES;
- _repeat.font = g_factory.font16;
- [self createLeftViewWithImage:[UIImage imageNamed:@"password"] superView:_repeat];
- [baseView addSubview:_repeat];
- [self showLine:_repeat];
-
- n = n+HEIGHT;
- }
-
- n += 30;
-
- UIButton* _btn = [UIFactory createCommonButton:Localized(@"JX_UpdatePassWord") target:self action:@selector(onClick:)];
- [_btn.titleLabel setFont:g_factory.font16];
- _btn.layer.masksToBounds = YES;
- _btn.layer.cornerRadius = 20.f;
- _btn.frame = CGRectMake(15, n, W-30, 40);
- [baseView addSubview:_btn];
-
-
- CGRect frame = baseView.frame;
- frame.size.height = CGRectGetMaxY(_btn.frame)+30;
- baseView.frame = frame;
-
-
- _phone.text = g_myself.phone;
- if (self.isModify) {
- _phone.enabled = NO;
- }else{
- if (_phone.text.length > 0) {
- [self getImgCodeImg];
- }
- }
-
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)refreshGraphicAction:(UIButton *)button{
- [self getImgCodeImg];
- }
- -(void)getImgCodeImg{
- if(_phone.text.length > 0){
- // if ([self checkPhoneNum]) {
- //请求图片验证码
- NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
- NSString * codeUrl = [g_server getImgCode:_phone.text areaCode:areaCode];
- NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:codeUrl] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
-
- [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
- if (!connectionError) {
- UIImage * codeImage = [UIImage imageWithData:data];
- if (codeImage != nil) {
- _imgCodeImg.image = codeImage;
- }else{
- [g_App showAlert:Localized(@"JX_ImageCodeFailed")];
- }
-
- }else{
- NSLog(@"%@",connectionError);
- [g_App showAlert:connectionError.localizedDescription];
- }
- }];
- // [_imgCodeImg sd_setImageWithURL:[NSURL URLWithString:codeUrl] placeholderImage:[UIImage imageNamed:@"refreshImgCode"] options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
- // if (!error) {
- // _imgCodeImg.image = image;
- // }else{
- // NSLog(@"%@",error);
- // }
- // }];
- }else{
-
- }
-
- }
- #pragma mark------验证
- -(void)onClick:(UIButton *)btn{
- btn.enabled = NO;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- btn.enabled = YES;
- });
- if([_phone.text length]<= 0){
- [g_App showAlert:Localized(@"JX_InputPhone")];
- return;
- }
- if (!self.isModify) {
- if([_code.text length]<4){
- //_code.text = @"1315";
- [g_App showAlert:Localized(@"JX_InputMessageCode")];
- return;
- }
- }
- if (self.isModify && [_oldPwd.text length] <= 0){
- [g_App showAlert:Localized(@"JX_InputPassWord")];
- return;
- }
-
- if (!self.isPayPWD) {
- if([_pwd.text length]<=0){
- [g_App showAlert:Localized(@"JX_InputPassWord")];
- return;
- }
- if ([_pwd.text length] < 6) {
- [g_App showAlert:Localized(@"JX_TurePasswordAlert")];
- return;
- }
- if([_repeat.text length]<=0){
- [g_App showAlert:Localized(@"JX_ConfirmPassWord")];
- return;
- }
- if(![_pwd.text isEqualToString:_repeat.text]){
- [g_App showAlert:Localized(@"JX_PasswordFiled")];
- return;
- }
-
- if ([_pwd.text isEqualToString:_oldPwd.text]) {
- [g_App showAlert:Localized(@"JX_PasswordOriginal")];
- return;
- }
- }
-
- // if([_smsCode length]<=0){
- // //忽略短信验证
- // //_smsCode = _code.text;
- // [g_App showAlert:@"请输入验证码"];
- // return;
- // }
- [self.view endEditing:YES];
- NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
- if (self.isModify){
- [_wait start];
-
- #ifdef IS_MsgEncrypt
- [g_server userGetRandomStr:self];
- #else
- [g_server updatePwd:_phone.text areaCode:areaCode oldPwd:_oldPwd.text newPwd:_pwd.text checkCode:nil toView:self];
- #endif
- }else{
-
- [_wait start];
- if (self.isPayPWD) {
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = time *1000 + g_server.timeDifference;
- NSString *salt = [NSString stringWithFormat:@"%ld",time];
- NSString *mac = [self getResetPayPWDMacWithSalt:salt];
- [g_server authkeysResetPayPasswordWithSalt:salt mac:mac toView:self];
- }else {
-
- [g_server resetPwd:_phone.text areaCode:areaCode randcode:_code.text newPwd:_pwd.text toView:self];
- }
-
- // BOOL b = YES;
- //
- // b = [_code.text isEqualToString:_smsCode];
- //
- // if(b){
- //
- // }
- // else
- // [g_App showAlert:Localized(@"inputPhoneVC_MsgCodeNotOK")];
- // [g_App showAlert:@"短信验证码不对"];
- }
-
- }
- - (NSString *)getResetPayPWDMacWithSalt:(NSString *)salt {
-
- NSMutableString *str = [NSMutableString string];
- [str appendString:APIKEY];
- [str appendString:g_myself.userId];
- [str appendString:g_server.access_token];
- [str appendString:salt];
-
- NSData *key = [MD5Util getMD5DataWithString:_code.text];
- NSData *macData = [g_securityUtil getHMACMD5:[str dataUsingEncoding:NSUTF8StringEncoding] key:key];
-
- NSString *mac = [macData base64EncodedStringWithOptions:0];
- return mac;
- }
- //验证手机号格式
- - (void)sendSMS{
- [_phone resignFirstResponder];
- [_imgCode resignFirstResponder];
- [_code resignFirstResponder];
-
- _send.enabled = NO;
- if (_imgCode.text.length < 3) {
- [g_App showAlert:Localized(@"JX_inputImgCode")];
- _send.enabled = YES;
- return;
- }
-
- [self onSend];
-
- // if([self isMobileNumber:_phone.text]){
- // //验证手机号码是否已注册
- // // [g_server verifyPhone:[NSString stringWithFormat:@"%@%@",[_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""],_phoneNumTextField.text] toView:self];
- //
- // //请求验证码
- //
- //
- // }else {
- // _send.enabled = YES;
- // }
- }
- //验证手机号码格式
- - (BOOL)isMobileNumber:(NSString *)number{
- if ([_phone.text length] == 0) {
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:Localized(@"JX_Tip") message:Localized(@"JX_InputPhone") delegate:nil cancelButtonTitle:Localized(@"JX_Confirm") otherButtonTitles:nil, nil];
- [alert show];
- // [alert release];
- return NO;
- }
-
- if ([_areaCodeBtn.titleLabel.text isEqualToString:@"+86"]) {
- NSString *regex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
- NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
- BOOL isMatch = [pred evaluateWithObject:number];
-
- if (!isMatch) {
- [g_App showAlert:Localized(@"inputPhoneVC_InputTurePhone")];
- // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:Localized(@"JXVerifyAccountVC_Prompt") message:Localized(@"JXVerifyAccountVC_PhoneNumberError") delegate:nil cancelButtonTitle:Localized(@"JXVerifyAccountVC_OK") otherButtonTitles:nil, nil];
- // [alert show];
- // [alert release];
- return NO;
- }
- }
- return YES;
- }
- -(void)onSend{
-
- if (!_send.selected) {
- [_wait start];
- NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
- // _user = [JXUserObject sharedInstance];
- _user.areaCode = areaCode;
- [g_server sendSMS:[NSString stringWithFormat:@"%@",_phone.text] areaCode:areaCode isRegister:NO imgCode:_imgCode.text toView:self];
- }
-
- }
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
- [_wait stop];
- if([aDownload.action isEqualToString:act_SendSMS]){
- _send.enabled = YES;
- _send.selected = YES;
- _send.userInteractionEnabled = NO;
- _send.backgroundColor = [UIColor grayColor];
- _smsCode = [[dict objectForKey:@"code"] copy];
- [_send setTitle:@"60s" forState:UIControlStateSelected];
- [_send setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
- _seconds = 60;
- timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showTime:) userInfo:_send repeats:YES];
- }
- if([aDownload.action isEqualToString:act_PwdUpdate] || [aDownload.action isEqualToString:act_PwdUpdateV1]){
- [g_App showAlert:Localized(@"JX_UpdatePassWordOK")];
- g_myself.password = [g_server getMD5String:_pwd.text];
- [g_default setObject:[g_server getMD5String:_pwd.text] forKey:kMY_USER_PASSWORD];
- [g_default synchronize];
- [self actionQuit];
- [self relogin];
- }
- if([aDownload.action isEqualToString:act_PwdReset] || [aDownload.action isEqualToString:act_PwdResetV1]){
- [g_App showAlert:Localized(@"JX_UpdatePassWordOK")];
- g_myself.password = [g_server getMD5String:_pwd.text];
- [g_default setObject:[g_server getMD5String:_pwd.text] forKey:kMY_USER_PASSWORD];
- [g_default synchronize];
- [self actionQuit];
- }
-
- if ([aDownload.action isEqualToString:act_UserGetRandomStr]) {
-
- NSString *checkCode = nil;
- #ifdef IS_MsgEncrypt
- NSString *userRandomStr = [dict objectForKey:@"userRandomStr"];
- SecKeyRef privateKey = [g_securityUtil getRSAKeyWithBase64Str:g_msgUtil.rsaPrivateKey isPrivateKey:YES];
- NSData *randomData = [[NSData alloc] initWithBase64EncodedString:userRandomStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
- NSData *codeData = [g_securityUtil decryptMessageRSA:randomData withPrivateKey:privateKey];
- checkCode = [[NSString alloc] initWithData:codeData encoding:NSUTF8StringEncoding];
- #endif
-
- NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
- [g_server updatePwd:_phone.text areaCode:areaCode oldPwd:_oldPwd.text newPwd:_pwd.text checkCode:checkCode toView:self];
- }
-
- if ([aDownload.action isEqualToString:act_AuthkeysResetPayPassword]) {
- if ([self.delegate respondsToSelector:@selector(forgetPwdSuccess)]) {
- [self actionQuit];
- [self.delegate forgetPwdSuccess];
- }
- }
-
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
- if([aDownload.action isEqualToString:act_SendSMS]){
- [_send setTitle:Localized(@"JX_SendAngin") forState:UIControlStateNormal];
- _send.enabled = YES;
- }else if ([aDownload.action isEqualToString:act_PwdUpdate] || [aDownload.action isEqualToString:act_PwdUpdateV1]) {
- NSString *error = [dict objectForKey:@"resultMsg"];
-
- [g_App showAlert:[NSString stringWithFormat:@"%@",error]];
-
- return hide_error;
- }
-
- [_wait stop];
- return show_error;
- }
- -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
- [_wait stop];
- _send.enabled = YES;
- return show_error;
- }
- -(void) didServerConnectStart:(JXConnection*)aDownload{
- [_wait stop];
- }
- -(void)showTime:(NSTimer*)sender{
- UIButton *but = (UIButton*)[timer userInfo];
- _seconds--;
- [but setTitle:[NSString stringWithFormat:@"%ds",_seconds] forState:UIControlStateSelected];
- if(_seconds<=0){
- but.selected = NO;
- but.userInteractionEnabled = YES;
- but.backgroundColor = g_theme.themeColor;
- [_send setTitle:Localized(@"JX_SendAngin") forState:UIControlStateNormal];
- if (timer) {
- timer = nil;
- [sender invalidate];
- }
- _seconds = 60;
-
- }
- }
- -(void)textFieldDidEndEditing:(UITextField *)textField{
- if (textField == _phone) {
- [self getImgCodeImg];
- }
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
-
- if (_phone == textField) {
- return [self validateNumber:string];
- }
- return YES;
- }
- - (BOOL)validateNumber:(NSString*)number {
- // 只能使用字母和数字
- NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet];
- NSString *filtered = [[number componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
- return [number isEqualToString:filtered];
-
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [self.view endEditing:YES];
- return YES;
- }
- - (void)areaCodeBtnClick:(UIButton *)but{
- [self.view endEditing:YES];
- JXTelAreaListVC *telAreaListVC = [[JXTelAreaListVC alloc] init];
- telAreaListVC.telAreaDelegate = self;
- telAreaListVC.didSelect = @selector(didSelectTelArea:);
- // [g_window addSubview:telAreaListVC.view];
- [g_navigation pushViewController:telAreaListVC animated:YES];
- }
- - (void)didSelectTelArea:(NSString *)areaCode{
- [_areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@",areaCode] forState:UIControlStateNormal];
- [self resetBtnEdgeInsets:_areaCodeBtn];
- }
- - (void)resetBtnEdgeInsets:(UIButton *)btn{
- [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width-2, 0, btn.imageView.frame.size.width+2)];
- [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width+2, 0, -btn.titleLabel.frame.size.width-2)];
- }
- -(void)relogin{
- [g_default removeObjectForKey:kMY_USER_PASSWORD];
- [g_default removeObjectForKey:kMY_USER_TOKEN];
- [share_defaults removeObjectForKey:kMY_ShareExtensionToken];
- // [g_default setObject:nil forKey:kMY_USER_TOKEN];
- g_server.access_token = nil;
-
- [g_notify postNotificationName:kSystemLogoutNotifaction object:nil];
- [[JXXMPP sharedInstance] logout];
- NSLog(@"XMPP ---- forgetPwdVC relogin");
-
- loginVC* vc = [loginVC alloc];
- vc.isAutoLogin = NO;
- vc.isSwitchUser= NO;
- vc = [vc init];
- [g_mainVC.view removeFromSuperview];
- g_mainVC = nil;
- [self.view removeFromSuperview];
- self.view = nil;
-
- g_navigation.rootViewController = vc;
- // g_navigation.lastVC = nil;
- // [g_navigation.subViews removeAllObjects];
- // [g_navigation pushViewController:vc];
- // g_App.window.rootViewController = vc;
- // [g_App.window makeKeyAndVisible];
-
- // loginVC* vc = [loginVC alloc];
- // vc.isAutoLogin = NO;
- // vc.isSwitchUser= NO;
- // vc = [vc init];
- // [g_window addSubview:vc.view];
- // [self actionQuit];
- // [_wait performSelector:@selector(stop) withObject:nil afterDelay:1];
- [_wait stop];
- #if TAR_IM
- #ifdef Meeting_Version
- [g_meeting stopMeeting];
- #endif
- #endif
- }
- - (void)createLeftViewWithImage:(UIImage *)image superView:(UITextField *)textField {
- UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 27, HEIGHT)];
- textField.leftView = leftView;
- textField.leftViewMode = UITextFieldViewModeAlways;
- UIImageView *leIgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, HEIGHT/2-10, 20, 20)];
- leIgView.image = image;
- leIgView.contentMode = UIViewContentModeScaleAspectFit;
- [leftView addSubview:leIgView];
- }
- - (void)showLine:(UIView *)view {
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, view.frame.size.height-LINE_WH, view.frame.size.width, LINE_WH)];
- line.backgroundColor = THE_LINE_COLOR;
- [view addSubview:line];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self.view endEditing:YES];
- }
- @end
|