// // modifyPwdController.m // ThePaperBase // // Created by Huixin on 15/8/26. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "modifyPwdController.h" @interface modifyPwdController () @property(nonatomic, strong)UIImageView *oldPasswordImageView; @property(nonatomic, strong)UITextField *oldPasswordField; @property(nonatomic, strong)UIView *oldPasswordLine; @property(nonatomic, strong)UIImageView *passwordImageView; @property(nonatomic, strong)UITextField *passwordField; @property(nonatomic, strong)UIView *passwordLine; @property(nonatomic, strong)UILabel *passwordLabel; @property(nonatomic, strong)TPCustomButton *confirmBtn; @end @implementation modifyPwdController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleStr = @"修改密码"; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; [self.view addGestureRecognizer:tapGesture]; [self.view addSubview:self.oldPasswordImageView]; [self.view addSubview:self.oldPasswordField]; [self.view addSubview:self.oldPasswordLine]; [self.view addSubview:self.passwordImageView]; [self.view addSubview:self.passwordField]; [self.view addSubview:self.passwordLine]; [self.view addSubview:self.passwordLabel]; [self.view addSubview:self.confirmBtn]; [self.oldPasswordField becomeFirstResponder]; [self layoutViews]; } - (void)layoutViews { [self.oldPasswordImageView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left).offset(20); make.bottom.equalTo(self.oldPasswordField.bottom); make.width.mas_equalTo(@18); make.height.mas_equalTo(@20); }]; [self.oldPasswordField makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.naviBar.bottom).offset(38); make.left.equalTo(self.view.left).offset(50); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@19); }]; [self.oldPasswordLine makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.oldPasswordField.bottom).offset(7); make.left.equalTo(self.oldPasswordImageView.left); make.right.equalTo(self.oldPasswordField.right); make.height.mas_equalTo(@1); }]; [self.passwordImageView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left).offset(20); make.bottom.equalTo(self.passwordField.bottom); make.width.mas_equalTo(@18); make.height.mas_equalTo(@20); }]; [self.passwordField makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.oldPasswordLine.bottom).offset(38); make.left.equalTo(self.view.left).offset(50); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@19); }]; [self.passwordLine makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordField.bottom).offset(7); make.left.equalTo(self.passwordImageView.left); make.right.equalTo(self.passwordField.right); make.height.mas_equalTo(@1); }]; [self.passwordLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordLine.bottom).offset(4); make.left.equalTo(self.passwordLine.left); make.right.equalTo(self.passwordLine.right); make.height.mas_equalTo(12); }]; [self.confirmBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordLabel.bottom).offset(45); make.left.equalTo(self.view.left).offset(20); make.right.equalTo(self.view.right).offset(-20); make.height.equalTo(self.confirmBtn.width).multipliedBy(0.15); }]; } #pragma mark - get method - (UIImageView*)oldPasswordImageView { if (!_oldPasswordImageView) { _oldPasswordImageView = [[UIImageView alloc] init]; _oldPasswordImageView.image = Image(@"login/password.png"); } return _oldPasswordImageView; } - (UITextField*)oldPasswordField { if (!_oldPasswordField) { _oldPasswordField = [[UITextField alloc] init]; _oldPasswordField.backgroundColor = [UIColor clearColor]; NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"原密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}]; _oldPasswordField.attributedPlaceholder = atrString; _oldPasswordField.textColor = [UIColor colorWithHexString:TextBlack]; _oldPasswordField.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _oldPasswordField.textAlignment = NSTextAlignmentLeft; _oldPasswordField.keyboardAppearance = UIKeyboardAppearanceDefault; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _oldPasswordField.keyboardAppearance = UIKeyboardAppearanceDark; } _oldPasswordField.keyboardType = UIKeyboardTypeASCIICapable; _oldPasswordField.secureTextEntry = YES; _oldPasswordField.clearButtonMode = UITextFieldViewModeWhileEditing; _oldPasswordField.delegate = self; [_oldPasswordField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; } return _oldPasswordField; } - (UIView*)oldPasswordLine { if (!_oldPasswordLine) { _oldPasswordLine = [[UIView alloc] init]; _oldPasswordLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _oldPasswordLine; } - (UIImageView*)passwordImageView { if (!_passwordImageView) { _passwordImageView = [[UIImageView alloc] init]; _passwordImageView.image = Image(@"login/password.png"); } return _passwordImageView; } - (UITextField*)passwordField { if (!_passwordField) { _passwordField = [[UITextField alloc] init]; _passwordField.backgroundColor = [UIColor clearColor]; NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"新密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}]; _passwordField.attributedPlaceholder = atrString; _passwordField.textColor = [UIColor colorWithHexString:TextBlack]; _passwordField.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _passwordField.textAlignment = NSTextAlignmentLeft; _passwordField.keyboardAppearance = UIKeyboardAppearanceDefault; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _passwordField.keyboardAppearance = UIKeyboardAppearanceDark; } _passwordField.keyboardType = UIKeyboardTypeASCIICapable; _passwordField.secureTextEntry = YES; _passwordField.clearButtonMode = UITextFieldViewModeWhileEditing; _passwordField.delegate = self; _passwordField.returnKeyType = UIReturnKeyDone; //bug:5035 关于密码的地方,键盘都改成“确定” [_passwordField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; } return _passwordField; } - (UIView*)passwordLine { if (!_passwordLine) { _passwordLine = [[UIView alloc] init]; _passwordLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _passwordLine; } - (UILabel*)passwordLabel { if (!_passwordLabel) { _passwordLabel = [[UILabel alloc] init]; _passwordLabel.backgroundColor = [UIColor clearColor]; _passwordLabel.text = @"请输入6-12个数字或字母"; _passwordLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _passwordLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _passwordLabel.textAlignment = NSTextAlignmentRight; } return _passwordLabel; } - (TPCustomButton*)confirmBtn { if (!_confirmBtn) { _confirmBtn = [[TPCustomButton alloc] init]; _confirmBtn.title = @"确认"; [_confirmBtn addTarget:self action:@selector(confirmEvent) forControlEvents:UIControlEventTouchUpInside]; } return _confirmBtn; } #pragma mark - textfield delegate - (void)textFieldDidChange:(UITextField *)textField { if ([textField.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) { textField.text = disable_emoji(textField.text); } } - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == _oldPasswordField) { [_passwordField becomeFirstResponder]; } else if (textField == _passwordField) { [self confirmEvent]; } return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([textField isFirstResponder]) { if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) { return NO; } } return YES; } #pragma mark - btn event handler - (void)confirmEvent { [self closeKeyBoard]; if (isBlankString(_oldPasswordField.text)) { ShowTextMessage(@"请输入原密码"); return; } if (isBlankString(_passwordField.text)) { ShowTextMessage(@"请输入新密码"); return; } NSDictionary *dic = @{@"pwd":_passwordField.text,@"oldPwd":_oldPasswordField.text}; [Remote doJsonAction:0 requestUrl:modifyPwdURL parameter:dic delegate:self]; } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responseData { if (actionTag == 0) { if ([responseData[@"resultCode"] intValue] == 1) { userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]); userBO *oriUser = [TPUserDefault instance].userBO; user.loginType = oriUser.loginType; [TPUserDefault instance].userBO = user; ShowTextMessage(@"密码修改成功"); [self.navigationController popViewControllerAnimated:YES]; }else { ShowTextMessage(responseData[@"resultMsg"]); } } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ ShowTextMessage(message); } #pragma mark - tap handler - (void)tap:(UITapGestureRecognizer*)sender { [self closeKeyBoard]; } #pragma mark - keyBoard event - (void)closeKeyBoard { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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