// // PBChangePWController.m // IphoneBIMe // // Created by zjf on 2018/9/21. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBChangePWController.h" #import "PGGCryptoDES.h" #import @interface PBChangePWController () @property (nonatomic, weak) UITextField *originalPwTF; @property (nonatomic, weak) UITextField *setPwTF; @property (nonatomic, weak) UITextField *confirmPwTF; @end @implementation PBChangePWController - (void)viewDidLoad { [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) { self.edgesForExtendedLayout = UIRectEdgeNone; } [self setupNav]; [self setupUI]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:NO]; } - (void)setupNav { self.title = @"修改密码"; UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Project_nav_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)]; self.navigationItem.leftBarButtonItem = backItem; UIBarButtonItem *saveItem = [[UIBarButtonItem alloc] initWithTitle:@"确认" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)]; self.navigationItem.rightBarButtonItem = saveItem; } - (void)backItemAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)saveAction { NSString *oldpass = self.originalPwTF.text; NSString *newpass = self.setPwTF.text; NSString *againpass = self.confirmPwTF.text; if ([oldpass isEqualToString:@""] || [newpass isEqualToString:@""] || [againpass isEqualToString:@""]) { [YJProgressHUD showMessage:@"请填写完整" inView:self.view]; return; } if ([oldpass isEqualToString:newpass]) { [YJProgressHUD showMessage:@"新密码不能和当前密码相同" inView:self.view]; return; } if (![newpass isEqualToString:againpass]) { [YJProgressHUD showMessage:@"两次输入的新密码不同" inView:self.view]; return; } [YJProgressHUD showProgress:@"" inView:self.view]; NSString *oldAES = [PGGCryptoDES encryptUseDES:oldpass]; NSString *newAES = [PGGCryptoDES encryptUseDES:newpass]; [[PBNetworkTools sharedTools] RequestSubmitResetPasswordWithOldPassword:oldAES NewPassword:newAES andCallBack:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"修改失败" inView:self.view]; return; } NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"%@",str); NSDictionary *dict = [NSString convertTodictionaryOrArr:str]; int type = [[dict valueForKey:@"Type"] intValue]; if (type == 1) { [YJProgressHUD showMessage:@"修改成功" inView:self.view]; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.navigationController popViewControllerAnimated:NO]; NSFileManager *manager=[NSFileManager defaultManager]; NSString *filepath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"login.plist"];//这里就是你将要删除的沙盒路径(.plist文件,名字 [manager removeItemAtPath:filepath error:nil]; [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { NSLog(@"%zd--%@--%zd",iResCode,iAlias,seq); } seq:10]; [self.navigationController popViewControllerAnimated:NO]; if (self.ChangePWCompleteBlock){ self.ChangePWCompleteBlock(); } }); }else { [YJProgressHUD showMessage:[dict valueForKey:@"Message"] inView:self.view]; } }]; } - (void)setupUI { self.view.backgroundColor = [UIColor whiteColor]; UITextField *originalPwTF = [[UITextField alloc] init]; originalPwTF.placeholder = @"请输入原密码"; originalPwTF.keyboardType = UIKeyboardTypeASCIICapable; originalPwTF.secureTextEntry = YES; originalPwTF.clearButtonMode = UITextFieldViewModeAlways; originalPwTF.returnKeyType = UIReturnKeyNext; originalPwTF.delegate = self; [originalPwTF becomeFirstResponder]; [self.view addSubview:originalPwTF]; [originalPwTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(25); make.left.equalTo(self.view).offset(10); make.right.equalTo(self.view).offset(-10); make.height.equalTo(@40); }]; UITextField *setPwTF = [[UITextField alloc] init]; setPwTF.placeholder = @"请输入新密码"; setPwTF.keyboardType = UIKeyboardTypeASCIICapable; setPwTF.secureTextEntry = YES; setPwTF.clearButtonMode = UITextFieldViewModeAlways; setPwTF.returnKeyType = UIReturnKeyNext; setPwTF.delegate = self; [self.view addSubview:setPwTF]; [setPwTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(originalPwTF.mas_bottom).offset(10); make.left.right.height.equalTo(originalPwTF); }]; UITextField *confirmPwTF = [[UITextField alloc] init]; confirmPwTF.placeholder = @"再次输入新密码"; confirmPwTF.keyboardType = UIKeyboardTypeASCIICapable; confirmPwTF.secureTextEntry = YES; confirmPwTF.clearButtonMode = UITextFieldViewModeAlways; confirmPwTF.returnKeyType = UIReturnKeyDone; confirmPwTF.delegate = self; [self.view addSubview:confirmPwTF]; [confirmPwTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(setPwTF.mas_bottom).offset(10); make.left.right.height.equalTo(originalPwTF); }]; self.originalPwTF = originalPwTF; self.setPwTF = setPwTF; self.confirmPwTF = confirmPwTF; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == self.originalPwTF) { [self.setPwTF becomeFirstResponder]; }else if (textField == self.setPwTF) { [self.confirmPwTF becomeFirstResponder]; }else { [self.view endEditing:NO]; } return YES; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end