JXAuthViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // JXAuthViewController.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/11/2.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXAuthViewController.h"
  9. @interface JXAuthViewController ()
  10. @end
  11. @implementation JXAuthViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. self.isGotoBack = NO;
  16. // self.title = [NSString stringWithFormat:@"%@%@",APP_NAME,Localized(@"JX_Login")];
  17. self.heightFooter = 0;
  18. self.heightHeader = JX_SCREEN_TOP;
  19. [self createHeadAndFoot];
  20. JXImageView *icon = [[JXImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2-85/2, 81, 85, 85)];
  21. icon.image = [UIImage imageNamed:@"ALOGO_1200"];
  22. [self.tableBody addSubview:icon];
  23. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(icon.frame) + 21, JX_SCREEN_WIDTH, 18)];
  24. label.font = [UIFont systemFontOfSize:18.0];
  25. label.textColor = HEXCOLOR(0x333333);
  26. label.text = [NSString stringWithFormat:@"%@",APP_NAME];
  27. label.textAlignment = NSTextAlignmentCenter;
  28. [self.tableBody addSubview:label];
  29. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(35, CGRectGetMaxY(label.frame)+50, JX_SCREEN_WIDTH-70, LINE_WH)];
  30. line.backgroundColor = THE_LINE_COLOR;
  31. [self.tableBody addSubview:line];
  32. label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame) + 25, JX_SCREEN_WIDTH, 16)];
  33. label.font = [UIFont systemFontOfSize:16];
  34. label.textColor = HEXCOLOR(0x333333);
  35. label.text = Localized(@"JX_AfterLogin");
  36. label.textAlignment = NSTextAlignmentCenter;
  37. [self.tableBody addSubview:label];
  38. UIView *view = [[UIView alloc] init];
  39. view.frame = CGRectMake((JX_SCREEN_WIDTH-13-6-246)/2,CGRectGetMaxY(label.frame) + 17,13,13);
  40. view.backgroundColor = HEXCOLOR(0xD8D8D8);
  41. view.layer.masksToBounds = YES;
  42. view.layer.cornerRadius = view.frame.size.width/2;
  43. [self.tableBody addSubview:view];
  44. label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view.frame)+6, CGRectGetMaxY(label.frame) + 16, 246, 15)];
  45. label.font = [UIFont systemFontOfSize:15];
  46. label.textColor = HEXCOLOR(0x999999);
  47. label.textAlignment = NSTextAlignmentCenter;
  48. label.text = Localized(@"JX_GetPublicInformation");
  49. [self.tableBody addSubview:label];
  50. UIButton *btn = [UIFactory createCommonButton:Localized(@"JX_ConfirmTheLogin") target:self action:@selector(loginBtnAction:)];
  51. btn.frame = CGRectMake(15, CGRectGetMaxY(label.frame) + 50, JX_SCREEN_WIDTH - 30, 40);
  52. [btn.titleLabel setFont:SYSFONT(16)];
  53. btn.layer.masksToBounds = YES;
  54. btn.layer.cornerRadius = 7.f;
  55. [self.tableBody addSubview:btn];
  56. //取消登录
  57. btn = [UIFactory createCommonButton:Localized(@"JX_CancelLogin") target:self action:@selector(quiteCurVC)];
  58. [btn setBackgroundImage:nil forState:UIControlStateHighlighted];
  59. [btn setBackgroundImage:nil forState:UIControlStateNormal];
  60. btn.custom_acceptEventInterval = 1.f;
  61. btn.frame = CGRectMake(JX_SCREEN_WIDTH/2-30,CGRectGetMaxY(label.frame) +50+40+ 32, 60, 30);
  62. [btn.titleLabel setFont:SYSFONT(14)];
  63. [btn setTitleColor:HEXCOLOR(0x999999) forState:UIControlStateNormal];
  64. btn.backgroundColor = [UIColor clearColor];
  65. [self.tableBody addSubview:btn];
  66. }
  67. - (void)quiteCurVC {
  68. [super actionQuit];
  69. }
  70. - (void)loginBtnAction:(UIButton *)btn {
  71. if (self.isWebAuth) {
  72. [g_server openCodeAuthorCheckAppId:self.appId state:g_server.access_token callbackUrl:self.callbackUrl toView:self];
  73. }else {
  74. [g_server openOpenAuthInterfaceWithUserId:g_myself.userId appId:self.appId appSecret:self.appSecret type:1 toView:self];
  75. }
  76. }
  77. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  78. [_wait hide];
  79. if([aDownload.action isEqualToString:act_OpenAuthInterface]){
  80. if ([dict[@"flag"] intValue] != 1) {
  81. [g_App showAlert:Localized(@"JX_NoCertification")];
  82. return;
  83. }
  84. NSString* s;
  85. if([dict[@"userId"] isKindOfClass:[NSNumber class]])
  86. s = [(NSNumber*)dict[@"userId"] stringValue];
  87. else
  88. s = dict[@"userId"];
  89. if([s length]<=0)
  90. return;
  91. NSString* dir = [NSString stringWithFormat:@"%d",[s intValue] % 10000];
  92. NSString* url = [NSString stringWithFormat:@"%@avatar/o/%@/%@.jpg",g_config.downloadAvatarUrl,dir,s];
  93. NSString *str = [NSString stringWithFormat:@"%@://type=%@,userId=%@,nickName=%@,avatarUrl=%@,birthday=%@,sex=%@",self.urlSchemes,@"Auth",dict[@"userId"],g_myself.userNickname,url,[NSString stringWithFormat:@"%@",g_myself.birthday],[NSString stringWithFormat:@"%@",g_myself.sex]];
  94. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] options:nil completionHandler:^(BOOL success) {
  95. }];
  96. [self actionQuit];
  97. }
  98. if ([aDownload.action isEqualToString:act_openCodeAuthorCheck]) {
  99. NSString *callbackUrl = [dict objectForKey:@"callbackUrl"];
  100. callbackUrl = [callbackUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  101. NSString *url;
  102. if ([callbackUrl rangeOfString:@"?"].location != NSNotFound) {
  103. url = [NSString stringWithFormat:@"%@&code=%@",callbackUrl,[dict objectForKey:@"code"]];
  104. }else {
  105. url = [NSString stringWithFormat:@"%@?code=%@",callbackUrl,[dict objectForKey:@"code"]];
  106. }
  107. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  108. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  109. [self actionQuit];
  110. }
  111. }
  112. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  113. [_wait hide];
  114. return show_error;
  115. }
  116. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  117. [_wait hide];
  118. return show_error;
  119. }
  120. -(void) didServerConnectStart:(JXConnection*)aDownload{
  121. [_wait start];
  122. }
  123. - (void)actionQuit {
  124. [self dismissViewControllerAnimated:YES completion:nil];
  125. }
  126. - (void)didReceiveMemoryWarning {
  127. [super didReceiveMemoryWarning];
  128. // Dispose of any resources that can be recreated.
  129. }
  130. /*
  131. #pragma mark - Navigation
  132. // In a storyboard-based application, you will often want to do a little preparation before navigation
  133. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  134. // Get the new view controller using [segue destinationViewController].
  135. // Pass the selected object to the new view controller.
  136. }
  137. */
  138. @end