SetPWDSecondViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. //
  2. // SetPWDSecondViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "SetPWDSecondViewController.h"
  8. #import <Masonry.h>
  9. #import "connectDeviceManager.h"
  10. #import "privacyModeTipViewController.h"
  11. @interface SetPWDSecondViewController (){
  12. NSString *pwd;
  13. UILabel *pointView0;
  14. UILabel *pointView1;
  15. UILabel *pointView2;
  16. UILabel *pointView3;
  17. UILabel *topLabel;
  18. UIButton *keyBoardBtn0;
  19. }
  20. @end
  21. @implementation SetPWDSecondViewController
  22. @synthesize oldPWD;
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. pwd = @"";
  27. [self drawAnyView];
  28. }
  29. - (void)drawAnyView{
  30. [self.navigationBar setHidden:YES];
  31. [self.toolBar setHidden:YES];
  32. [self.view setBackgroundColor:HWF5F7FAColor];
  33. /*上一步按钮*/
  34. UIButton *upStepBtn = [[UIButton alloc] init];
  35. [upStepBtn setTitle:NSLocalizedString(@"guide_set_pwd_up_step",nil) forState:(UIControlStateNormal)];
  36. [upStepBtn setTitleColor:HW05BAFBColor forState:(UIControlStateNormal)];
  37. [upStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  38. [upStepBtn addTarget:self.navigationController
  39. action:@selector(popViewControllerAnimated:)
  40. forControlEvents:(UIControlEventTouchUpInside)];
  41. [self.view addSubview:upStepBtn];
  42. [upStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.mas_equalTo(10.f);
  44. make.width.mas_equalTo(58.f);
  45. make.top.mas_equalTo(5.f + H_STATE_BAR);
  46. make.height.mas_equalTo(32.f);
  47. }];
  48. /*设置密码标题*/
  49. topLabel = [[UILabel alloc] init];
  50. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  51. [topLabel setTextColor:HW333333Color];
  52. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  53. [topLabel setText:NSLocalizedString(@"guide_set_pwd_makesure_title",nil)];
  54. [self.view addSubview:topLabel];
  55. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(20);
  57. make.right.mas_equalTo(-20);
  58. make.top.mas_equalTo(99.f + H_STATE_BAR);
  59. }];
  60. CGFloat w_pwd = 24.f;
  61. CGFloat h_pwd = 24.f;
  62. CGFloat pointFont = 20.f;
  63. /*密码视图*/
  64. pointView0 = [[UILabel alloc] init];
  65. [pointView0 setTextColor:HW0A132BColor];
  66. [pointView0 setBackgroundColor:HWE3E8F1Color];
  67. [pointView0 setClipsToBounds:YES];
  68. [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
  69. [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
  70. [pointView0.layer setCornerRadius:w_pwd/2.f];
  71. [self.view addSubview:pointView0];
  72. [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  74. make.height.mas_equalTo(h_pwd);
  75. make.width.mas_equalTo(w_pwd);
  76. make.top.mas_equalTo(151.f + H_STATE_BAR);
  77. }];
  78. pointView1 = [[UILabel alloc] init];
  79. [pointView1 setTextColor:HW0A132BColor];
  80. [pointView1 setBackgroundColor:HWE3E8F1Color];
  81. [pointView1 setClipsToBounds:YES];
  82. [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
  83. [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
  84. [pointView1.layer setCornerRadius:w_pwd/2.f];
  85. [self.view addSubview:pointView1];
  86. [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  88. make.height.mas_equalTo(h_pwd);
  89. make.width.mas_equalTo(w_pwd);
  90. make.top.mas_equalTo(151.f + H_STATE_BAR);
  91. }];
  92. pointView2 = [[UILabel alloc] init];
  93. [pointView2 setTextColor:HW0A132BColor];
  94. [pointView2 setBackgroundColor:HWE3E8F1Color];
  95. [pointView2 setClipsToBounds:YES];
  96. [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
  97. [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
  98. [pointView2.layer setCornerRadius:w_pwd/2.f];
  99. [self.view addSubview:pointView2];
  100. [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  102. make.height.mas_equalTo(h_pwd);
  103. make.width.mas_equalTo(w_pwd);
  104. make.top.mas_equalTo(151.f + H_STATE_BAR);
  105. }];
  106. pointView3 = [[UILabel alloc] init];
  107. [pointView3 setTextColor:HW0A132BColor];
  108. [pointView3 setBackgroundColor:HWE3E8F1Color];
  109. [pointView3 setClipsToBounds:YES];
  110. [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
  111. [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
  112. [pointView3.layer setCornerRadius:w_pwd/2.f];
  113. [self.view addSubview:pointView3];
  114. [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  116. make.height.mas_equalTo(h_pwd);
  117. make.width.mas_equalTo(w_pwd);
  118. make.top.mas_equalTo(151.f + H_STATE_BAR);
  119. }];
  120. /*下方绘制键盘按钮*/
  121. UIView *bgViewForNumberBoard = [[UIView alloc] init];
  122. [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
  123. CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
  124. CGFloat h_bgViewForNumberBoard = 330.f;
  125. [self.view addSubview:bgViewForNumberBoard];
  126. [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.mas_equalTo(22.f*AUTOSCALE);
  128. make.height.mas_equalTo(h_bgViewForNumberBoard);
  129. make.width.mas_equalTo(w_bgViewForNumberBoard);
  130. make.bottom.mas_equalTo(-70.f);
  131. }];
  132. CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
  133. CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
  134. /*绘制键盘 1~9*/
  135. for (NSInteger nFori = 0; nFori < 9; nFori++) {
  136. CGFloat x_key_btn = (nFori%3)*w_key_btn;
  137. CGFloat y_key_btn = (nFori/3)*h_key_btn;
  138. UIButton *keyBoardBtn = [[UIButton alloc] init];
  139. [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
  140. [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  141. [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  142. [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
  143. [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  144. [bgViewForNumberBoard addSubview:keyBoardBtn];
  145. [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.left.mas_equalTo(x_key_btn);
  147. make.top.mas_equalTo(y_key_btn);
  148. make.width.mas_equalTo(w_key_btn);
  149. make.height.mas_equalTo(h_key_btn);
  150. }];
  151. }
  152. /*删除按钮*/
  153. UIButton *deleteBoardBtn = [[UIButton alloc] init];
  154. [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
  155. [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  156. [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
  157. [bgViewForNumberBoard addSubview:deleteBoardBtn];
  158. [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.left.mas_equalTo(0);
  160. make.bottom.mas_equalTo(0);
  161. make.width.mas_equalTo(w_key_btn);
  162. make.height.mas_equalTo(h_key_btn);
  163. }];
  164. /*0*/
  165. keyBoardBtn0 = [[UIButton alloc] init];
  166. [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
  167. [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  168. [keyBoardBtn0 setTitleColor:COLOR_PACEHOLDER forState:(UIControlStateDisabled)];
  169. [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  170. [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
  171. [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  172. keyBoardBtn0.enabled = NO;
  173. [bgViewForNumberBoard addSubview:keyBoardBtn0];
  174. [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
  175. make.left.mas_equalTo(w_key_btn);
  176. make.bottom.mas_equalTo(0);
  177. make.width.mas_equalTo(w_key_btn);
  178. make.height.mas_equalTo(h_key_btn);
  179. }];
  180. /*OK*/
  181. UIButton *keyBoardBtnOK = [[UIButton alloc] init];
  182. [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
  183. [keyBoardBtnOK setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  184. [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
  185. [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
  186. [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
  187. [bgViewForNumberBoard addSubview:keyBoardBtnOK];
  188. [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
  189. make.left.mas_equalTo(2*w_key_btn);
  190. make.bottom.mas_equalTo(0);
  191. make.width.mas_equalTo(w_key_btn);
  192. make.height.mas_equalTo(h_key_btn);
  193. }];
  194. }
  195. - (void)deleteBoardBtnPressed{
  196. if (pwd.length > 0){
  197. NSInteger numberLength = pwd.length;
  198. if (numberLength == 1){
  199. [pointView0 setText:@""];
  200. [pointView0 setBackgroundColor:HWE3E8F1Color];
  201. self->keyBoardBtn0.enabled = NO;
  202. }else if (numberLength == 2){
  203. [pointView1 setText:@""];
  204. [pointView1 setBackgroundColor:HWE3E8F1Color];
  205. }else if (numberLength == 3){
  206. [pointView2 setText:@""];
  207. [pointView2 setBackgroundColor:HWE3E8F1Color];
  208. }else if (numberLength == 4){
  209. [pointView3 setText:@""];
  210. [pointView3 setBackgroundColor:HWE3E8F1Color];
  211. }
  212. pwd = [pwd substringToIndex:numberLength-1];
  213. }
  214. }
  215. - (void)keyBoardBtnOKPressed{
  216. if (pwd.length == 4){
  217. if ([pwd isEqualToString:oldPWD]) {
  218. /*设置密码成功*/
  219. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  220. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  221. [dict setObject:pwd forKey:Const_Have_Add_Device_PWD];
  222. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  223. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  224. //有设备了先去做链接准备 // 80bec9c5
  225. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  226. if(SNStr){
  227. KWeakSelf
  228. [[netWorkManager shareInstance] updateCardInfoBySN:SNStr withPwdStr:pwd didNetEnd:^(NSInteger didSuc) {
  229. if(didSuc){
  230. [weakSelf getPwdFunBy:SNStr];
  231. }
  232. else{
  233. [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  234. }
  235. }];
  236. }
  237. }
  238. }else{
  239. /*提示密码不一致*/
  240. [topLabel setText:NSLocalizedString(@"guide_set_pwd_no_same",nil)];
  241. }
  242. }
  243. }
  244. - (void)keyBoardBtnPressed:(id)sender{
  245. UIButton *btn = (UIButton *)sender;
  246. NSString *selectNumberStr = btn.titleLabel.text;
  247. if (pwd.length < 4){
  248. NSInteger numberLength = pwd.length;
  249. if (numberLength == 0){
  250. [pointView0 setText:selectNumberStr];
  251. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  252. [self->pointView0 setBackgroundColor:HW0A132BColor];
  253. self->keyBoardBtn0.enabled = YES;
  254. });
  255. }else if (numberLength == 1){
  256. [pointView1 setText:selectNumberStr];
  257. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  258. [self->pointView1 setBackgroundColor:HW0A132BColor];
  259. });
  260. }else if (numberLength == 2){
  261. [pointView2 setText:selectNumberStr];
  262. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  263. [self->pointView2 setBackgroundColor:HW0A132BColor];
  264. });
  265. }else if (numberLength == 3){
  266. [pointView3 setText:selectNumberStr];
  267. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  268. [self->pointView3 setBackgroundColor:HW0A132BColor];
  269. });
  270. }
  271. pwd = [pwd stringByAppendingString:selectNumberStr];
  272. }
  273. }
  274. #pragma mark 重新获取密码
  275. -(void)getPwdFunBy:(NSString*)SNStr
  276. {
  277. KWeakSelf
  278. // [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:NO didNetEnd:^(NSInteger didSuc) {
  279. //
  280. // if(didSuc){
  281. // if(self->_isForgetPwdType){
  282. // [[NSNotificationCenter defaultCenter] postNotificationName:forgetPwdDidSetNotification object:nil];
  283. // }
  284. // else{
  285. //// [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
  286. // [weakSelf gotoPrivacyModeTipVCFun];
  287. // }
  288. //
  289. // }
  290. // else{
  291. // [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  292. // }
  293. //
  294. // }];
  295. [[netWorkManager shareInstance] getThridMsgBySN:SNStr success:^(id _Nonnull responseObject) {
  296. DeviceThirdIdModel *model = responseObject;
  297. if([model isKindOfClass:[DeviceThirdIdModel class]]){
  298. if(model.status == 0 && model.data){
  299. if(self->_isForgetPwdType){
  300. [[NSNotificationCenter defaultCenter] postNotificationName:forgetPwdDidSetNotification object:nil];
  301. }
  302. else{
  303. // [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
  304. [weakSelf gotoPrivacyModeTipVCFun];
  305. }
  306. }
  307. else{
  308. [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  309. }
  310. }
  311. else{
  312. [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  313. }
  314. } failure:^(NSError * _Nonnull error) {
  315. [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  316. }];
  317. }
  318. - (void)gotoPrivacyModeTipVCFun
  319. {
  320. privacyModeTipViewController *nextVC = [privacyModeTipViewController new];
  321. //[self.navigationController pushViewController:nextVC animated:YES];
  322. UIWindow* window = [iTools getKeyWindow];
  323. window.rootViewController = nextVC;
  324. //第一次没有主动链接的问题
  325. [[webRtcManager shareManager] beginToLinkWebRtcFun];
  326. }
  327. @end