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