loginVC.m 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. //
  2. // loginVC.m
  3. // shiku_im
  4. //
  5. // Created by flyeagleTang on 14-6-7.
  6. // Copyright (c) 2014年 Reese. All rights reserved.
  7. //
  8. #import "loginVC.h"
  9. #import "forgetPwdVC.h"
  10. #import "inputPhoneVC.h"
  11. #import "PSRegisterBaseVC.h"
  12. #import "JXMainViewController.h"
  13. #import "JXTelAreaListVC.h"
  14. #import "QCheckBox.h"
  15. #import "webpageVC.h"
  16. #import "JXLocation.h"
  17. #import "WXApi.h"
  18. #import "JXLabelObject.h"
  19. #import "JLBubbleModel.h"
  20. #import <TencentOpenAPI/TencentOAuth.h>
  21. #import <TencentOpenAPI/QQApiInterface.h>
  22. #import "JXShareAnQuanView.h"
  23. #define HEIGHT 35
  24. #define tyCurrentWindow [[UIApplication sharedApplication].windows firstObject]
  25. @interface loginVC ()<UITextFieldDelegate,QCheckBoxDelegate,JXLocationDelegate,JXLocationDelegate,WXApiDelegate,WXApiManagerDelegate,TencentSessionDelegate,TencentLoginDelegate>
  26. {
  27. UIButton *_areaCodeBtn;
  28. QCheckBox * _checkProtocolBtn;
  29. UIButton *_forgetBtn;
  30. BOOL _isFirstLocation;
  31. NSString *_myToken;
  32. //短信验证码登录
  33. UIButton *_switchLogin; //切换登录方式
  34. UIImageView * _imgCodeImg;
  35. UITextField *_imgCode; //图片验证码
  36. UIButton *_send; //发送短信
  37. UIButton * _graphicButton;
  38. NSString* _smsCode;
  39. int _seconds;
  40. NSTimer *_timer;
  41. NSInteger setServerNum;
  42. }
  43. @property(nonatomic,strong)dispatch_source_t authTimer;
  44. @property(nonatomic,assign)NSInteger count;
  45. @property(nonatomic,strong)UIView *waitAuthView;
  46. @property (nonatomic, retain)TencentOAuth *oauth;
  47. @property (nonatomic,strong) JXShareAnQuanView *vc;
  48. @property (nonatomic,copy) NSString *security;
  49. @end
  50. @implementation loginVC
  51. - (void)backBtnCLick{
  52. [g_navigation dismissViewController:self animated:NO];
  53. }
  54. - (id)init
  55. {
  56. self = [super init];
  57. if (self) {
  58. // _pSelf = self;
  59. _user = [[JXUserObject alloc] init];
  60. // self.isGotoBack = self.isSwitchUser;
  61. // self.title = Localized(@"JX_Login");
  62. self.heightFooter = 0;
  63. // self.heightHeader = JX_SCREEN_TOP;
  64. self.heightHeader = 0;
  65. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  66. if (_isThirdLogin) {
  67. // self.isGotoBack = YES;
  68. // self.title = Localized(@"JX_BindNo.");
  69. self.title = Localized(@"JX_BindExistingAccount");
  70. }
  71. if (self.isSMSLogin) {
  72. self.title = Localized(@"JX_SMSLogin");
  73. self.isGotoBack = YES;
  74. }
  75. [g_server getAppResource:@"0" ToView:self];
  76. [g_server customerLinkList:self];
  77. // 获取所有气泡
  78. [g_server getAllBubbleFontListToView:self];
  79. // 获取所有等级
  80. // [g_server getAllGradeListToView:self];
  81. g_server.isManualLogin = NO;
  82. [self createHeadAndFoot];
  83. self.tableBody.backgroundColor = [UIColor clearColor];
  84. UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.tableBody.bounds];
  85. imageView.contentMode = UIViewContentModeScaleAspectFill;
  86. // imageView.image = [UIImage imageNamed:@"new_login_bg"];
  87. imageView.backgroundColor=[UIColor whiteColor];
  88. [self.tableBody addSubview:imageView];
  89. self.isGotoBack = NO;
  90. _myToken = [g_default objectForKey:kMY_USER_TOKEN];
  91. [g_default setObject:nil forKey:kMyPayPrivateKey];
  92. int n = INSETS;
  93. g_server.isLogin = NO;
  94. g_navigation.lastVC = nil;
  95. UIButton * backBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 40, 44, 44)];
  96. [backBtn setImage:[UIImage imageNamed:@"photo_title_back_black"] forState:UIControlStateNormal];
  97. [self.view addSubview:backBtn];
  98. [backBtn addTarget:self action:@selector(backBtnCLick) forControlEvents:UIControlEventTouchUpInside];
  99. #if IS_SetupServer
  100. // Localized(@"JX_SetupServer")
  101. UIButton* btn = [UIFactory createButtonWithTitle:@"" titleFont:[UIFont systemFontOfSize:15] titleColor:[UIColor whiteColor] normal:nil highlight:nil];
  102. [btn setTitleColor:THESIMPLESTYLE ? [UIColor blackColor] : [UIColor whiteColor] forState:UIControlStateNormal];
  103. btn.backgroundColor = [UIColor clearColor];
  104. [btn addTarget:self action:@selector(onSetting) forControlEvents:UIControlEventTouchUpInside];
  105. btn.frame = CGRectMake(JX_SCREEN_WIDTH-88, JX_SCREEN_TOP - 38, 83, 30);
  106. btn.hidden = _isThirdLogin || self.isSMSLogin;
  107. //[self.tableHeader addSubview:btn];
  108. setServerNum = 0;
  109. #endif
  110. n += 50;
  111. //icon
  112. UIImageView * kuliaoIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ALOGO_1200"]];
  113. kuliaoIconView.frame = CGRectMake((JX_SCREEN_WIDTH-100)/2, n+20, 100, 100);
  114. // [self.tableBody addSubview:kuliaoIconView];
  115. UILabel *titleLable = [[UILabel alloc] init];
  116. titleLable.text = @"手机号登录";
  117. titleLable.textColor = kRGBColor51;
  118. titleLable.font = [UIFont systemFontOfSize:30 weight:(UIFontWeightBlack)];
  119. [titleLable sizeToFit];
  120. titleLable.frame = CGRectMake(JX_SCREEN_WIDTH/2- titleLable.frame.size.width/2, JX_SCREEN_TOP, titleLable.frame.size.width, titleLable.frame.size.height);
  121. [titleLable sizeToFit];
  122. [self.tableBody addSubview:titleLable];
  123. //title
  124. NSString * titleStr;
  125. #if TAR_IM
  126. titleStr = APP_NAME;
  127. //#elif TAR_LIVE
  128. // NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  129. // // app名称
  130. // titleStr = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  131. #endif
  132. // UILabel * kuliaoTitleLabel = [UIFactory createLabelWith:CGRectMake(0, CGRectGetMaxY(kuliaoIconView.frame), 100, 35) text:titleStr font:g_factory.font20 textColor:[UIColor blackColor] backgroundColor:[UIColor clearColor]];
  133. // kuliaoTitleLabel.center = CGPointMake(kuliaoIconView.center.x, kuliaoTitleLabel.center.y);
  134. // kuliaoTitleLabel.textAlignment = NSTextAlignmentCenter;
  135. // [self.tableBody addSubview:kuliaoTitleLabel];
  136. // UIButton* lb;
  137. /*
  138. lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 100, 60, 30)];
  139. lb.textColor = [UIColor blackColor];
  140. lb.backgroundColor = [UIColor clearColor];
  141. lb.text = @"手机:";
  142. [self.tableBody addSubview:lb];
  143. [lb release];
  144. lb = [[JXLabel alloc]initWithFrame:CGRectMake(10, 150, 60, 30)];
  145. lb.textColor = [UIColor blackColor];
  146. lb.backgroundColor = [UIColor clearColor];
  147. lb.text = @"密码:";
  148. [self.tableBody addSubview:lb];
  149. [lb release];*/
  150. //(INSETS, n, self_width-INSETS-INSETS, HEIGHT)
  151. n += 143;
  152. //区号
  153. if (!_phone) {
  154. if ([g_config.regeditPhoneOrName intValue] != 1) {
  155. _phone = [UIFactory createTextFieldWith:CGRectMake(40, n, JX_SCREEN_WIDTH-40*2, HEIGHT) delegate:self returnKeyType:UIReturnKeyNext secureTextEntry:NO placeholder:Localized(@"JX_InputPhone") font:g_factory.font16];
  156. _phone.attributedPlaceholder = [[NSAttributedString alloc] initWithString:Localized(@"JX_InputPhone") attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  157. _phone.keyboardType = UIKeyboardTypeDefault;
  158. }else {
  159. _phone = [UIFactory createTextFieldWith:CGRectMake(40, n, JX_SCREEN_WIDTH-40*2, HEIGHT) delegate:self returnKeyType:UIReturnKeyNext secureTextEntry:NO placeholder:Localized(@"JX_InputUserAccount") font:g_factory.font16];
  160. _phone.attributedPlaceholder = [[NSAttributedString alloc] initWithString:Localized(@"JX_InputUserAccount") attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  161. _phone.keyboardType = UIKeyboardTypeNumberPad;
  162. }
  163. _phone.borderStyle = UITextBorderStyleNone;
  164. _phone.clearButtonMode = UITextFieldViewModeWhileEditing;
  165. UIImage *textFieldBgImage = [UIImage imageNamed:@"new_login_button_bg.png"];
  166. [_phone setBackground:textFieldBgImage];
  167. // _phone.keyboardType = UIKeyboardTypeNumberPad;
  168. [self.tableBody addSubview:_phone];
  169. [_phone addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  170. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 37, HEIGHT)];
  171. _phone.leftView = leftView;
  172. _phone.leftViewMode = UITextFieldViewModeAlways;
  173. UIImageView *phIgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, HEIGHT/2-11, 22, 22)];
  174. phIgView.image = [UIImage imageNamed:@"account"];
  175. phIgView.contentMode = UIViewContentModeScaleAspectFit;
  176. [leftView addSubview:phIgView];
  177. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT-LINE_WH, _phone.frame.size.width, LINE_WH)];
  178. line.backgroundColor = THE_LINE_COLOR;
  179. [_phone addSubview:line];
  180. UIView *riPhView = [[UIView alloc] initWithFrame:CGRectMake(_phone.frame.size.width-44, 0, HEIGHT, HEIGHT)];
  181. _phone.rightView = riPhView;
  182. _phone.rightViewMode = UITextFieldViewModeAlways;
  183. [_phone addTarget:self action:@selector(longLimit:) forControlEvents:UIControlEventEditingChanged];
  184. NSString *areaStr;
  185. if (![g_default objectForKey:kMY_USER_AREACODE]) {
  186. areaStr = @"+86";
  187. } else {
  188. areaStr = [NSString stringWithFormat:@"+%@",[g_default objectForKey:kMY_USER_AREACODE]];
  189. }
  190. _areaCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, HEIGHT/2-11, HEIGHT-5, 22)];
  191. [_areaCodeBtn setTitle:areaStr forState:UIControlStateNormal];
  192. _areaCodeBtn.titleLabel.font = SYSFONT(16);
  193. [_areaCodeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  194. // [_areaCodeBtn setImage:[UIImage imageNamed:@"account"] forState:UIControlStateNormal];
  195. _areaCodeBtn.custom_acceptEventInterval = 1.0f;
  196. //[_areaCodeBtn addTarget:self action:@selector(areaCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  197. [self resetBtnEdgeInsets:_areaCodeBtn];
  198. [riPhView addSubview:_areaCodeBtn];
  199. }
  200. //账号
  201. // _phone = [[UITextField alloc] initWithFrame:CGRectMake(50, n+170, JX_SCREEN_WIDTH-50*2, HEIGHT)];
  202. // _phone.delegate = self;
  203. // _phone.autocorrectionType = UITextAutocorrectionTypeNo;
  204. // _phone.autocapitalizationType = UITextAutocapitalizationTypeNone;
  205. // _phone.enablesReturnKeyAutomatically = YES;
  206. // _phone.borderStyle = UITextBorderStyleRoundedRect;
  207. // _phone.returnKeyType = UIReturnKeyDone;
  208. // _phone.clearButtonMode = UITextFieldViewModeWhileEditing;
  209. // _phone.placeholder = Localized(@"JX_InputPhone");
  210. // _phone.userInteractionEnabled = YES;
  211. // [_phone addTarget:self action:@selector(longLimit:) forControlEvents:UIControlEventEditingChanged];
  212. // [self.tableBody addSubview:_phone];
  213. // [_phone release];
  214. n = n+HEIGHT;
  215. //监听账号是否被删除
  216. //
  217. // UIImageView *leftView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 34, 30)];
  218. // leftView.image = [UIImage imageNamed:@"userhead"];
  219. // leftView.contentMode = UIViewContentModeScaleAspectFit;
  220. // _phone.leftView = leftView;
  221. // _phone.leftViewMode = UITextFieldViewModeAlways;
  222. if (self.isSMSLogin) {
  223. //图片验证码
  224. _imgCode = [UIFactory createTextFieldWith:CGRectMake(40, n, JX_SCREEN_WIDTH-40*2-70-INSETS-35-4, HEIGHT) delegate:self returnKeyType:UIReturnKeyNext secureTextEntry:NO placeholder:Localized(@"JX_inputImgCode") font:g_factory.font16];
  225. _imgCode.attributedPlaceholder = [[NSAttributedString alloc] initWithString:Localized(@"JX_inputImgCode") attributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]}];
  226. _imgCode.borderStyle = UITextBorderStyleNone;
  227. _imgCode.clearButtonMode = UITextFieldViewModeWhileEditing;
  228. [self.tableBody addSubview:_imgCode];
  229. UIView *imCView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 37, HEIGHT)];
  230. _imgCode.leftView = imCView;
  231. _imgCode.leftViewMode = UITextFieldViewModeAlways;
  232. UIImageView *imCIView = [[UIImageView alloc] initWithFrame:CGRectMake(2, HEIGHT/2-11, 22, 22)];
  233. imCIView.image = [UIImage imageNamed:@"verify"];
  234. imCIView.contentMode = UIViewContentModeScaleAspectFit;
  235. [imCView addSubview:imCIView];
  236. UIView *imCLine = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT-LINE_WH, _phone.frame.size.width, LINE_WH)];
  237. imCLine.backgroundColor = THE_LINE_COLOR;
  238. [_imgCode addSubview:imCLine];
  239. _imgCodeImg = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgCode.frame)+INSETS, 0, 70, 35)];
  240. _imgCodeImg.center = CGPointMake(_imgCodeImg.center.x, _imgCode.center.y);
  241. _imgCodeImg.userInteractionEnabled = YES;
  242. [self.tableBody addSubview:_imgCodeImg];
  243. UIView *imgCodeLine = [[UIView alloc] initWithFrame:CGRectMake(_imgCodeImg.frame.size.width, 3, LINE_WH, _imgCodeImg.frame.size.height-6)];
  244. imgCodeLine.backgroundColor = THE_LINE_COLOR;
  245. [_imgCodeImg addSubview:imgCodeLine];
  246. _graphicButton = [UIButton buttonWithType:UIButtonTypeCustom];
  247. _graphicButton.frame = CGRectMake(CGRectGetMaxX(_imgCodeImg.frame)+6, 7, 26, 26);
  248. _graphicButton.center = CGPointMake(_graphicButton.center.x,_imgCode.center.y);
  249. [_graphicButton setBackgroundImage:[UIImage imageNamed:@"refreshGraphic"] forState:UIControlStateNormal];
  250. [_graphicButton setBackgroundImage:[UIImage imageNamed:@"refreshGraphic"] forState:UIControlStateHighlighted];
  251. [_graphicButton addTarget:self action:@selector(refreshGraphicAction:) forControlEvents:UIControlEventTouchUpInside];
  252. [self.tableBody addSubview:_graphicButton];
  253. n = n+HEIGHT;
  254. }
  255. n = n+HEIGHT;
  256. //密码
  257. _pwd = [[UITextField alloc] initWithFrame:CGRectMake(40, n, JX_SCREEN_WIDTH-40*2, HEIGHT)];
  258. _pwd.delegate = self;
  259. _pwd.font = g_factory.font16;
  260. _pwd.autocorrectionType = UITextAutocorrectionTypeNo;
  261. _pwd.autocapitalizationType = UITextAutocapitalizationTypeNone;
  262. _pwd.enablesReturnKeyAutomatically = YES;
  263. // _pwd.borderStyle = UITextBorderStyleRoundedRect;
  264. _pwd.returnKeyType = UIReturnKeyDone;
  265. _pwd.clearButtonMode = UITextFieldViewModeWhileEditing;
  266. _pwd.attributedPlaceholder = [[NSAttributedString alloc] initWithString:Localized(@"JX_InputPassWord") attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  267. _pwd.secureTextEntry = !self.isSMSLogin;
  268. _pwd.userInteractionEnabled = YES;
  269. UIImage *textFieldBgImage = [UIImage imageNamed:@"new_login_button_bg.png"];
  270. [_pwd setBackground:textFieldBgImage];
  271. [self.tableBody addSubview:_pwd];
  272. // UIView *line = [[UIView alloc] initWithFrame:CGRectMake(40,n+1, JX_SCREEN_WIDTH-40*2, 1)];
  273. // line.backgroundColor = HEXCOLOR(0xD6D6D6);
  274. // [_pwd addSubview:line];
  275. // //忘记密码
  276. // UIButton *lbUser = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-60-50, n+10, 70, 20)];
  277. // [lbUser setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  278. // [lbUser setTitle:Localized(@"JX_ForgetPassWord") forState:UIControlStateNormal];
  279. // lbUser.titleLabel.font = g_factory.font16;
  280. // lbUser.custom_acceptEventInterval = 1.0f;
  281. // [lbUser addTarget:self action:@selector(onForget) forControlEvents:UIControlEventTouchUpInside];
  282. // lbUser.titleEdgeInsets = UIEdgeInsetsMake(0, -27, 0, 0);
  283. // [self.tableBody addSubview:lbUser];
  284. // _forgetBtn = lbUser;
  285. if (self.isSMSLogin) {
  286. _pwd.attributedPlaceholder = [[NSAttributedString alloc] initWithString:Localized(@"JX_InputMessageCode") attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  287. _send = [UIFactory createButtonWithTitle:Localized(@"JX_Send")
  288. titleFont:g_factory.font16
  289. titleColor:[UIColor whiteColor]
  290. normal:nil
  291. highlight:nil ];
  292. _send.frame = CGRectMake(JX_SCREEN_WIDTH-70-40-11, n+HEIGHT/2-15, 70, 30);
  293. [_send addTarget:self action:@selector(sendSMS) forControlEvents:UIControlEventTouchUpInside];
  294. _send.backgroundColor = g_theme.themeColor;
  295. _send.layer.masksToBounds = YES;
  296. _send.layer.cornerRadius = 7.f;
  297. [self.tableBody addSubview:_send];
  298. }else {
  299. UIView *eyeView = [[UIView alloc]initWithFrame:CGRectMake(_pwd.frame.size.width-HEIGHT, 0, HEIGHT, HEIGHT)];
  300. _pwd.rightView = eyeView;
  301. _pwd.rightViewMode = UITextFieldViewModeAlways;
  302. UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, HEIGHT/2-6.5, 21, 13)];
  303. [rightBtn setBackgroundImage:[UIImage imageNamed:@"ic_password_hide"] forState:UIControlStateNormal];
  304. [rightBtn setBackgroundImage:[UIImage imageNamed:@"ic_password_display"] forState:UIControlStateSelected];
  305. [rightBtn addTarget:self action:@selector(passWordRightViewClicked:) forControlEvents:UIControlEventTouchUpInside];
  306. [eyeView addSubview:rightBtn];
  307. }
  308. n = n+HEIGHT+INSETS;
  309. UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 37, HEIGHT)];
  310. _pwd.leftView = rightView;
  311. _pwd.leftViewMode = UITextFieldViewModeAlways;
  312. UIImageView *riIgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, HEIGHT/2-11, 22, 22)];
  313. riIgView.image = [UIImage imageNamed:@"password"];
  314. riIgView.contentMode = UIViewContentModeScaleAspectFit;
  315. [rightView addSubview:riIgView];
  316. UIView *verticalLine = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT-LINE_WH, _pwd.frame.size.width, LINE_WH)];
  317. verticalLine.backgroundColor = THE_LINE_COLOR;
  318. [_pwd addSubview:verticalLine];
  319. n += 6;
  320. //注册用户
  321. CGSize size =[Localized(@"JX_Register") boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font16} context:nil].size;
  322. // UIButton *lb = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-40-(140 - (140 - size.width) / 2), n, 140, 20)];
  323. UIButton *lb = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-14-(140 - (140 - size.width) / 2), 40, 140, 20)];
  324. lb.titleLabel.font = g_factory.font24;
  325. [lb setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  326. [lb setTitle:@"注册" forState:UIControlStateNormal];
  327. lb.custom_acceptEventInterval = 1.0f;
  328. [lb addTarget:self action:@selector(onRegister) forControlEvents:UIControlEventTouchUpInside];
  329. lb.hidden = self.isSMSLogin;
  330. [self.tableBody addSubview:lb];
  331. if (!self.isSMSLogin) {
  332. n = n+36;
  333. }
  334. if (![[g_default objectForKey:@"agreement"] boolValue]) { //用户协议
  335. UIView * protocolView = [[UIView alloc] init];
  336. [self.tableBody addSubview:protocolView];
  337. //
  338. // UIButton * catProtocolbtn = [UIButton buttonWithType:UIButtonTypeSystem];
  339. // catProtocolbtn.frame = CGRectMake(0, 0, protocolView.frame.size.width, 25);
  340. NSString * agreeStr = @"登录注册代表同意";
  341. NSString * protocolStr = Localized(@"JX_ShikuProtocolTitle");
  342. // NSString * agreeProtocolStr = [NSString stringWithFormat:@"%@%@",agreeStr,protocolStr];
  343. // NSMutableAttributedString* tncString = [[NSMutableAttributedString alloc] initWithString:agreeProtocolStr];
  344. //
  345. // [tncString addAttribute:NSUnderlineStyleAttributeName
  346. // value:@(NSUnderlineStyleSingle)
  347. // range:(NSRange){agreeStr.length,[protocolStr length]}];
  348. // [tncString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(agreeStr.length,[protocolStr length])];
  349. // [tncString addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0,agreeStr.length)];
  350. // [tncString addAttribute:NSUnderlineColorAttributeName value:[UIColor blueColor] range:(NSRange){agreeStr.length,[protocolStr length]}];
  351. // [catProtocolbtn setAttributedTitle:tncString forState:UIControlStateNormal];
  352. // [catProtocolbtn addTarget:self action:@selector(catUserProtocol) forControlEvents:UIControlEventTouchUpInside];
  353. // [protocolView addSubview:catProtocolbtn];
  354. UIButton *agrBtn = [[UIButton alloc] init];
  355. agrBtn.titleLabel.font = SYSFONT(13);
  356. CGSize agreSize = [agreeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:agrBtn.titleLabel.font} context:nil].size;
  357. agrBtn.frame = CGRectMake(0, 0, agreSize.width, agreSize.height);
  358. [agrBtn setTitle:agreeStr forState:UIControlStateNormal];
  359. [agrBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  360. [agrBtn addTarget:self
  361. action:@selector(agrBtnAction:)
  362. forControlEvents:UIControlEventTouchUpInside];
  363. [protocolView addSubview:agrBtn];
  364. UILabel *protocolLab = [[UILabel alloc] init];
  365. protocolLab.font = SYSFONT(13);
  366. CGSize proSize = [protocolStr boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:protocolLab.font} context:nil].size;
  367. protocolLab.frame = CGRectMake(CGRectGetMaxX(agrBtn.frame), 0, proSize.width, proSize.height);
  368. protocolLab.textColor = HEXCOLOR(0x2A98FF);
  369. NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone]};
  370. NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:protocolStr attributes:attribtDic];
  371. protocolLab.attributedText = attribtStr;
  372. [protocolView addSubview:protocolLab];
  373. protocolLab.userInteractionEnabled = YES;
  374. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(catUserProtocol)];
  375. [protocolLab addGestureRecognizer:tap];
  376. NSString *agreeStr1 = @"和";
  377. UIButton *agrBtn1 = [[UIButton alloc] init];
  378. agrBtn1.titleLabel.font = SYSFONT(13);
  379. CGSize agreSize1 = [agreeStr1 boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:agrBtn1.titleLabel.font} context:nil].size;
  380. agrBtn1.frame = CGRectMake(CGRectGetMaxX(protocolLab.frame), 0, agreSize1.width, agreSize1.height);
  381. [agrBtn1 setTitle:agreeStr1 forState:UIControlStateNormal];
  382. [agrBtn1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  383. [agrBtn1 addTarget:self
  384. action:@selector(agrBtnAction:)
  385. forControlEvents:UIControlEventTouchUpInside];
  386. [protocolView addSubview:agrBtn1];
  387. NSString *protocolStr1 = @"隐私政策";
  388. UILabel *protocolLab1 = [[UILabel alloc] init];
  389. protocolLab1.font = SYSFONT(13);
  390. CGSize proSize1 = [protocolStr1 boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:protocolLab1.font} context:nil].size;
  391. protocolLab1.frame = CGRectMake(CGRectGetMaxX(agrBtn1.frame), 0, proSize1.width, proSize1.height);
  392. protocolLab1.textColor = HEXCOLOR(0x2A98FF);
  393. NSDictionary *attribtDic1 = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone]};
  394. NSMutableAttributedString *attribtStr1 = [[NSMutableAttributedString alloc]initWithString:protocolStr1 attributes:attribtDic1];
  395. protocolLab1.attributedText = attribtStr1;
  396. [protocolView addSubview:protocolLab1];
  397. protocolLab1.userInteractionEnabled = YES;
  398. UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(catUserProtocol)];
  399. [protocolLab1 addGestureRecognizer:tap1];
  400. CGFloat w = agreSize.width+proSize.width+agreSize1.width+proSize1.width;
  401. protocolView.frame = CGRectMake((JX_SCREEN_WIDTH -w)/2, n-30, w, 25);
  402. _checkProtocolBtn = [[QCheckBox alloc] initWithDelegate:self];
  403. // [self.tableBody addSubview:_checkProtocolBtn];
  404. _checkProtocolBtn.frame = CGRectMake((JX_SCREEN_WIDTH -w)/2-20, n, 20, 20);
  405. // CGSize size = [agreeProtocolStr boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:catProtocolbtn.titleLabel.font} context:nil].size;
  406. // _checkProtocolBtn.frame = CGRectMake((catProtocolbtn.frame.size.width - size.width) / 2 - 28, 3, 20, 20);
  407. n+=25;
  408. }
  409. n+=80;
  410. //登陆按钮
  411. _btn = [UIFactory createCommonButton:@"同意协议并登录" target:self action:@selector(onClick)];
  412. _btn.custom_acceptEventInterval = 1.0f;
  413. [_btn.titleLabel setFont:g_factory.font16];
  414. _btn.layer.cornerRadius = 20.f;
  415. _btn.clipsToBounds = YES;
  416. _btn.frame = CGRectMake(60, n, JX_SCREEN_WIDTH-60*2, 40);
  417. _btn.userInteractionEnabled = NO;
  418. [self.tableBody addSubview:_btn];
  419. n = n+HEIGHT+INSETS+INSETS;
  420. //忘记密码
  421. UIButton *lbUser = [[UIButton alloc]init];
  422. [lbUser setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  423. [lbUser setTitle:Localized(@"JX_ForgetPassWord") forState:UIControlStateNormal];
  424. lbUser.titleLabel.font = g_factory.font16;
  425. lbUser.custom_acceptEventInterval = 1.0f;
  426. [lbUser addTarget:self action:@selector(onForget) forControlEvents:UIControlEventTouchUpInside];
  427. lbUser.titleEdgeInsets = UIEdgeInsetsMake(0, -27, 0, 0);
  428. [self.tableBody addSubview:lbUser];
  429. [lbUser mas_makeConstraints:^(MASConstraintMaker *make) {
  430. make.centerX.mas_equalTo(self.tableBody.mas_centerX);
  431. make.top.mas_equalTo(_btn.mas_bottom).mas_offset(20);
  432. make.width.mas_equalTo(90);
  433. }];
  434. // lbUser.hidden = self.isSMSLogin;
  435. _forgetBtn = lbUser;
  436. NSString *protocolStr2 =@"";// @"登录遇到问题?";
  437. UILabel *protocolLab2 = [[UILabel alloc] init];
  438. protocolLab2.font = SYSFONT(13);
  439. CGSize proSize2 = [protocolStr2 boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:protocolLab2.font} context:nil].size;
  440. protocolLab2.frame = CGRectMake((JX_SCREEN_WIDTH-proSize2.width)/2, n, proSize2.width, proSize2.height);
  441. protocolLab2.textColor = HEXCOLOR(0x2A98FF);
  442. NSDictionary *attribtDic2 = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone]};
  443. NSMutableAttributedString *attribtStr2 = [[NSMutableAttributedString alloc]initWithString:protocolStr2 attributes:attribtDic2];
  444. //protocolLab2.attributedText = attribtStr2;
  445. [self.tableBody addSubview:protocolLab2];
  446. protocolLab2.userInteractionEnabled = YES;
  447. UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onForget)];
  448. //[protocolLab2 addGestureRecognizer:tap2];
  449. n = n+HEIGHT+INSETS;
  450. // 屏幕太小,第三方登录超过登录界面,就另外计算y
  451. CGFloat wxWidth = 48;
  452. BOOL isSmall = JX_SCREEN_HEIGHT-JX_SCREEN_TOP - wxWidth - 30 <= CGRectGetMaxY(_btn.frame)+30;
  453. CGFloat loginY = isSmall ? CGRectGetMaxY(_btn.frame)+30 : JX_SCREEN_HEIGHT-JX_SCREEN_TOP - wxWidth - 60;
  454. // UIImageView *wxLogin = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH-wxWidth*3)/4, loginY, wxWidth, wxWidth)];
  455. UIImageView *wxLogin = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH/3)-(wxWidth/2), loginY+30, wxWidth/2, wxWidth/2)];
  456. //wxLogin.image = [UIImage imageNamed:@"wechat_icon"];
  457. wxLogin.userInteractionEnabled = NO;
  458. [self.tableBody addSubview:wxLogin];
  459. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didWechatToLogin:)];
  460. [wxLogin addGestureRecognizer:tap];
  461. wxLogin.hidden = (_isThirdLogin || self.isSMSLogin);
  462. if (isSmall) {
  463. self.tableBody.contentSize = CGSizeMake(0, CGRectGetMaxY(wxLogin.frame)+20);
  464. }
  465. //QQ登录
  466. // UIImageView *qqLogin = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH-wxWidth*3)/4*2+wxWidth, loginY, wxWidth, wxWidth)];
  467. UIImageView *qqLogin = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH/3*2)-(wxWidth/2), loginY+30, wxWidth/2, wxWidth/2)];
  468. //qqLogin.image = [UIImage imageNamed:@"qq_login"];
  469. qqLogin.userInteractionEnabled = NO;
  470. [self.tableBody addSubview:qqLogin];
  471. qqLogin.hidden = (_isThirdLogin || self.isSMSLogin);
  472. UITapGestureRecognizer *qqTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didQQToLogin:)];
  473. [qqLogin addGestureRecognizer:qqTap];
  474. //短信登录
  475. UIImageView *smsLogin = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH-wxWidth*3)/4*3+wxWidth*2, loginY, wxWidth, wxWidth)];
  476. // smsLogin.image = [UIImage imageNamed:@"sms_login"];
  477. smsLogin.userInteractionEnabled = NO;
  478. // [self.tableBody addSubview:smsLogin];
  479. smsLogin.hidden = (_isThirdLogin || self.isSMSLogin);
  480. UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(switchLoginWay)];
  481. [smsLogin addGestureRecognizer:tap1];
  482. // 微信登录回调
  483. [WXApiManager sharedManager].delegate = self;
  484. if ([g_default objectForKey:kMY_USER_NICKNAME])
  485. _user.userNickname = MY_USER_NAME;
  486. if ([g_default objectForKey:kMY_USER_ID])
  487. _user.userId = [g_default objectForKey:kMY_USER_ID];
  488. if ([g_default objectForKey:kMY_USER_COMPANY_ID])
  489. _user.companyId = [g_default objectForKey:kMY_USER_COMPANY_ID];
  490. if ([g_default objectForKey:kMY_USER_LoginName]) {
  491. [_phone setText:[g_default objectForKey:kMY_USER_LoginName]];
  492. _user.telephone = _phone.text;
  493. }
  494. if ([g_default objectForKey:kMY_USER_PASSWORD]) {
  495. // [_pwd setText:[g_default objectForKey:kMY_USER_PASSWORD]];
  496. _user.password = _pwd.text;
  497. }
  498. if ([g_default objectForKey:kLocationLogin]) {
  499. NSDictionary *dict = [g_default objectForKey:kLocationLogin];
  500. g_server.longitude = [[dict objectForKey:@"longitude"] doubleValue];
  501. g_server.latitude = [[dict objectForKey:@"latitude"] doubleValue];
  502. }
  503. [g_notify addObserver:self selector:@selector(onRegistered:) name:kRegisterNotifaction object:nil];
  504. [g_notify addObserver:self selector:@selector(authRespNotification:) name:kWxSendAuthRespNotification object:nil];
  505. if(!self.isAutoLogin || IsStringNull(_myToken)) {
  506. _btn.userInteractionEnabled = YES;
  507. }else {
  508. _launchImageView = [[UIImageView alloc] init];
  509. _launchImageView.frame = self.view.bounds;
  510. _launchImageView.image = [UIImage imageNamed:[self getLaunchImageName]];
  511. [self.view addSubview:_launchImageView];
  512. }
  513. // NSString *area = [g_default objectForKey:kLocationArea];
  514. // if (area.length > 0) {
  515. if(self.isAutoLogin && !IsStringNull(_myToken))
  516. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  517. // [_wait start:Localized(@"JX_Logining")];
  518. [_wait startWithClearColor];
  519. });
  520. if (!_isThirdLogin) {
  521. [g_server getSetting:self];
  522. }
  523. // }else {
  524. // _isFirstLocation = NO;
  525. // JXLocation *location = [[JXLocation alloc] init];
  526. // location.delegate = self;
  527. // [location getLocationWithIp];
  528. // }
  529. }
  530. return self;
  531. }
  532. //验证手机号格式
  533. - (void)sendSMS{
  534. if (!_send.selected) {
  535. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  536. _user = [JXUserObject sharedInstance];
  537. _user.areaCode = areaCode;
  538. [g_server sendSMS:[NSString stringWithFormat:@"%@",_phone.text] areaCode:areaCode isRegister:NO imgCode:_imgCode.text toView:self];
  539. [_send setTitle:Localized(@"JX_Sending") forState:UIControlStateNormal];
  540. }
  541. }
  542. -(void)textFieldDidBeginEditing:(UITextField *)textField{
  543. if (textField == _imgCode) {
  544. if (!_imgCodeImg.image) {
  545. [self refreshGraphicAction:nil];
  546. }
  547. }
  548. }
  549. - (void)switchLoginWay {
  550. if (self.isSMSLogin) {
  551. [self actionQuit];
  552. }else {
  553. loginVC *vc = [loginVC alloc];
  554. vc.isSMSLogin = YES;
  555. vc = [vc init];
  556. [g_navigation pushViewController:vc animated:YES];
  557. }
  558. }
  559. -(void)refreshGraphicAction:(UIButton *)button{
  560. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  561. [g_server checkPhone:_phone.text areaCode:areaCode verifyType:1 toView:self];
  562. }
  563. -(void)getImgCodeImg{
  564. if([self isMobileNumber:_phone.text]){
  565. // if ([self checkPhoneNum]) {
  566. //请求图片验证码
  567. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  568. NSString * codeUrl = [g_server getImgCode:_phone.text areaCode:areaCode];
  569. NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:codeUrl] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
  570. [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
  571. if (!connectionError) {
  572. UIImage * codeImage = [UIImage imageWithData:data];
  573. _imgCodeImg.image = codeImage;
  574. }else{
  575. NSLog(@"%@",connectionError);
  576. [g_App showAlert:connectionError.localizedDescription];
  577. }
  578. }];
  579. }
  580. }
  581. //验证手机号码格式
  582. - (BOOL)isMobileNumber:(NSString *)number{
  583. if ([g_config.isOpenSMSCode boolValue] && [g_config.regeditPhoneOrName intValue] != 1) {
  584. if ([_phone.text length] == 0) {
  585. [g_App showAlert:Localized(@"JX_InputPhone")];
  586. return NO;
  587. }
  588. }
  589. return YES;
  590. }
  591. #pragma mark - 微信登录
  592. - (void)didWechatToLogin:(UITapGestureRecognizer *)tap {
  593. // if (![[g_default objectForKey:@"agreement"] boolValue]) {
  594. // [g_App showAlert:Localized(@"JX_NotAgreeProtocol")];
  595. // return;
  596. // }
  597. self.type = JXLoginWX;
  598. if (![WXApi isWXAppInstalled]) {
  599. [g_App showAlert:@"您的手机没有安装微信, 请下载后使用微信登录."];
  600. return;
  601. }
  602. SendAuthReq* req = [[SendAuthReq alloc] init];
  603. req.scope = @"snsapi_userinfo"; // @"post_timeline,sns"
  604. req.state = @"login";
  605. req.openID = @"";
  606. [WXApi sendAuthReq:req
  607. viewController:self
  608. delegate:[WXApiManager sharedManager]];
  609. }
  610. - (void)authRespNotification:(NSNotification *)notif {
  611. SendAuthResp *response = notif.object;
  612. NSString *strMsg = [NSString stringWithFormat:@"Auth结果 code:%@,state:%@,errcode:%d", response.code, response.state, response.errCode];
  613. NSLog(@"-------%@",strMsg);
  614. if (response.code.length > 0) {
  615. [g_server getWxOpenId:response.code toView:self];
  616. }
  617. }
  618. #pragma mark - QQ登录
  619. - (void)didQQToLogin:(UITapGestureRecognizer *)tap {
  620. self.type = JXLoginQQ;
  621. if (![TencentOAuth iphoneQQInstalled]) {
  622. [g_App showAlert:@"您的手机没有安装手机QQ, 请下载后使用QQ登录."];
  623. return;
  624. }
  625. NSString *appid = g_App.QQ_LOGIN_APPID;
  626. _oauth = [[TencentOAuth alloc] initWithAppId:appid
  627. andDelegate:self];
  628. _oauth.authMode = kAuthModeClientSideToken;
  629. [_oauth authorize:[self getPermissions] inSafari:NO];
  630. }
  631. // QQ登录成功回调
  632. - (void)tencentDidLogin {
  633. NSString *qqOpenId = _oauth.openId;
  634. g_server.openId = qqOpenId;
  635. if (qqOpenId.length > 0) {
  636. [g_server wxSdkLogin:_user type:1 openId:qqOpenId toView:self];
  637. }
  638. }
  639. - (NSMutableArray *)getPermissions {
  640. NSMutableArray * g_permissions = [[NSMutableArray alloc] initWithObjects:kOPEN_PERMISSION_GET_USER_INFO,
  641. kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
  642. kOPEN_PERMISSION_ADD_ALBUM,
  643. kOPEN_PERMISSION_ADD_TOPIC,
  644. kOPEN_PERMISSION_CHECK_PAGE_FANS,
  645. kOPEN_PERMISSION_GET_INFO,
  646. kOPEN_PERMISSION_GET_OTHER_INFO,
  647. kOPEN_PERMISSION_LIST_ALBUM,
  648. kOPEN_PERMISSION_UPLOAD_PIC,
  649. kOPEN_PERMISSION_GET_VIP_INFO,
  650. kOPEN_PERMISSION_GET_VIP_RICH_INFO, nil];
  651. return g_permissions;
  652. }
  653. - (void)agrBtnAction:(UIButton *)btn {
  654. _checkProtocolBtn.selected = !_checkProtocolBtn.selected;
  655. [self didSelectedCheckBox:_checkProtocolBtn checked:_checkProtocolBtn.selected];
  656. }
  657. //设置文本框只能输入数字
  658. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  659. if (_phone == textField) {
  660. return [self validateNumber:string];
  661. }
  662. return YES;
  663. }
  664. - (BOOL)validateNumber:(NSString*)number {
  665. // if ([g_config.regeditPhoneOrName intValue] == 1) {
  666. // 如果用户名注册选项开启, 则不筛选
  667. NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet];
  668. NSString *filtered = [[number componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
  669. return [number isEqualToString:filtered];
  670. // }
  671. // BOOL res = YES;
  672. // NSCharacterSet *tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  673. // int i = 0;
  674. // while (i < number.length) {
  675. // NSString *string = [number substringWithRange:NSMakeRange(i, 1)];
  676. // NSRange range = [string rangeOfCharacterFromSet:tmpSet];
  677. // if (range.length == 0) {
  678. // res = NO;
  679. // break;
  680. // }
  681. // i ++;
  682. // }
  683. // return res;
  684. }
  685. -(void)location:(JXLocation *)location getLocationWithIp:(NSDictionary *)dict {
  686. if (_isFirstLocation) {
  687. return;
  688. }
  689. NSString *area = [NSString stringWithFormat:@"%@,%@,%@",dict[@"country"],dict[@"region"],dict[@"city"]];
  690. [g_default setObject:area forKey:kLocationArea];
  691. [g_default synchronize];
  692. if(self.isAutoLogin && !IsStringNull(_myToken))
  693. [_wait start:Localized(@"JX_Logining")];
  694. if (!_isThirdLogin) {
  695. [g_server getSetting:self];
  696. }
  697. }
  698. - (void)location:(JXLocation *)location getLocationError:(NSError *)error {
  699. if (_isFirstLocation) {
  700. return;
  701. }
  702. [g_default setObject:nil forKey:kLocationArea];
  703. [g_default synchronize];
  704. if(self.isAutoLogin && !IsStringNull(_myToken))
  705. [_wait start:Localized(@"JX_Logining")];
  706. if (!_isThirdLogin) {
  707. [g_server getSetting:self];
  708. }
  709. }
  710. -(void)longLimit:(UITextField *)textField
  711. {
  712. // if (textField.text.length > 11) {
  713. // textField.text = [textField.text substringToIndex:11];
  714. // }
  715. }
  716. -(void)dealloc{
  717. // _pSelf = nil;
  718. // NSLog(@"loginVC.dealloc");
  719. [g_notify removeObserver:self name:kRegisterNotifaction object:nil];
  720. // [_user release];
  721. // [super dealloc];
  722. }
  723. - (void)viewDidLoad
  724. {
  725. [super viewDidLoad];
  726. // Do any additional setup after loading the view.
  727. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  728. [self.view addGestureRecognizer:tap];
  729. _vc=[JXShareAnQuanView XIBJXShareShowView];
  730. _vc.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.1];
  731. _vc.frame=[UIScreen mainScreen].bounds;
  732. [[UIApplication sharedApplication].keyWindow addSubview:_vc];
  733. [_vc.yanzBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
  734. _vc.hidden=YES;
  735. _security=@"";
  736. }
  737. //登录登录
  738. - (void)addBtnClick{
  739. if (_vc.yaoqinTF.text.length==0) {
  740. [SVProgressHUD showWithStatus:@"请输入安全码"];
  741. [SVProgressHUD dismissWithDelay:0.7];
  742. return;
  743. }
  744. _user.security=_vc.yaoqinTF.text;
  745. _security=_vc.yaoqinTF.text;
  746. [self onClick];
  747. }
  748. - (void)tapAction:(UITapGestureRecognizer *)tap {
  749. [self.view endEditing:YES];
  750. }
  751. - (void)didReceiveMemoryWarning
  752. {
  753. [super didReceiveMemoryWarning];
  754. // Dispose of any resources that can be recreated.
  755. }
  756. - (void) textFieldDidChange:(UITextField *) TextField{
  757. if ([TextField.text isEqualToString:@""]) {
  758. _pwd.text = @"";
  759. }
  760. // if (TextField == _phone) { // 限制手机号最多只能输入11位,为了适配外国电话,将不能显示手机号位数
  761. // if ([g_config.regeditPhoneOrName intValue] == 1) {
  762. // if (_phone.text.length > 10) {
  763. // _phone.text = [_phone.text substringToIndex:10];
  764. // }
  765. // }else {
  766. // if (_phone.text.length > 11) {
  767. // _phone.text = [_phone.text substringToIndex:11];
  768. // }
  769. // }
  770. // }
  771. }
  772. -(void)onClick{
  773. AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
  774. [manager startMonitoring];
  775. [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  776. if (status != AFNetworkReachabilityStatusNotReachable) {
  777. }else {
  778. [JXMyTools showTipView:Localized(@"JX_NetWorkError")];
  779. return;
  780. }
  781. }];
  782. // self.isSwitchUser = NO;
  783. if([_phone.text length]<=0){
  784. if ([g_config.regeditPhoneOrName intValue] == 1) {
  785. [g_App showAlert:Localized(@"JX_InputUserAccount")];
  786. }else {
  787. [g_App showAlert:Localized(@"JX_InputPhone")];
  788. }
  789. return;
  790. }
  791. if([_pwd.text length]<=0){
  792. [g_App showAlert:self.isSMSLogin ? Localized(@"JX_InputMessageCode") : Localized(@"JX_InputPassWord")];
  793. return;
  794. }
  795. // if (![[g_default objectForKey:@"agreement"] boolValue]) {
  796. // [g_App showAlert:Localized(@"JX_NotAgreeProtocol")];
  797. // return;
  798. // }
  799. [self.view endEditing:YES];
  800. if (self.isSMSLogin) {
  801. _user.verificationCode = _pwd.text;
  802. }else {
  803. _user.password = [g_server getMD5String:_pwd.text];
  804. }
  805. _user.telephone = _phone.text;
  806. _user.areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  807. self.isAutoLogin = NO;
  808. [_wait start:Localized(@"JX_Logining")];
  809. [g_server getSetting:self];
  810. // [g_App.jxServer login:_user toView:self];
  811. }
  812. - (void)actionConfig {
  813. // 自动登录失败,清除token后,重新赋值一次
  814. _myToken = [g_default objectForKey:kMY_USER_TOKEN];
  815. if ([g_config.regeditPhoneOrName intValue] == 1) {
  816. _areaCodeBtn.hidden = YES;
  817. _forgetBtn.hidden = YES;
  818. // _phone.keyboardType = UIKeyboardTypeDefault; // 仅支持大小写字母数字
  819. _phone.placeholder = Localized(@"JX_InputUserAccount");
  820. }else {
  821. _areaCodeBtn.hidden = NO;
  822. // _forgetBtn.hidden = NO;
  823. // _phone.keyboardType = UIKeyboardTypeNumberPad; // 限制只能数字输入,使用数字键盘
  824. _phone.placeholder = Localized(@"JX_InputPhone");
  825. // 短信登录界面不显示忘记密码
  826. _forgetBtn.hidden = self.isSMSLogin;
  827. }
  828. if ([g_config.isOpenPositionService intValue] == 0) {
  829. _isFirstLocation = YES;
  830. _location = [[JXLocation alloc] init];
  831. _location.delegate = self;
  832. g_server.location = _location;
  833. [g_server locate];
  834. }
  835. if((_isAutoLogin && !IsStringNull(_myToken)) || _isThirdLogin)
  836. if (_isThirdLogin) {
  837. // [g_server thirdLogin:_user type:2 openId:g_server.openId isLogin:NO toView:self];
  838. [g_loginServer thirdLoginV1:_user password:_pwd.text type:self.type openId:g_server.openId isLogin:NO toView:self];
  839. }else {
  840. [self performSelector:@selector(autoLogin) withObject:nil afterDelay:.5];
  841. }
  842. else if (IsStringNull(_myToken) && !IsStringNull(_phone.text) && !IsStringNull(_pwd.text)) {
  843. g_server.isManualLogin = YES;
  844. // [g_App.jxServer login:_user toView:self];
  845. NSString *areaCode = [_areaCodeBtn.titleLabel.text stringByReplacingOccurrencesOfString:@"+" withString:@""];
  846. if (self.isSMSLogin) {
  847. [g_loginServer smsLoginWithUser:_user areaCode:areaCode account:_phone.text toView:self];
  848. }else {
  849. g_server.temporaryPWD = _pwd.text;
  850. /*[g_loginServer loginWithUser:_user password:_pwd.text areaCode:areaCode account:_phone.text toView:self];
  851. NSLog(@"name: %@", [[UIDevice currentDevice] name]);
  852. NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
  853. NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
  854. NSLog(@"model: %@", [[UIDevice currentDevice] model]);
  855. NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);
  856. */
  857. NSString *modelAll=[NSString stringWithFormat:@"%@ :%@%@",[[UIDevice currentDevice] name],[[UIDevice currentDevice] systemName], [[UIDevice currentDevice] systemVersion]];
  858. _user.model=modelAll;
  859. // [g_loginServer loginWithUser:_user password:_pwd.text areaCode:areaCode account:_phone.text toView:self];
  860. [g_loginServer loginWithUserNew:_user password:_pwd.text areaCode:areaCode account:_phone.text model:modelAll security:_security toView:self];
  861. }
  862. }
  863. else
  864. [_wait stop];
  865. }
  866. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  867. [_wait stop];
  868. if ([aDownload.action isEqualToString:act_getGradeList])
  869. {
  870. NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
  871. NSString *fileName = [path stringByAppendingPathComponent:@"grade.plist"];
  872. [array1 writeToFile:fileName atomically:YES];
  873. // 保存到数据库
  874. JLBubbleManager *manager = [JLBubbleManager sharedManager];
  875. FMDatabase* db = [manager openResouceDb];
  876. BOOL result = [manager checkGradeTableCreatedInDb:db];
  877. if (result) {
  878. // self.gradeIndex, self.avatarUrl, self.id, self.name, self.rankUrl, self.grade
  879. for (NSDictionary *tempDict in array1) {
  880. JLBubbleManager *manager = [JLBubbleManager mj_objectWithKeyValues:tempDict];
  881. [manager insertGradeTable];
  882. }
  883. }
  884. NSMutableArray *imagesArray = [NSMutableArray array];
  885. for (NSDictionary *tempDict in array1) {
  886. //[imagesArray addObject:[NSURL URLWithString:tempDict[@"avatarUrl"]]];
  887. //[imagesArray addObject:[NSURL URLWithString:tempDict[@"rankUrl"]]];
  888. NSString *avatarUrl = @"";
  889. if (tempDict[@"avatarUrl"] == nil) {
  890. avatarUrl = @"";
  891. }else {
  892. avatarUrl = tempDict[@"avatarUrl"];
  893. }
  894. NSString *rankUrl = @"";
  895. if (tempDict[@"rankUrl"] == nil) {
  896. avatarUrl = @"";
  897. }else {
  898. rankUrl = tempDict[@"rankUrl"];
  899. }
  900. [imagesArray addObject:[NSURL URLWithString:avatarUrl]];
  901. [imagesArray addObject:[NSURL URLWithString:rankUrl]];
  902. NSArray *bubbleFontSet = tempDict[@"bubbleFontSet"];
  903. for (NSDictionary *bubbleFontDict in bubbleFontSet) {
  904. JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:bubbleFontDict];
  905. [imagesArray addObject:[NSURL URLWithString:model.bubble.iosLeftUrl]];
  906. [imagesArray addObject:[NSURL URLWithString:model.bubble.iosRightUrl]];
  907. // [imagesArray addObject:[NSURL URLWithString:model.homeUrl]];
  908. }
  909. // NSArray *faceSet = tempDict[@"faceSet"];
  910. // for (NSDictionary *faceSetDict in faceSet) {
  911. // NSArray *array = faceSetDict[@"path"];
  912. // for (NSString *url in array) {
  913. // NSURL *urlPath = [NSURL URLWithString:url];
  914. // [imagesArray addObject:urlPath];
  915. // }
  916. // }
  917. if (result) {
  918. // int gradeIndex = (int)tempDict[@"gradeIndex"];
  919. // [JXLabelObject sharedInstance].gradeIndex = gradeIndex;
  920. // NSData *data = [NSKeyedArchiver archivedDataWithRootObject:tempDict];
  921. // [JXLabelObject sharedInstance].data = data;
  922. // [[JXLabelObject sharedInstance] insertGradeTable];
  923. // NSArray *array = [tempDict allValues];
  924. }
  925. }
  926. // 缓存图片
  927. [[JLBubbleManager sharedManager] cacheBubbleImage:imagesArray];
  928. }
  929. if ([aDownload.action isEqualToString:act_getAllBubbleFontList])
  930. {
  931. NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
  932. NSString *fileName = [path stringByAppendingPathComponent:@"bubbleFontList.plist"];
  933. [array1 writeToFile:fileName atomically:YES];
  934. // 保存到数据库
  935. // 保存到数据库
  936. JLBubbleManager *manager = [JLBubbleManager sharedManager];
  937. FMDatabase* db = [manager openResouceDb];
  938. BOOL result = [manager checkBubbleFontTableCreatedInDb:db];
  939. if (result) {
  940. // self.id, self.iosLeftUrl, self.iosRightUrl, self.name, self.code, self.color
  941. for (NSDictionary *tempDict in array1) {
  942. JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:tempDict];
  943. manager.id = model.id;
  944. manager.iosLeftUrl = model.bubble.iosLeftUrl;
  945. manager.iosRightUrl = model.bubble.iosRightUrl;
  946. manager.name = model.bubble.name;
  947. manager.code = [NSString stringWithFormat:@"%d", model.font.code];
  948. manager.color = model.font.color;
  949. [manager insertBubbleFontTable];
  950. }
  951. }
  952. // 缓存图片
  953. // NSMutableArray *imagesArray = [NSMutableArray array];
  954. // for (NSDictionary *modelDict in array1) {
  955. // JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:modelDict];
  956. // [imagesArray addObject:[NSURL URLWithString:model.bubble.iosLeftUrl]];
  957. // [imagesArray addObject:[NSURL URLWithString:model.bubble.iosRightUrl]];
  958. //// [imagesArray addObject:[NSURL URLWithString:model.homeUrl]];
  959. // }
  960. // [[JLBubbleManager sharedManager] cacheBubbleImage:imagesArray];
  961. }
  962. if ([aDownload.action isEqualToString:act_customerLinkList])
  963. {
  964. g_App.customerLinkListArray = array1;
  965. }
  966. if( [aDownload.action isEqualToString:act_Config]){
  967. [g_config didReceive:dict];
  968. [self actionConfig];
  969. }
  970. if([aDownload.action isEqualToString:act_CheckPhone]){
  971. [self getImgCodeImg];
  972. }
  973. if([aDownload.action isEqualToString:act_SendSMS]){
  974. [JXMyTools showTipView:Localized(@"JXAlert_SendOK")];
  975. _send.selected = YES;
  976. _send.userInteractionEnabled = NO;
  977. _send.backgroundColor = [UIColor grayColor];
  978. _smsCode = [[dict objectForKey:@"code"] copy];
  979. [_send setTitle:@"60s" forState:UIControlStateSelected];
  980. _seconds = 60;
  981. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showTime:) userInfo:_send repeats:YES];
  982. }
  983. if( [aDownload.action isEqualToString:act_UserLogin] || [aDownload.action isEqualToString:act_thirdLogin] || [aDownload.action isEqualToString:act_thirdLoginV1] || [aDownload.action isEqualToString:act_sdkLogin] || [aDownload.action isEqualToString:act_sdkLoginV1] || [aDownload.action isEqualToString:act_UserLoginV1] || [aDownload.action isEqualToString:act_UserSMSLogin]){
  984. if ([dict.allKeys containsObject:@"authKey"]) {
  985. [_wait stop];
  986. [self createWaitAuthView];
  987. [self startAuthDevice:[dict objectForKey:@"authKey"]];
  988. return;
  989. }
  990. if ([aDownload.action isEqualToString:act_thirdLogin] || [aDownload.action isEqualToString:act_thirdLoginV1] || [aDownload.action isEqualToString:act_sdkLogin] || [aDownload.action isEqualToString:act_sdkLoginV1] ) {
  991. g_server.openId = nil;
  992. [g_default setBool:YES forKey:kTHIRD_LOGIN_AUTO];
  993. }else {
  994. [g_default setBool:NO forKey:kTHIRD_LOGIN_AUTO];
  995. }
  996. // if (!IsStringNull(_pwd.text)) {
  997. // _user.password = [g_server getMD5String:_pwd.text];
  998. // }
  999. // [g_default setBool:[[dict objectForKey:@"multipleDevices"] boolValue] forKey:kISMultipleLogin];
  1000. // [g_default synchronize];
  1001. [g_server doLoginOK:dict user:_user];
  1002. if(self.isSwitchUser){
  1003. //切换登录,同步好友
  1004. [g_notify postNotificationName:kXmppClickLoginNotifaction object:nil];
  1005. // 更新“我”页面
  1006. [g_notify postNotificationName:kUpdateUserNotifaction object:nil];
  1007. }
  1008. else
  1009. _vc.hidden=YES;
  1010. [g_App showMainUI];
  1011. [self actionQuit];
  1012. [_wait stop];
  1013. }
  1014. if([aDownload.action isEqualToString:act_userLoginAuto] || [aDownload.action isEqualToString:act_userLoginAutoV1]){
  1015. // int status = [[dict objectForKey:@"serialStatus"] intValue];
  1016. // int token = [[dict objectForKey:@"tokenExists"] intValue];
  1017. // if(status == 2){//序列号一致
  1018. // if(token==1){//Token也存在,说明不用登录了
  1019. // [g_default setBool:[[dict objectForKey:@"multipleDevices"] boolValue] forKey:kISMultipleLogin];
  1020. // [g_default synchronize];
  1021. [g_server getAppResource:@"2" ToView:self];
  1022. [g_server doLoginOK:dict user:_user];
  1023. [g_App showMainUI];
  1024. [self actionQuit];
  1025. // }else{
  1026. // //Token不存在
  1027. // [g_App showAlert:Localized(@"JX_LoginAgain")];
  1028. // _launchImageView.hidden = YES;
  1029. // }
  1030. // }else{
  1031. // //设备号已换
  1032. // [g_App showAlert:Localized(@"JX_LoginAgainNow")];
  1033. // _launchImageView.hidden = YES;
  1034. // }
  1035. [_wait stop];
  1036. }
  1037. if ([aDownload.action isEqualToString:act_GetWxOpenId]) {
  1038. _launchImageView.hidden = NO;
  1039. g_server.openId = [dict objectForKey:@"openid"];
  1040. // [g_server wxSdkLogin:_user type:2 openId:g_server.openId toView:self];
  1041. [g_loginServer wxSdkLoginV1:_user type:2 openId:g_server.openId toView:self];
  1042. }
  1043. if ([aDownload.action isEqualToString:act_getAppResource]) {
  1044. // NSLog(@"%@",array1);
  1045. NSMutableArray *tempArray0 = [NSMutableArray array];
  1046. NSMutableArray *tempArray2 = [NSMutableArray array];
  1047. for (NSDictionary *resourceDict in array1) {
  1048. NSString *code = resourceDict[@"code"];
  1049. if ([code isEqualToString:@"0"]) {
  1050. [tempArray0 addObject:resourceDict];
  1051. }else if ([code isEqualToString:@"2"]) {
  1052. [tempArray2 addObject:resourceDict];
  1053. }
  1054. }
  1055. if (tempArray0.count>0) {
  1056. g_App.linkArray = tempArray0;
  1057. g_App.imgUrl = tempArray0[0][@"imgUrl"];
  1058. }
  1059. if (tempArray2.count>0) {
  1060. NSDictionary *adDict = tempArray2.firstObject;
  1061. [g_App setupLunchADUrl:adDict[@"imgUrl"] link:adDict[@"link"]];
  1062. }else {
  1063. [g_notify postNotificationName:kLaunchAdShowFinishNotifaction object:nil];
  1064. }
  1065. }
  1066. _btn.userInteractionEnabled = YES;
  1067. }
  1068. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  1069. _btn.userInteractionEnabled = YES;
  1070. _launchImageView.hidden = YES;
  1071. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  1072. [_wait stop];
  1073. if ([aDownload.action isEqualToString:act_UserDeviceIsAuth]) {
  1074. if ([[dict objectForKey:@"resultCode"] intValue] == 101987) {
  1075. [self changeAccount];
  1076. [g_server getSetting:self];
  1077. }
  1078. return hide_error;
  1079. }
  1080. if ([aDownload.action isEqualToString:act_AuthGetLoginCode]) {
  1081. [SVProgressHUD showWithStatus:errorCode];
  1082. [SVProgressHUD dismissWithDelay:1.2];;
  1083. }
  1084. if ([aDownload.action isEqualToString:act_Config]) {
  1085. NSString *url = [g_default stringForKey:kLastApiUrl];
  1086. g_config.apiUrl = url;
  1087. [self actionConfig];
  1088. return hide_error;
  1089. }
  1090. [_wait stop];
  1091. if (([aDownload.action isEqualToString:act_sdkLogin] || [aDownload.action isEqualToString:act_sdkLoginV1]) && [[dict objectForKey:@"resultCode"] intValue] == 1040305) {
  1092. inputPhoneVC *vc = [[inputPhoneVC alloc] init];
  1093. vc.isThirdLogin = YES;
  1094. vc.type = self.type;
  1095. [g_navigation pushViewController:vc animated:YES];
  1096. // loginVC *login = [loginVC alloc];
  1097. // login.isThirdLogin = YES;
  1098. // login.isAutoLogin = NO;
  1099. // login.isSwitchUser= NO;
  1100. // login = [login init];
  1101. // [g_navigation pushViewController:login animated:YES];
  1102. return show_error;
  1103. }
  1104. if (([aDownload.action isEqualToString:act_thirdLogin] || [aDownload.action isEqualToString:act_thirdLoginV1]) && [[dict objectForKey:@"resultCode"] intValue] == 1040306) {
  1105. _vc.hidden=NO;
  1106. inputPhoneVC *vc = [[inputPhoneVC alloc] init];
  1107. vc.isThirdLogin = YES;
  1108. vc.type = self.type;
  1109. [g_navigation pushViewController:vc animated:YES];
  1110. return show_error;
  1111. }
  1112. if([aDownload.action isEqualToString:act_userLoginAuto] || [aDownload.action isEqualToString:act_userLoginAutoV1]){
  1113. [g_default removeObjectForKey:kMY_USER_TOKEN];
  1114. [share_defaults removeObjectForKey:kMY_ShareExtensionToken];
  1115. _vc.hidden=NO;
  1116. }
  1117. if ([aDownload.action isEqualToString:act_thirdLogin] || [aDownload.action isEqualToString:act_thirdLoginV1]) {
  1118. // g_server.openId = nil;
  1119. _vc.hidden=NO;
  1120. }
  1121. if ([aDownload.action isEqualToString:act_SendSMS]) {
  1122. [_send setTitle:Localized(@"JX_Send") forState:UIControlStateNormal];
  1123. }if ([aDownload.action isEqualToString:act_UserLoginV1]) { //密码正确登录的时候
  1124. [_wait stop];
  1125. //user/login/v1
  1126. [SVProgressHUD dismissWithDelay:1.2];
  1127. [SVProgressHUD showWithStatus:@"安全码错误"];
  1128. _vc.hidden=NO;
  1129. }
  1130. return 1;
  1131. }
  1132. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  1133. _btn.userInteractionEnabled = YES;
  1134. _launchImageView.hidden = YES;
  1135. if ([aDownload.action isEqualToString:act_Config]) {
  1136. NSString *url = [g_default stringForKey:kLastApiUrl];
  1137. g_config.apiUrl = url;
  1138. if (_myToken==nil||_myToken.length==0) {
  1139. }else{
  1140. [self actionConfig];
  1141. }
  1142. return hide_error;
  1143. }
  1144. if([aDownload.action isEqualToString:act_userLoginAuto] || [aDownload.action isEqualToString:act_userLoginAutoV1]){
  1145. [g_default removeObjectForKey:kMY_USER_TOKEN];
  1146. [share_defaults removeObjectForKey:kMY_ShareExtensionToken];
  1147. _vc.hidden=NO;
  1148. }
  1149. if ([aDownload.action isEqualToString:act_thirdLogin] || [aDownload.action isEqualToString:act_thirdLoginV1]) {
  1150. // g_server.openId = nil;
  1151. _vc.hidden=NO;
  1152. }
  1153. if ([aDownload.action isEqualToString:act_SendSMS]) {
  1154. [_send setTitle:Localized(@"JX_Send") forState:UIControlStateNormal];
  1155. }if ([aDownload.action isEqualToString:act_UserLoginV1]) {
  1156. _vc.hidden=NO;
  1157. }
  1158. [_wait stop];
  1159. return 1;
  1160. }
  1161. -(void) didServerConnectStart:(JXConnection*)aDownload{
  1162. // _btn.userInteractionEnabled = NO;
  1163. if([aDownload.action isEqualToString:act_thirdLogin] || [aDownload.action isEqualToString:act_thirdLoginV1] || [aDownload.action isEqualToString:act_sdkLogin]|| [aDownload.action isEqualToString:act_sdkLoginV1]){
  1164. [_wait start];
  1165. }
  1166. }
  1167. -(void)onRegister{
  1168. inputPhoneVC* vc = [[inputPhoneVC alloc]init];
  1169. // PSRegisterBaseVC *vc = [[PSRegisterBaseVC alloc] init];
  1170. // [g_window addSubview:vc.view];
  1171. [g_navigation pushViewController:vc animated:YES];
  1172. }
  1173. -(void)onForget{
  1174. forgetPwdVC* vc = [[forgetPwdVC alloc] init];
  1175. vc.isModify = NO;
  1176. // [g_window addSubview:vc.view];
  1177. [g_navigation pushViewController:vc animated:YES];
  1178. }
  1179. -(void)autoLogin{
  1180. // _btn.userInteractionEnabled = ![g_server autoLogin:self];
  1181. NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kMY_USER_TOKEN];
  1182. _btn.userInteractionEnabled = token.length > 0;
  1183. if (token.length > 0) {
  1184. [g_loginServer autoLoginWithToView:self];
  1185. }else {
  1186. _launchImageView.hidden = YES;
  1187. }
  1188. // if (_btn.userInteractionEnabled) {
  1189. // _launchImageView.hidden = YES;
  1190. // }
  1191. }
  1192. -(void)onRegistered:(NSNotification *)notifacation{
  1193. [self actionQuit];
  1194. if(!self.isSwitchUser)
  1195. [g_App showMainUI];
  1196. }
  1197. -(void)actionQuit{
  1198. [super actionQuit];
  1199. // _pSelf = nil;
  1200. }
  1201. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  1202. {
  1203. if (textField == _phone) {
  1204. [_pwd becomeFirstResponder];
  1205. }else{
  1206. [self.view endEditing:YES];
  1207. }
  1208. return YES;
  1209. }
  1210. - (void)areaCodeBtnClick:(UIButton *)but{
  1211. [self.view endEditing:YES];
  1212. JXTelAreaListVC *telAreaListVC = [[JXTelAreaListVC alloc] init];
  1213. telAreaListVC.telAreaDelegate = self;
  1214. telAreaListVC.didSelect = @selector(didSelectTelArea:);
  1215. // [g_window addSubview:telAreaListVC.view];
  1216. [g_navigation pushViewController:telAreaListVC animated:YES];
  1217. }
  1218. - (void)didSelectTelArea:(NSString *)areaCode{
  1219. [_areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@",areaCode] forState:UIControlStateNormal];
  1220. [self resetBtnEdgeInsets:_areaCodeBtn];
  1221. }
  1222. - (void)resetBtnEdgeInsets:(UIButton *)btn{
  1223. [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width-2, 0, btn.imageView.frame.size.width+2)];
  1224. [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width+2, 0, -btn.titleLabel.frame.size.width-2)];
  1225. }
  1226. - (void)passWordRightViewClicked:(UIButton *)but{
  1227. [_pwd resignFirstResponder];
  1228. but.selected = !but.selected;
  1229. _pwd.secureTextEntry = !but.selected;
  1230. }
  1231. - (void)didSelectedCheckBox:(QCheckBox *)checkbox checked:(BOOL)checked{
  1232. [g_default setObject:[NSNumber numberWithBool:checked] forKey:@"agreement"];
  1233. [g_default synchronize];
  1234. }
  1235. -(void)catUserProtocol{
  1236. webpageVC * webVC = [webpageVC alloc];
  1237. webVC.url = [self protocolUrl];
  1238. webVC.isSend = NO;
  1239. // [[NSBundle mainBundle] pathForResource:@"用户协议" ofType:@"html"];
  1240. webVC = [webVC init];
  1241. // [g_navigation.navigationView addSubview:webVC.view];
  1242. [g_navigation pushViewController:webVC animated:YES];
  1243. }
  1244. -(NSString *)protocolUrl{
  1245. NSString * protocolStr = g_config.privacyPolicyPrefix;
  1246. NSString * lange = g_constant.sysLanguage;
  1247. if (![lange isEqualToString:ZHHANTNAME] && ![lange isEqualToString:NAME]) {
  1248. lange = ENNAME;
  1249. }
  1250. // return [NSString stringWithFormat:@"%@%@.html",protocolStr,lange];
  1251. return [NSString stringWithFormat:@"%@",protocolStr];
  1252. }
  1253. // 获取启动图
  1254. - (NSString *)getLaunchImageName
  1255. {
  1256. NSString *viewOrientation = @"Portrait";
  1257. if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
  1258. viewOrientation = @"Landscape";
  1259. }
  1260. NSString *launchImageName = nil;
  1261. NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
  1262. CGSize viewSize = tyCurrentWindow.bounds.size;
  1263. for (NSDictionary* dict in imagesDict)
  1264. {
  1265. CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
  1266. if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]])
  1267. {
  1268. launchImageName = dict[@"UILaunchImageName"];
  1269. }
  1270. }
  1271. return launchImageName;
  1272. }
  1273. #pragma mark JXLocationDelegate
  1274. - (void)location:(JXLocation *)location CountryCode:(NSString *)countryCode CityName:(NSString *)cityName CityId:(NSString *)cityId Address:(NSString *)address Latitude:(double)lat Longitude:(double)lon{
  1275. g_server.countryCode = countryCode;
  1276. g_server.cityName = cityName;
  1277. g_server.cityId = [cityId intValue];
  1278. g_server.address = address;
  1279. g_server.latitude = lat;
  1280. g_server.longitude = lon;
  1281. NSDictionary *dict = @{@"latitude":@(lat),@"longitude":@(lon)};
  1282. [g_default setObject:dict forKey:kLocationLogin];
  1283. }
  1284. -(void)showTime:(NSTimer*)sender{
  1285. UIButton *but = (UIButton*)[_timer userInfo];
  1286. _seconds--;
  1287. [but setTitle:[NSString stringWithFormat:@"%ds",_seconds] forState:UIControlStateSelected];
  1288. if(_seconds<=0){
  1289. but.selected = NO;
  1290. but.userInteractionEnabled = YES;
  1291. but.backgroundColor = g_theme.themeColor;
  1292. [_send setTitle:Localized(@"JX_SendAngin") forState:UIControlStateNormal];
  1293. if (_timer) {
  1294. _timer = nil;
  1295. [sender invalidate];
  1296. }
  1297. _seconds = 60;
  1298. }
  1299. }
  1300. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  1301. [self.view endEditing:YES];
  1302. }
  1303. - (void)createWaitAuthView{
  1304. self.waitAuthView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT)];
  1305. self.waitAuthView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  1306. UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeAccount)];
  1307. [self.waitAuthView addGestureRecognizer:ges];
  1308. [self.view addSubview:self.waitAuthView];
  1309. UIView *authView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH - 80, JX_SCREEN_HEIGHT / 3)];
  1310. authView.backgroundColor = [UIColor whiteColor];
  1311. authView.layer.cornerRadius = 10;
  1312. authView.layer.masksToBounds = YES;
  1313. CGPoint center = authView.center;
  1314. UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 95, 95)];
  1315. imgV.image = [UIImage imageNamed:@"ALOGO_1200"];
  1316. [authView addSubview:imgV];
  1317. imgV.center = CGPointMake(center.x, 20 + 95/2);
  1318. UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH - 200, 50)];
  1319. lab.text = Localized(@"JX_WaitingForAuthorization");
  1320. lab.font = [UIFont systemFontOfSize:17];
  1321. lab.textColor = [UIColor blackColor];
  1322. lab.textAlignment = NSTextAlignmentCenter;
  1323. [authView addSubview:lab];
  1324. lab.center = CGPointMake(center.x, CGRectGetMaxY(imgV.frame) + 30);
  1325. UIButton *btn = [UIFactory createCommonButton:Localized(@"JX_SwitchAccount") target:self action:@selector(changeAccount)];
  1326. btn.custom_acceptEventInterval = 1.0f;
  1327. [btn.titleLabel setFont:g_factory.font17];
  1328. btn.layer.cornerRadius = 20;
  1329. btn.clipsToBounds = YES;
  1330. btn.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH-100*2, 40);
  1331. [authView addSubview:btn];
  1332. btn.center = CGPointMake(center.x, CGRectGetMaxY(authView.frame) - 40);
  1333. btn.userInteractionEnabled = NO;
  1334. [self.waitAuthView addSubview:authView];
  1335. authView.center = self.waitAuthView.center;
  1336. }
  1337. - (void)changeAccount{
  1338. [self.waitAuthView removeFromSuperview];
  1339. dispatch_cancel(_authTimer);
  1340. _authTimer = nil;
  1341. }
  1342. - (void)startAuthDevice:(NSString *)str{
  1343. if (_authTimer) {
  1344. dispatch_cancel(_authTimer);
  1345. _authTimer = nil;
  1346. }
  1347. dispatch_queue_t queue = dispatch_get_main_queue();
  1348. _authTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
  1349. dispatch_time_t start = DISPATCH_TIME_NOW;
  1350. dispatch_time_t interval = 1.0 * NSEC_PER_SEC;
  1351. dispatch_source_set_timer(_authTimer, start, interval, 0);
  1352. dispatch_source_set_event_handler(_authTimer, ^{
  1353. _count ++;
  1354. [g_server loginIsAuthKey:str toView:self];
  1355. if (_count == 300 ) {
  1356. _count = 0;
  1357. [self changeAccount];
  1358. }
  1359. });
  1360. dispatch_resume(_authTimer);
  1361. }
  1362. @end