ChangePasswordController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // ChangePasswordController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/4/29.
  6. //
  7. #import "ChangePasswordController.h"
  8. #import "UIViewController+General.h"
  9. #import "Masonry.h"
  10. #import "config.h"
  11. #import "UserNetApi.h"
  12. @interface ChangePasswordController ()<UITextFieldDelegate>
  13. @property (nonatomic, strong) UIStackView * titleStackView;
  14. @property (nonatomic, strong) UILabel * oldPasswordLbl;
  15. @property (nonatomic, strong) UILabel * changePasswordLbl;
  16. @property (nonatomic, strong) UILabel * confirmPasswordLbl;
  17. @property (nonatomic, strong) UILabel * oldPwdAlertLbl;
  18. @property (nonatomic, strong) UILabel * changePwdAlterLbl;
  19. @property (nonatomic, strong) UILabel * confirmPwdAlertLbl;
  20. @property (nonatomic, strong) UITextField * oldPasswordTextfield;
  21. @property (nonatomic, strong) UITextField * changePasswordTextfield;
  22. @property (nonatomic, strong) UITextField * confirmPasswordTextfield;
  23. @property (nonatomic, strong) UIButton * saveBtn;
  24. @end
  25. @implementation ChangePasswordController
  26. #pragma mark lifecircle
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // 创建一个点击手势
  30. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  31. // 将手势添加到主视图上
  32. [self.view addGestureRecognizer:tap];
  33. [self configUI];
  34. }
  35. -(void)dismissKeyboard{
  36. NSLog(@"dismissKeyboard");
  37. [self.view endEditing:YES];
  38. }
  39. #pragma mark UI
  40. - (void)configUI{
  41. [self setNavigationTitle:NSLocalizedString(@"userCenter-xiugaimm", @"")];
  42. // 设置导航栏背景色
  43. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  44. // 设置标题颜色和字体
  45. [self setNavigationTitleColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:16]];
  46. // 设置返回按钮
  47. [self setBackButtonTitle:@""];
  48. [self setBackButtonColor:[UIColor whiteColor]];
  49. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  50. [self.view addSubview:bgImageView];
  51. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.right.top.bottom.mas_equalTo(0);
  53. }];
  54. [self.view addSubview:self.titleStackView];
  55. [self.titleStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.height.mas_equalTo(180);
  57. make.left.mas_equalTo(20);
  58. make.top.mas_equalTo(SCREEN_TOP+48);
  59. make.width.mas_equalTo(70);
  60. }];
  61. [self.view addSubview:self.oldPasswordTextfield];
  62. [self.oldPasswordTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.mas_equalTo(self.titleStackView.mas_right).offset(20);
  64. make.height.mas_equalTo(50);
  65. make.right.mas_equalTo(-20);
  66. make.centerY.mas_equalTo(self.oldPasswordLbl.mas_centerY);
  67. }];
  68. [self.view addSubview:self.oldPwdAlertLbl];
  69. [self.oldPwdAlertLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.height.mas_equalTo(12);
  71. make.left.mas_equalTo(self.oldPasswordTextfield.mas_left).offset(20);
  72. make.top.mas_equalTo(self.oldPasswordTextfield.mas_bottom).offset(6);
  73. }];
  74. [self.view addSubview:self.changePasswordTextfield];
  75. [self.changePasswordTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.mas_equalTo(self.titleStackView.mas_right).offset(20);
  77. make.height.mas_equalTo(50);
  78. make.right.mas_equalTo(-20);
  79. make.centerY.mas_equalTo(self.changePasswordLbl.mas_centerY);
  80. }];
  81. [self.view addSubview:self.changePwdAlterLbl];
  82. [self.changePwdAlterLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.height.mas_equalTo(12);
  84. make.left.mas_equalTo(self.changePasswordTextfield.mas_left).offset(20);
  85. make.top.mas_equalTo(self.changePasswordTextfield.mas_bottom).offset(6);
  86. }];
  87. [self.view addSubview:self.confirmPasswordTextfield];
  88. [self.confirmPasswordTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.mas_equalTo(self.titleStackView.mas_right).offset(20);
  90. make.height.mas_equalTo(50);
  91. make.right.mas_equalTo(-20);
  92. make.centerY.mas_equalTo(self.confirmPasswordLbl.mas_centerY);
  93. }];
  94. [self.view addSubview:self.confirmPwdAlertLbl];
  95. [self.confirmPwdAlertLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.height.mas_equalTo(12);
  97. make.left.mas_equalTo(self.confirmPasswordTextfield.mas_left).offset(20);
  98. make.top.mas_equalTo(self.confirmPasswordTextfield.mas_bottom).offset(6);
  99. }];
  100. [self.view addSubview:self.saveBtn];
  101. [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.height.mas_equalTo(46);
  103. make.left.mas_equalTo(20);
  104. make.right.mas_equalTo(-20);
  105. make.top.mas_equalTo(self.confirmPasswordTextfield.mas_bottom).offset(30);
  106. }];
  107. }
  108. #pragma mark event
  109. - (void)saveButtonClicked{
  110. if (self.oldPasswordTextfield.text.length == 0) {
  111. self.oldPwdAlertLbl.hidden = NO;
  112. self.oldPasswordTextfield.layer.borderColor = UIColor.redColor.CGColor;
  113. return;
  114. }
  115. if (self.changePasswordTextfield.text.length == 0) {
  116. self.changePwdAlterLbl.hidden = NO;
  117. self.changePasswordTextfield.layer.borderColor = UIColor.redColor.CGColor;
  118. return;
  119. }
  120. if (self.confirmPasswordTextfield.text.length == 0) {
  121. self.confirmPwdAlertLbl.hidden = NO;
  122. self.confirmPasswordTextfield.layer.borderColor = UIColor.redColor.CGColor;
  123. return;
  124. }
  125. if (![self.confirmPasswordTextfield.text isEqualToString:self.changePasswordTextfield.text]) {
  126. self.confirmPwdAlertLbl.text = NSLocalizedString(@"PwdChange_passwordsDifferent_alter", @"");
  127. self.confirmPwdAlertLbl.hidden = NO;
  128. self.confirmPasswordTextfield.layer.borderColor = UIColor.redColor.CGColor;
  129. return;
  130. }
  131. NSDictionary * param = @{@"oldPassword":self.oldPasswordTextfield.text,
  132. @"newPassword":self.confirmPasswordTextfield.text};
  133. [UserNetApi changePassword:param succ:^(int code, NSDictionary * _Nullable res) {
  134. NSLog(@"result:%@",res);
  135. if ([res jk_hasKey:@"msg"]) {
  136. [MBProgressHUD showWithText:[res objectForKey:@"msg"]];
  137. }
  138. } fail:^(NSError * _Nonnull error) {
  139. NSLog(@"error:%@",error);
  140. // [MBProgressHUD showWithText:@"修改失败"];
  141. }];
  142. }
  143. #pragma mark textfield delegate
  144. - (void)textFieldDidEndEditing:(UITextField *)textField{
  145. if (textField == self.oldPasswordTextfield && self.oldPasswordTextfield.text.length != 0) {
  146. self.oldPwdAlertLbl.hidden = YES;
  147. self.oldPasswordTextfield.layer.borderColor = UIColor.whiteColor.CGColor;
  148. }
  149. if (textField == self.changePasswordTextfield && self.changePasswordTextfield.text.length != 0) {
  150. self.changePwdAlterLbl.hidden = YES;
  151. self.changePasswordTextfield.layer.borderColor = UIColor.whiteColor.CGColor;
  152. }
  153. if (textField == self.confirmPasswordTextfield && self.confirmPasswordTextfield.text.length != 0) {
  154. self.confirmPwdAlertLbl.hidden = YES;
  155. self.confirmPasswordTextfield.layer.borderColor = UIColor.whiteColor.CGColor;
  156. }
  157. if ([self.confirmPasswordTextfield.text isEqualToString:self.changePasswordTextfield.text]) {
  158. self.confirmPwdAlertLbl.hidden = YES;
  159. self.confirmPasswordTextfield.layer.borderColor = UIColor.whiteColor.CGColor;
  160. }
  161. }
  162. #pragma mark lazy
  163. - (UIStackView *)titleStackView{
  164. if (!_titleStackView) {
  165. _titleStackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.oldPasswordLbl,self.changePasswordLbl,self.confirmPasswordLbl]];
  166. _titleStackView.axis = UILayoutConstraintAxisVertical;
  167. _titleStackView.alignment = UIStackViewAlignmentFill;
  168. _titleStackView.distribution = UIStackViewDistributionEqualSpacing;
  169. _titleStackView.spacing = 64.f;
  170. }
  171. return _titleStackView;
  172. }
  173. - (UILabel *)oldPasswordLbl{
  174. if (!_oldPasswordLbl) {
  175. _oldPasswordLbl = [[UILabel alloc] init];
  176. _oldPasswordLbl.text = NSLocalizedString(@"PwdChange_oldPassword", @"");
  177. _oldPasswordLbl.textColor = UIColor.whiteColor;
  178. _oldPasswordLbl.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
  179. }
  180. return _oldPasswordLbl;
  181. }
  182. - (UILabel *)changePasswordLbl{
  183. if (!_changePasswordLbl) {
  184. _changePasswordLbl = [[UILabel alloc] init];
  185. _changePasswordLbl.text = NSLocalizedString(@"PwdChange_newPassword", @"");
  186. _changePasswordLbl.textColor = UIColor.whiteColor;
  187. _changePasswordLbl.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
  188. }
  189. return _changePasswordLbl;
  190. }
  191. - (UILabel *)confirmPasswordLbl{
  192. if (!_confirmPasswordLbl) {
  193. _confirmPasswordLbl = [[UILabel alloc] init];
  194. _confirmPasswordLbl.text = NSLocalizedString(@"PwdChange_confirmPassword", @"");
  195. _confirmPasswordLbl.textColor = UIColor.whiteColor;
  196. _confirmPasswordLbl.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
  197. }
  198. return _confirmPasswordLbl;
  199. }
  200. - (UILabel *)oldPwdAlertLbl{
  201. if (!_oldPwdAlertLbl) {
  202. _oldPwdAlertLbl = [[UILabel alloc] init];
  203. _oldPwdAlertLbl.text = NSLocalizedString(@"PwdChange_oldPwd_alter", @"");
  204. _oldPwdAlertLbl.textColor = globalColor(GCTypeRedd);
  205. _oldPwdAlertLbl.font = SYSFONT(12);
  206. _oldPwdAlertLbl.hidden = YES;
  207. }
  208. return _oldPwdAlertLbl;
  209. }
  210. - (UILabel *)changePwdAlterLbl{
  211. if (!_changePwdAlterLbl) {
  212. _changePwdAlterLbl = [[UILabel alloc] init];
  213. _changePwdAlterLbl.text = NSLocalizedString(@"PwdChange_newPwd_alter", @"");
  214. _changePwdAlterLbl.textColor = globalColor(GCTypeRedd);
  215. _changePwdAlterLbl.font = SYSFONT(12);
  216. _changePwdAlterLbl.hidden = YES;
  217. }
  218. return _changePwdAlterLbl;
  219. }
  220. - (UILabel *)confirmPwdAlertLbl{
  221. if (!_confirmPwdAlertLbl) {
  222. _confirmPwdAlertLbl = [[UILabel alloc] init];
  223. _confirmPwdAlertLbl.text = NSLocalizedString(@"PwdChange_confirmPwd_alter", @"");
  224. _confirmPwdAlertLbl.textColor = globalColor(GCTypeRedd);
  225. _confirmPwdAlertLbl.font = SYSFONT(12);
  226. _confirmPwdAlertLbl.hidden = YES;
  227. }
  228. return _confirmPwdAlertLbl;
  229. }
  230. - (UITextField *)oldPasswordTextfield{
  231. if (!_oldPasswordTextfield) {
  232. _oldPasswordTextfield = [[UITextField alloc] init];
  233. _oldPasswordTextfield.textColor = UIColor.whiteColor;
  234. _oldPasswordTextfield.borderStyle = UITextBorderStyleNone;
  235. _oldPasswordTextfield.layer.borderWidth = 1.f;
  236. _oldPasswordTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  237. _oldPasswordTextfield.layer.cornerRadius = 5.f;
  238. _oldPasswordTextfield.secureTextEntry = YES;
  239. _oldPasswordTextfield.delegate = self;
  240. _oldPasswordTextfield.leftViewMode = UITextFieldViewModeAlways;
  241. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  242. _oldPasswordTextfield.leftView = leftView;
  243. }
  244. return _oldPasswordTextfield;
  245. }
  246. - (UITextField *)changePasswordTextfield{
  247. if (!_changePasswordTextfield) {
  248. _changePasswordTextfield = [[UITextField alloc] init];
  249. _changePasswordTextfield.textColor = UIColor.whiteColor;
  250. _changePasswordTextfield.borderStyle = UITextBorderStyleNone;
  251. _changePasswordTextfield.layer.borderWidth = 1.f;
  252. _changePasswordTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  253. _changePasswordTextfield.layer.cornerRadius = 5.f;
  254. _changePasswordTextfield.secureTextEntry = YES;
  255. _changePasswordTextfield.delegate = self;
  256. _changePasswordTextfield.leftViewMode = UITextFieldViewModeAlways;
  257. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  258. _changePasswordTextfield.leftView = leftView;
  259. }
  260. return _changePasswordTextfield;
  261. }
  262. - (UITextField *)confirmPasswordTextfield{
  263. if (!_confirmPasswordTextfield) {
  264. _confirmPasswordTextfield = [[UITextField alloc] init];
  265. _confirmPasswordTextfield.textColor = UIColor.whiteColor;
  266. _confirmPasswordTextfield.borderStyle = UITextBorderStyleNone;
  267. _confirmPasswordTextfield.layer.borderWidth = 1.f;
  268. _confirmPasswordTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  269. _confirmPasswordTextfield.layer.cornerRadius = 5.f;
  270. _confirmPasswordTextfield.secureTextEntry = YES;
  271. _confirmPasswordTextfield.delegate = self;
  272. _confirmPasswordTextfield.leftViewMode = UITextFieldViewModeAlways;
  273. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  274. _confirmPasswordTextfield.leftView = leftView;
  275. }
  276. return _confirmPasswordTextfield;
  277. }
  278. - (UIButton *)saveBtn{
  279. if (!_saveBtn) {
  280. _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  281. [_saveBtn setTitle:NSLocalizedString(@"EGroupCtr-baocun", @"") forState:UIControlStateNormal];
  282. [_saveBtn setBackgroundColor:globalColor(GCTypeGreen)];
  283. [_saveBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  284. _saveBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  285. _saveBtn.layer.cornerRadius = 5.f;
  286. _saveBtn.layer.masksToBounds = YES;
  287. [_saveBtn addTarget:self action:@selector(saveButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  288. }
  289. return _saveBtn;
  290. }
  291. #pragma mark statusBar
  292. - (UIStatusBarStyle)preferredStatusBarStyle{
  293. return UIStatusBarStyleLightContent;
  294. }
  295. @end