SecurityPasswordController.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // SecurityPasswordController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/13.
  6. //
  7. #import "SecurityPasswordController.h"
  8. #import "APPLocker.h"
  9. @interface SecurityPasswordController ()
  10. @property (nonatomic, strong) UIStackView * titleStackView;
  11. @property (nonatomic, strong) UILabel * passwordTitle;
  12. @property (nonatomic, strong) UILabel * confirmTitle;
  13. @property (nonatomic, strong) UITextField * passwordTextfield;
  14. @property (nonatomic, strong) UITextField * confirmTextfield;
  15. @property (nonatomic, strong) UIButton * saveBtn;
  16. @end
  17. @implementation SecurityPasswordController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // 创建一个点击手势
  21. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  22. // 将手势添加到主视图上
  23. [self.view addGestureRecognizer:tap];
  24. [self configUI];
  25. }
  26. -(void)dismissKeyboard{
  27. NSLog(@"dismissKeyboard");
  28. [self.view endEditing:YES];
  29. }
  30. - (void)configUI{
  31. [self setNavigationTitle:NSLocalizedString(@"userCenter-anquanmm", @"")];
  32. // 设置导航栏背景色
  33. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  34. // 设置标题颜色和字体
  35. [self setNavigationTitleColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:16]];
  36. // 设置返回按钮
  37. [self setBackButtonTitle:@""];
  38. [self setBackButtonColor:[UIColor whiteColor]];
  39. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  40. [self.view addSubview:bgImageView];
  41. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.right.top.bottom.mas_equalTo(0);
  43. }];
  44. [self.view addSubview:self.titleStackView];
  45. [self.titleStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.height.mas_equalTo(120);
  47. make.left.mas_equalTo(20);
  48. make.top.mas_equalTo(SCREEN_TOP+48);
  49. make.width.mas_equalTo(70);
  50. }];
  51. [self.view addSubview:self.passwordTextfield];
  52. [self.passwordTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(104);
  54. make.height.mas_equalTo(50);
  55. make.right.mas_equalTo(-20);
  56. make.centerY.mas_equalTo(self.passwordTitle.mas_centerY);
  57. }];
  58. [self.view addSubview:self.confirmTextfield];
  59. [self.confirmTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(104);
  61. make.height.mas_equalTo(50);
  62. make.right.mas_equalTo(-20);
  63. make.centerY.mas_equalTo(self.confirmTitle.mas_centerY);
  64. }];
  65. [self.view addSubview:self.saveBtn];
  66. [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.height.mas_equalTo(46);
  68. make.left.mas_equalTo(20);
  69. make.right.mas_equalTo(-20);
  70. make.top.mas_equalTo(self.confirmTextfield.mas_bottom).offset(30);
  71. }];
  72. }
  73. #pragma mark event
  74. - (void)saveButtonClicked{
  75. NSLog(@"1");
  76. NSString *password = self.passwordTextfield.text;
  77. NSString *confirmPassword = self.confirmTextfield.text;
  78. if (password.length == 0) {
  79. [MBProgressHUD showWithText:NSLocalizedString(@"Security_confirmPassword_alter", @"")];
  80. return;
  81. }
  82. if (confirmPassword.length == 0) {
  83. [MBProgressHUD showWithText:NSLocalizedString(@"Security_newPassword_alter", @"")];
  84. return;
  85. }
  86. if (![password isEqualToString:confirmPassword]) {
  87. [MBProgressHUD showWithText:NSLocalizedString(@"Security_passwordDefferent", @"")];
  88. return;
  89. }
  90. BOOL success = NO;
  91. NSError *error = nil;
  92. NSLog(@"3");
  93. // 验证安全密码不能跟应用锁密码一致
  94. success = [[APPLocker sharedLocker] verifyPassword:password];
  95. if (success) {
  96. NSLog(@"验证安全密码不能跟应用锁密码一致");
  97. [MBProgressHUD showWithText:NSLocalizedString(@"Security_lockf-same", @"")];
  98. return;
  99. }
  100. success = [APPLocker.sharedLocker setSecurityPassword:password error:&error];
  101. if (success) {
  102. [MBProgressHUD showWithText:NSLocalizedString(@"Common_successfully_set", @"")];
  103. [self.navigationController popViewControllerAnimated:YES];
  104. }
  105. else{
  106. [MBProgressHUD showWithText:NSLocalizedString(@"AppLock_fail", @"")];
  107. }
  108. }
  109. #pragma mark lazy
  110. - (UIStackView *)titleStackView{
  111. if (!_titleStackView) {
  112. _titleStackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.passwordTitle,self.confirmTitle]];
  113. _titleStackView.axis = UILayoutConstraintAxisVertical;
  114. _titleStackView.alignment = UIStackViewAlignmentFill;
  115. _titleStackView.distribution = UIStackViewDistributionEqualSpacing;
  116. _titleStackView.spacing = 64.f;
  117. }
  118. return _titleStackView;
  119. }
  120. - (UILabel *)passwordTitle{
  121. if (!_passwordTitle) {
  122. _passwordTitle = [[UILabel alloc] init];
  123. _passwordTitle.text = @"新密码";
  124. _passwordTitle.textColor = UIColor.whiteColor;
  125. _passwordTitle.font = SYSFONT(16);
  126. }
  127. return _passwordTitle;
  128. }
  129. - (UILabel *)confirmTitle{
  130. if (!_confirmTitle) {
  131. _confirmTitle = [[UILabel alloc] init];
  132. _confirmTitle.text = @"确认密码";
  133. _confirmTitle.textColor = UIColor.whiteColor;
  134. _confirmTitle.font = SYSFONT(16);
  135. }
  136. return _confirmTitle;
  137. }
  138. - (UITextField *)passwordTextfield{
  139. if (!_passwordTextfield) {
  140. _passwordTextfield = [[UITextField alloc] init];
  141. _passwordTextfield.textColor = UIColor.whiteColor;
  142. _passwordTextfield.borderStyle = UITextBorderStyleNone;
  143. _passwordTextfield.layer.borderWidth = 1.f;
  144. _passwordTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  145. _passwordTextfield.layer.cornerRadius = 5.f;
  146. _passwordTextfield.secureTextEntry = YES;
  147. // _passwordTextfield.delegate = self;
  148. _passwordTextfield.leftViewMode = UITextFieldViewModeAlways;
  149. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  150. _passwordTextfield.leftView = leftView;
  151. }
  152. return _passwordTextfield;
  153. }
  154. - (UITextField *)confirmTextfield{
  155. if (!_confirmTextfield) {
  156. _confirmTextfield = [[UITextField alloc] init];
  157. _confirmTextfield.textColor = UIColor.whiteColor;
  158. _confirmTextfield.borderStyle = UITextBorderStyleNone;
  159. _confirmTextfield.layer.borderWidth = 1.f;
  160. _confirmTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  161. _confirmTextfield.layer.cornerRadius = 5.f;
  162. _confirmTextfield.secureTextEntry = YES;
  163. // _confirmTextfield.delegate = self;
  164. _confirmTextfield.leftViewMode = UITextFieldViewModeAlways;
  165. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  166. _confirmTextfield.leftView = leftView;
  167. }
  168. return _confirmTextfield;
  169. }
  170. - (UIButton *)saveBtn{
  171. if (!_saveBtn) {
  172. _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  173. [_saveBtn setTitle:@"保存" forState:UIControlStateNormal];
  174. [_saveBtn setBackgroundColor:globalColor(GCTypeGreen)];
  175. [_saveBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  176. _saveBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  177. _saveBtn.layer.cornerRadius = 5.f;
  178. _saveBtn.layer.masksToBounds = YES;
  179. [_saveBtn addTarget:self action:@selector(saveButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  180. }
  181. return _saveBtn;
  182. }
  183. @end