ChangePasswordViewController.mm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // ChangePasswordViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/10/17.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "ChangePasswordViewController.h"
  9. #import "ChangePasswordView.h"
  10. #import "UserAccountModel.h"
  11. #import "NSString+Extention.h"
  12. @interface ChangePasswordViewController ()<UserAccountModelDelegate>
  13. {
  14. ChangePasswordView *changePwdView; //修改账号密码视图
  15. UserAccountModel *accountModel; //账号相关功能接口管理器
  16. }
  17. @end
  18. @implementation ChangePasswordViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. //账号相关功能接口管理器
  22. accountModel = [[UserAccountModel alloc] init];
  23. accountModel.delegate = self;
  24. //修改账号密码视图初始化
  25. changePwdView = [[ChangePasswordView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
  26. __weak typeof(self) weakSelf = self;
  27. //修改密码按钮点击处理
  28. changePwdView.changePwdBtnClicked = ^(NSString * _Nonnull userName,NSString * _Nonnull pwdOld, NSString * _Nonnull pwdNew1, NSString * _Nonnull pwdNew2) {
  29. [weakSelf changePassWordWithUserName:userName OldPwd:pwdOld newPwd:pwdNew1 confirmPwd:pwdNew2];
  30. };
  31. self.view = changePwdView;
  32. //设置导航栏
  33. [self setNaviStyle];
  34. }
  35. - (void)setNaviStyle {
  36. self.navigationItem.title = TS("Modify_pwd");
  37. UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"new_back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(popViewController)];
  38. self.navigationItem.leftBarButtonItem = leftBtn;
  39. }
  40. #pragma mark - button event
  41. -(void)popViewController
  42. {
  43. if([SVProgressHUD isVisible]){
  44. [SVProgressHUD dismiss];
  45. }
  46. [self.navigationController popViewControllerAnimated:YES];
  47. }
  48. #pragma mark 修改密码按钮点击处理
  49. -(void)changePassWordWithUserName:(NSString *)userName OldPwd:(NSString *)pwdOld newPwd:(NSString *)pwdNew1 confirmPwd:(NSString *)pwdNew2
  50. {
  51. //判断原密码是否为空
  52. if (pwdOld.length == 0 ) {
  53. [SVProgressHUD showErrorWithStatus:TS("password_error2")];
  54. return;
  55. }
  56. //判断新密码是否为空
  57. if (pwdNew1.length == 0 ) {
  58. [SVProgressHUD showErrorWithStatus:TS("set_new_psd")];
  59. return;
  60. }
  61. //检查新密码格式
  62. if(![NSString isValidatePassword:pwdNew1]){
  63. [SVProgressHUD showErrorWithStatus:TS("edit_pwd_error5")];
  64. return;
  65. }
  66. //判断2次新密码是否相同
  67. if ( ![pwdNew1 isEqualToString:pwdNew2]) {
  68. [SVProgressHUD showErrorWithStatus:TS("pass_notsame")];
  69. return;
  70. }
  71. [SVProgressHUD show];
  72. //发送修改密码命令
  73. [accountModel changePassword:userName oldPassword:pwdOld newPsw:pwdNew1];
  74. }
  75. #pragma mark - funsdk 回调处理
  76. -(void)changePasswordDelegateResult:(long)result
  77. {
  78. [SVProgressHUD dismiss];
  79. if (result >= 0) {
  80. [SVProgressHUD showSuccessWithStatus:TS("Modify_pwd_success")];
  81. }
  82. else{
  83. [MessageUI ShowErrorInt:(int)result title:TS("Modify_pwd_failed")];
  84. }
  85. }
  86. - (void)didReceiveMemoryWarning {
  87. [super didReceiveMemoryWarning];
  88. // Dispose of any resources that can be recreated.
  89. }
  90. @end