GLoginController.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 "FilePreviewer.h"
  14. #import "GCoverController.h"
  15. #import "LoginStateManager.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. @end
  26. @implementation GLoginController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. [self.navigationController setNavigationBarHidden:YES animated:NO];
  30. // Do any additional setup after loading the view.
  31. NSLog(@"GLoginController viewDidLoad");
  32. // 创建一个点击手势
  33. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  34. // 将手势添加到主视图上
  35. [self.view addGestureRecognizer:tap];
  36. _isagreed=false;
  37. NSString *agreed = [UDManager.shareInstance getSDManager:dkagreed];
  38. if(agreed){
  39. if([agreed isEqualToString:@"1"]){
  40. _isagreed = true;
  41. }
  42. }
  43. [self initsubView];
  44. }
  45. -(void)initsubView{
  46. _userId.borderStyle=UITextBorderStyleNone;
  47. _userId.layer.borderWidth = 1.0f;
  48. _userId.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  49. _userId.layer.cornerRadius = 8.0f; // 可选,设置圆角
  50. _userId.backgroundColor = [UIColor clearColor];
  51. _userId.textColor=[UIColor whiteColor];
  52. NSString *note = NSLocalizedString(@"login-usernme-note", @"");
  53. NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  54. UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  55. _userId.leftView = paddingView;
  56. _userId.leftViewMode = UITextFieldViewModeAlways;
  57. _userId.attributedPlaceholder = placeholder;
  58. _password.borderStyle=UITextBorderStyleNone;
  59. _password.layer.borderWidth = 1.0f;
  60. _password.layer.borderColor = globalColor(GCTypeGreen).CGColor; //globalColor(GCTypeGreen);
  61. _password.layer.cornerRadius = 8.0f; // 可选,设置圆角
  62. _password.backgroundColor = [UIColor clearColor];
  63. _password.textColor=[UIColor whiteColor];
  64. note = NSLocalizedString(@"login-passw-note", @"");
  65. NSMutableAttributedString *placeholder2 = [[NSMutableAttributedString alloc] initWithString:note attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}];
  66. UIView *paddingView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
  67. _password.leftView = paddingView2;
  68. _password.leftViewMode = UITextFieldViewModeAlways;
  69. _password.attributedPlaceholder = placeholder2;
  70. [_loginBt setTitle:NSLocalizedString(@"login-denglu", @"登录") forState:UIControlStateNormal];
  71. _loginBt.titleLabel.font = [UIFont systemFontOfSize: 19.0];
  72. [_loginBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  73. [_loginBt setBackgroundColor:globalColor(GCTypeGreen)];
  74. _loginBt.layer.cornerRadius = 27;
  75. _loginBt.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  76. _wangjiBt.titleLabel.font = [UIFont systemFontOfSize: 14.0];
  77. [_wangjiBt setTitleColor:globalColor(GCTypeGreen) forState:UIControlStateNormal];
  78. [_wangjiBt setTitle:NSLocalizedString(@"login-wangjimm", @"忘记密码?") forState:UIControlStateNormal];
  79. _signBt.titleLabel.font = [UIFont systemFontOfSize: 14.0];
  80. [_signBt setTitleColor:globalColor(GCTypeGreen) forState:UIControlStateNormal];
  81. [_signBt setTitle:NSLocalizedString(@"login-quzhuce", @"去注册") forState:UIControlStateNormal];
  82. _meiyouzhlb.text =NSLocalizedString(@"login-meiyouzh", @"没有账号?");
  83. if(_isagreed){
  84. [_agreedBt setImage:kImageMake(@"checkbox_selected") forState:UIControlStateNormal];
  85. }
  86. else{
  87. [_agreedBt setImage:kImageMake(@"checkbox_unselected") forState:UIControlStateNormal];
  88. }
  89. }
  90. -(void)dismissKeyboard{
  91. NSLog(@"dismissKeyboard");
  92. [self.view endEditing:YES];
  93. }
  94. - (IBAction)login:(id)sender {
  95. if(!_isagreed){
  96. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认"
  97. message:@"同意接受隱私政策"
  98. preferredStyle:UIAlertControllerStyleAlert];
  99. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"查看政策"
  100. style:UIAlertActionStyleCancel
  101. handler:^(UIAlertAction * action) {
  102. // 点击后的操作
  103. [[FilePreviewer shared] previewFileWithLocalPath:@"" remoteURL:getURL(privacyPolicy) fromViewController:self];
  104. }];
  105. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"同意"
  106. style:UIAlertActionStyleDefault
  107. handler:^(UIAlertAction * action) {
  108. [UDManager.shareInstance setSDManager:@"1" key:dkagreed];
  109. self->_isagreed=YES;
  110. [self->_agreedBt setImage:kImageMake(@"checkbox_selected") forState:UIControlStateNormal];
  111. [self loginAct];
  112. // 点击确定后的操作
  113. }];
  114. [alert addAction:cancelAction];
  115. [alert addAction:okAction];
  116. [self presentViewController:alert animated:YES completion:nil];
  117. return;
  118. }
  119. [self loginAct];
  120. }
  121. -(void)loginAct{
  122. [self.view endEditing:YES];
  123. NSString *userid = self.userId.text;
  124. NSString *password = self.password.text;
  125. NSDictionary *ps = @{@"username": userid,
  126. @"password": password,
  127. @"code": @"",
  128. @"version":@"111",
  129. @"uuid": @""};
  130. [MBProgressHUD showLoadingWithText:@"" inView:self.view];
  131. [UserNetApi login:ps succ:^(int code, NSDictionary * res) {
  132. dispatch_main_async_safe(^{
  133. NSLog(@"%@",res);
  134. NSString *codes = res[@"code"];
  135. if(codes.intValue!=200){
  136. [MBProgressHUD showWithText:res[@"msg"]];
  137. return;
  138. }
  139. NSString *token =res[@"token"];
  140. if([token isKindOfClass:NSString.class]){
  141. [UDManager.shareInstance setSDManager:token key:gkeytoken];
  142. [UDManager.shareInstance setSDManager:userid key:dkuserloginId];
  143. [[LoginStateManager sharedManager] requestUserInfoWith:^(BOOL isSuccess) {
  144. [MBProgressHUD hideAllTipsInView:self.view];
  145. if (isSuccess) {
  146. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLoginSucc object:nil];
  147. }
  148. }];
  149. }
  150. else{
  151. [MBProgressHUD showWithText:@"数据异常"];
  152. }
  153. })
  154. } fail:^(NSError * _Nonnull error) {
  155. NSLog(@"--%@",error);
  156. dispatch_main_async_safe(^{
  157. [MBProgressHUD showWithText:error.localizedDescription];
  158. })
  159. }];
  160. }
  161. - (IBAction)wangjimm:(id)sender {
  162. GCoverController * resetPwdVc = [[GCoverController alloc] init];
  163. resetPwdVc.isLogin = YES;
  164. resetPwdVc.modalPresentationStyle = UIModalPresentationFullScreen;
  165. [self presentViewController:resetPwdVc animated:YES completion:nil];
  166. }
  167. - (IBAction)sign:(id)sender {
  168. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  169. GSignController *chatctr = [board instantiateViewControllerWithIdentifier:@"GSignController"];
  170. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  171. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  172. [self presentViewController :uiNavC animated:YES completion:nil];
  173. }
  174. #pragma mark private
  175. - (IBAction)agreedAct:(id)sender {
  176. _isagreed=!_isagreed;
  177. if(_isagreed){
  178. [_agreedBt setImage:kImageMake(@"checkbox_selected") forState:UIControlStateNormal];
  179. [UDManager.shareInstance setSDManager:@"1" key:dkagreed];
  180. }
  181. else{
  182. [_agreedBt setImage:kImageMake(@"checkbox_unselected") forState:UIControlStateNormal];
  183. [UDManager.shareInstance setSDManager:@"0" key:dkagreed];
  184. }
  185. }
  186. - (IBAction)yinsizhengc:(id)sender {
  187. [[FilePreviewer shared] previewFileWithLocalPath:@"" remoteURL:getURL(privacyPolicy) fromViewController:self];
  188. }
  189. @end