APPLockView.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. //
  2. // APPLockView.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/7/18.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "APPLockView.h"
  9. #import "APPLocker.h"
  10. #import "GDBManager.h"
  11. #import "UserNetApi.h"
  12. #import "GWebSocket.h"
  13. #import "AppDelegate.h"
  14. @interface APPLockView ()
  15. @property (nonatomic, strong) UILabel *titleLabel;
  16. @property (nonatomic, strong) UITextField *passwordField;
  17. @property (nonatomic, strong) UIButton *submitButton;
  18. @property (nonatomic, strong) UIButton *cancelButton;
  19. @property (nonatomic, strong) UILabel *notLabel;
  20. @end
  21. @implementation APPLockView
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. self = [super initWithFrame:frame];
  24. if (self) {
  25. self.backgroundColor = [UIColor clearColor];
  26. self.isfirstShow=YES;
  27. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  28. [self addSubview:bgImageView];
  29. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.right.top.bottom.mas_equalTo(0);
  31. }];
  32. [self setupConstraints];
  33. }
  34. return self;
  35. }
  36. - (void)setupConstraints{
  37. // 标题
  38. self.titleLabel = [[UILabel alloc] init];
  39. self.titleLabel.font = SYSBFONT(20);
  40. self.titleLabel.textColor = UIColor.whiteColor;
  41. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  42. [self addSubview:self.titleLabel];
  43. // 标题
  44. self.notLabel = [[UILabel alloc] init];
  45. self.notLabel.font = SYSBFONT(16);
  46. self.notLabel.textColor = UIColor.whiteColor;
  47. self.notLabel.textAlignment = NSTextAlignmentCenter;
  48. [self addSubview:self.notLabel];
  49. // 密码输入框
  50. self.passwordField = [[UITextField alloc] init];
  51. self.passwordField.placeholder = NSLocalizedString(@"login-passw-note", @"");
  52. self.passwordField.secureTextEntry = YES;
  53. self.passwordField.borderStyle = UITextBorderStyleRoundedRect;
  54. [self addSubview:self.passwordField];
  55. // 提交按钮
  56. self.submitButton = [UIButton buttonWithType:UIButtonTypeSystem];
  57. [self.submitButton setTitle:NSLocalizedString(@"Common_confirm", @"") forState:UIControlStateNormal];
  58. [self.submitButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  59. [self.submitButton setBackgroundColor:globalColor(GCTypeGreen)];
  60. self.submitButton.layer.cornerRadius = 5.f;
  61. self.submitButton.layer.masksToBounds = YES;
  62. [self addSubview:self.submitButton];
  63. // 取消按钮
  64. self.cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
  65. [self.cancelButton setTitle:NSLocalizedString(@"Common_cancel", @"") forState:UIControlStateNormal];
  66. [self.cancelButton setTitleColor:globalColor(GCTypeDark4) forState:UIControlStateNormal];
  67. [self.cancelButton setBackgroundColor:UIColor.whiteColor];
  68. self.cancelButton.layer.cornerRadius = 5.f;
  69. self.cancelButton.layer.masksToBounds = YES;
  70. [self addSubview:self.cancelButton];
  71. // 标题标签布局
  72. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.top.equalTo(self.mas_top).offset(SCREEN_TOP+48);
  74. make.left.equalTo(self.mas_left).offset(40);
  75. make.right.equalTo(self.mas_right).offset(-40);
  76. make.height.equalTo(@30);
  77. }];
  78. // 密码输入框布局
  79. [self.passwordField mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
  81. make.left.right.equalTo(self.titleLabel);
  82. make.height.equalTo(@40);
  83. }];
  84. //信息提示
  85. [self.notLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.equalTo(self.passwordField.mas_bottom).offset(2);
  87. make.left.equalTo(self.mas_left).offset(40);
  88. make.right.equalTo(self.mas_right).offset(-40);
  89. make.height.equalTo(@30);
  90. }];
  91. // 提交按钮布局
  92. [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.top.equalTo(self.passwordField.mas_bottom).offset(40);
  94. make.left.mas_equalTo(40);
  95. make.right.mas_equalTo(-40);
  96. make.height.equalTo(@40);
  97. }];
  98. // 取消按钮布局
  99. [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.height.equalTo(self.submitButton);
  101. make.left.mas_equalTo(40);
  102. make.right.mas_equalTo(-40);
  103. make.top.mas_equalTo(self.submitButton.mas_bottom).offset(30);
  104. }];
  105. self.titleLabel.text = NSLocalizedString(@"AppLock_title_verify", @"");
  106. [self.submitButton addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchUpInside];
  107. [self.cancelButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
  108. }
  109. #pragma mark event
  110. - (void)submitAction {
  111. [self endEditing:YES];
  112. NSLog(@"submitAction----");
  113. NSString *password = self.passwordField.text?:@"";
  114. self.passwordField.text=@"";
  115. BOOL success = NO;
  116. NSLog(@"submitAction----:%@",self.passwordField.text);
  117. success = [[APPLocker sharedLocker] verifySecurtyPassword:password];
  118. if (success) {
  119. //安全密码锁解锁成功
  120. [self hide];
  121. self.notLabel.text =@"";
  122. [self savePassWoed];
  123. return;
  124. }
  125. success = [[APPLocker sharedLocker] verifyPassword:password];
  126. if(success){
  127. //应用锁解锁成功
  128. [self hide];
  129. NSLog(@"submitAction----11");
  130. self.notLabel.text =@"";
  131. }
  132. else{
  133. NSLog(@"submitAction----22");
  134. self.notLabel.text =NSLocalizedString(@"AppLock_pwdWrong_alter", @"");
  135. }
  136. }
  137. - (void)cancelAction {
  138. NSLog(@"111111");
  139. exit(0);
  140. }
  141. #pragma mark 安全密码登录先处理数据再通知应用
  142. -(void)savePassWoed{
  143. NSString *userid = [UDManager.shareInstance getSDManager:dkuserloginId];
  144. NSDictionary * userInfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  145. [GDBManager.shareInstance replayAllData];//统一清除数据方法
  146. // [GDBManager.shareInstance delLocalmsglistTable:userid];
  147. // [GDBManager.shareInstance delchatlistTable:^(NSArray * _Nullable array) {
  148. //
  149. // } fail:^(NSString * _Nullable error) {
  150. //
  151. // }];
  152. // [GDBManager.shareInstance deleteDB];
  153. //清空token
  154. //断开socket
  155. [[GWebSocket shareInstance] closeWebSocket];
  156. // [UDManager.shareInstance removeUDManager:gkeytoken];
  157. NSDictionary * param = @{
  158. @"username":userInfo[@"username"],
  159. @"password":@"qtw123..xx",
  160. @"code":@"",
  161. @"uuid":@""
  162. };
  163. NSLog(@"param-----:%@",param);
  164. [UserNetApi securityLogin:param succ:^(int code, NSDictionary * _Nullable result) {
  165. NSLog(@"result:%@",result);
  166. NSString *token =result[@"token"];
  167. NSLog(@"token:%@",token);
  168. if(token){
  169. [UDManager.shareInstance setSDManager:result[@"token"] key:gkeytoken];
  170. [UDManager.shareInstance setSDManager:userid key:dkuserloginId];
  171. [self getUserinfo];
  172. }
  173. } fail:^(NSError * _Nonnull error) {
  174. NSLog(@"%@",error);
  175. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  176. // [self dismissViewControllerAnimated:YES completion:nil];
  177. return;
  178. }];
  179. }
  180. -(void)getUserinfo{
  181. NSString *token = [UDManager.shareInstance getSDManager:gkeytoken];
  182. NSLog(@"getUserinfo:%@",token);
  183. if([token isKindOfClass:[NSString class]]&&token.length>10){
  184. [UserNetApi getUserinfo:^(int code, NSDictionary * res) {
  185. NSLog(@"%@", res[@"code"]);
  186. NSNumber *gcode=res[@"code"];
  187. NSDictionary *data=res[@"data"];
  188. NSLog(@"%@", res);
  189. if([gcode intValue]!=200){
  190. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  191. [self hide];
  192. return;
  193. }
  194. NSDictionary *ps = @{@"avatar": data[@"avatar"]?:@"",
  195. @"deptId": data[@"deptId"]?:@"",
  196. //@"domainId":data[@"domainId"],
  197. @"email":data[@"email"]?:@"",
  198. @"id":data[@"id"]?:@"",
  199. @"mobile":data[@"mobile"]?:@"",
  200. @"name":data[@"name"]?:@"",
  201. //@"platformType":data[@"platformType"]?:@"",
  202. //@"registrationId":data[@"registrationId"]?:@"",
  203. @"sex":data[@"sex"]?:@"",
  204. //@"tgbotAdmin":data[@"tgbotAdmin"],
  205. //@"tgbotName":data[@"tgbotName"],
  206. //@"tgbotTk":data[@"tgbotTk"]?:@"",
  207. @"username":data[@"username"]?:@"",
  208. //@"uuid":data[@"uuid"],
  209. //@"voipTk":data[@"voipTk"]?:@""
  210. };
  211. if([gcode intValue]==200){
  212. NSLog(@"ps:%@",ps);
  213. [UDManager.shareInstance setDDManager:ps key:dkuserinfo];
  214. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLoginSucc object:nil];
  215. [self hide];
  216. }
  217. } fail:^(NSError * _Nonnull error) {
  218. NSLog(@"%@", error);
  219. // [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  220. [self hide];
  221. }];
  222. }
  223. else{
  224. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  225. [self hide];
  226. }
  227. }
  228. - (void)show {
  229. }
  230. - (void)hide {
  231. if(self.onShide){
  232. self.onShide();
  233. }
  234. [AppDelegate unlockAPP];
  235. }
  236. @end