GLoginController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //
  2. // GLoginController.m
  3. // aiim
  4. //
  5. // Created by gan on 2025/2/27.
  6. //
  7. #import "GLoginController.h"
  8. #import "UserNetApi.h"
  9. #import "AppDelegate.h"
  10. #import "UDManager.h"
  11. #import "config.h"
  12. #import "GSignController.h"
  13. #import <AdSupport/AdSupport.h>
  14. #import "FilePreviewer.h"
  15. #import "GCoverController.h"
  16. @interface GLoginController ()
  17. @property (weak, nonatomic) IBOutlet UITextField *userId;
  18. @property (weak, nonatomic) IBOutlet UITextField *password;
  19. @property (weak, nonatomic) IBOutlet UIButton *loginBt;
  20. @property (weak, nonatomic) IBOutlet UIButton *wangjiBt;
  21. @property (weak, nonatomic) IBOutlet UIButton *signBt;
  22. @property (weak, nonatomic) IBOutlet UILabel *meiyouzhlb;
  23. @property (weak, nonatomic) IBOutlet UIButton *agreedBt;
  24. @property (nonatomic) BOOL isagreed;
  25. @property (nonatomic) NSInteger reLoginC;
  26. @end
  27. @implementation GLoginController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. [self.navigationController setNavigationBarHidden:YES animated:NO];
  31. // Do any additional setup after loading the view.
  32. NSLog(@"GLoginController viewDidLoad");
  33. // 创建一个点击手势
  34. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  35. // 将手势添加到主视图上
  36. [self.view addGestureRecognizer:tap];
  37. _isagreed=false;
  38. NSString *agreed = [UDManager.shareInstance getSDManager:dkagreed];
  39. if(agreed){
  40. if([agreed isEqualToString:@"1"]){
  41. _isagreed = true;
  42. }
  43. }
  44. [self initsubView];
  45. _reLoginC = 0;
  46. [self getUserinfo];
  47. }
  48. -(void)initsubView{
  49. _userId.borderStyle=UITextBorderStyleNone;
  50. _userId.layer.borderWidth = 1.0f;
  51. _userId.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  52. _userId.layer.cornerRadius = 8.0f; // 可选,设置圆角
  53. _userId.backgroundColor = [UIColor clearColor];
  54. _userId.textColor=[UIColor whiteColor];
  55. NSString *note = NSLocalizedString(@"login-usernme-note", @"");
  56. NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  57. UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  58. _userId.leftView = paddingView;
  59. _userId.leftViewMode = UITextFieldViewModeAlways;
  60. _userId.attributedPlaceholder = placeholder;
  61. _password.borderStyle=UITextBorderStyleNone;
  62. _password.layer.borderWidth = 1.0f;
  63. _password.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  64. _password.layer.cornerRadius = 8.0f; // 可选,设置圆角
  65. _password.backgroundColor = [UIColor clearColor];
  66. _password.textColor=[UIColor whiteColor];
  67. note = NSLocalizedString(@"login-passw-note", @"");
  68. NSMutableAttributedString *placeholder2 = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  69. UIView *paddingView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  70. _password.leftView = paddingView2;
  71. _password.leftViewMode = UITextFieldViewModeAlways;
  72. _password.attributedPlaceholder = placeholder2;
  73. [_loginBt setTitle:NSLocalizedString(@"login-denglu", @"登录") forState:UIControlStateNormal];
  74. _loginBt.titleLabel.font = [UIFont systemFontOfSize: 19.0];
  75. [_loginBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  76. [_loginBt setBackgroundColor:globalColor(GCTypeGreen)];
  77. _loginBt.layer.cornerRadius = 27;
  78. _loginBt.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  79. NSString *vendorIdentifier = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
  80. NSLog(@"vendorIdentifier:%@",vendorIdentifier);
  81. _wangjiBt.titleLabel.font = [UIFont systemFontOfSize: 14.0];
  82. [_wangjiBt setTitleColor:globalColor(GCTypeGreen) forState:UIControlStateNormal];
  83. [_wangjiBt setTitle:NSLocalizedString(@"login-wangjimm", @"忘记密码?") forState:UIControlStateNormal];
  84. _signBt.titleLabel.font = [UIFont systemFontOfSize: 14.0];
  85. [_signBt setTitleColor:globalColor(GCTypeGreen) forState:UIControlStateNormal];
  86. [_signBt setTitle:NSLocalizedString(@"login-quzhuce", @"去注册") forState:UIControlStateNormal];
  87. _meiyouzhlb.text =NSLocalizedString(@"login-meiyouzh", @"没有账号?");
  88. if(_isagreed){
  89. [_agreedBt setImage:kImageMake(@"checkbox_selected") forState:UIControlStateNormal];
  90. }
  91. else{
  92. [_agreedBt setImage:kImageMake(@"checkbox_unselected") forState:UIControlStateNormal];
  93. }
  94. }
  95. -(void)dismissKeyboard{
  96. NSLog(@"dismissKeyboard");
  97. [self.view endEditing:YES];
  98. }
  99. - (IBAction)login:(id)sender {
  100. if(!_isagreed){
  101. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认"
  102. message:@"同意接受隱私政策"
  103. preferredStyle:UIAlertControllerStyleAlert];
  104. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"查看政策"
  105. style:UIAlertActionStyleCancel
  106. handler:^(UIAlertAction * action) {
  107. // 点击后的操作
  108. [[FilePreviewer shared] previewFileWithLocalPath:@"" remoteURL:getURL(privacyPolicy) fromViewController:self];
  109. }];
  110. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"同意"
  111. style:UIAlertActionStyleDefault
  112. handler:^(UIAlertAction * action) {
  113. [UDManager.shareInstance setSDManager:@"1" key:dkagreed];
  114. self->_isagreed=YES;
  115. [self->_agreedBt setImage:kImageMake(@"checkbox_selected") forState:UIControlStateNormal];
  116. [self loginAct];
  117. // 点击确定后的操作
  118. }];
  119. [alert addAction:cancelAction];
  120. [alert addAction:okAction];
  121. [self presentViewController:alert animated:YES completion:nil];
  122. return;
  123. }
  124. [MBProgressHUD showLoadingWithText:@"" inView:self.view];
  125. [self loginAct];
  126. }
  127. -(void)loginAct{
  128. [self.view endEditing:YES];
  129. NSString *userid = self.userId.text;
  130. NSString *password = self.password.text;
  131. NSDictionary *ps = @{@"username": userid,
  132. @"password": password,
  133. @"code": @"",
  134. @"version":@"111",
  135. @"uuid": @""};
  136. [UserNetApi login:ps succ:^(int code, NSDictionary * res) {
  137. NSLog(@"%@",res);
  138. self->_reLoginC=4;
  139. [MBProgressHUD hideAllTipsInView:self.view];
  140. NSString *codes = res[@"code"];
  141. if(codes.intValue!=200){
  142. [MBProgressHUD showWithText:res[@"msg"]];
  143. return;
  144. }
  145. NSLog(@"%@",res[@"token"]);
  146. NSString *token =res[@"token"];
  147. if(token){
  148. [UDManager.shareInstance setSDManager:res[@"token"] key:gkeytoken];
  149. [UDManager.shareInstance setSDManager:userid key:dkuserloginId];
  150. [self getUserinfo];
  151. }
  152. else{
  153. [MBProgressHUD showWithText:@"数据异常"];
  154. }
  155. } fail:^(NSError * _Nonnull error) {
  156. NSLog(@"--%@",error);
  157. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  158. if(self->_reLoginC<3){
  159. self->_reLoginC=self->_reLoginC+1;
  160. [self loginAct];
  161. }
  162. else{
  163. [MBProgressHUD hideAllTipsInView:self.view];
  164. }
  165. });
  166. }];
  167. }
  168. - (IBAction)wangjimm:(id)sender {
  169. GCoverController * resetPwdVc = [[GCoverController alloc] init];
  170. resetPwdVc.isLogin = YES;
  171. resetPwdVc.modalPresentationStyle = UIModalPresentationFullScreen;
  172. [self presentViewController:resetPwdVc animated:YES completion:nil];
  173. }
  174. - (IBAction)sign:(id)sender {
  175. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  176. GSignController *chatctr = [board instantiateViewControllerWithIdentifier:@"GSignController"];
  177. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  178. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  179. [self presentViewController :uiNavC animated:YES completion:nil];
  180. }
  181. #pragma mark private
  182. -(void)getUserinfo{
  183. NSString *token = [UDManager.shareInstance getSDManager:gkeytoken];
  184. if([token isKindOfClass:[NSString class]]&&token.length>10){
  185. [UserNetApi getUserinfo:^(int code, NSDictionary * res) {
  186. NSLog(@"%d", code);
  187. NSNumber *gcode=res[@"code"];
  188. NSDictionary *data=res[@"data"];
  189. NSLog(@"%@", res);
  190. if([gcode intValue]!=200){
  191. NSLog(@"%@",res[@"msg"]);
  192. [MBProgressHUD showWithText:@"登录异常,请重新登录"];
  193. return;
  194. }
  195. NSDictionary *ps = @{@"avatar": data[@"avatar"]?:@"",
  196. @"deptId": data[@"deptId"]?:@"",
  197. //@"domainId":data[@"domainId"],
  198. @"email":data[@"email"]?:@"",
  199. @"id":data[@"id"]?:@"",
  200. @"mobile":data[@"mobile"]?:@"",
  201. @"name":data[@"name"]?:@"",
  202. //@"platformType":data[@"platformType"]?:@"",
  203. //@"registrationId":data[@"registrationId"]?:@"",
  204. @"sex":data[@"sex"]?:@"",
  205. //@"tgbotAdmin":data[@"tgbotAdmin"],
  206. //@"tgbotName":data[@"tgbotName"],
  207. //@"tgbotTk":data[@"tgbotTk"]?:@"",
  208. @"username":data[@"username"]?:@"",
  209. //@"uuid":data[@"uuid"],
  210. //@"voipTk":data[@"voipTk"]?:@""
  211. };
  212. if([gcode intValue]==200){
  213. NSLog(@"ps:%@",ps);
  214. [MBProgressHUD showWithText:@"登录成功"];
  215. [MBProgressHUD hideAllTipsInView:self.view];
  216. [UDManager.shareInstance setSDManager:ps[@"id"] key:dkuserId];
  217. [UDManager.shareInstance setDDManager:ps key:dkuserinfo];
  218. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLoginSucc object:nil];
  219. }
  220. } fail:^(NSError * _Nonnull error) {
  221. NSLog(@"%@", error);
  222. // 使用GCD创建一个在3秒后执行的定时器
  223. [MBProgressHUD hideAllTipsInView:self.view];
  224. }];
  225. }
  226. }
  227. - (IBAction)agreedAct:(id)sender {
  228. _isagreed=!_isagreed;
  229. if(_isagreed){
  230. [_agreedBt setImage:kImageMake(@"checkbox_selected") forState:UIControlStateNormal];
  231. [UDManager.shareInstance setSDManager:@"1" key:dkagreed];
  232. }
  233. else{
  234. [_agreedBt setImage:kImageMake(@"checkbox_unselected") forState:UIControlStateNormal];
  235. [UDManager.shareInstance setSDManager:@"0" key:dkagreed];
  236. }
  237. }
  238. - (IBAction)yinsizhengc:(id)sender {
  239. [[FilePreviewer shared] previewFileWithLocalPath:@"" remoteURL:getURL(privacyPolicy) fromViewController:self];
  240. }
  241. @end