PwdPopupView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // PwdPopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/12/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTextField.h"
  13. #import "ValidateUtil.h"
  14. #import "PwdPopupView.h"
  15. @interface PwdPopupView () <CustomTextFieldDelegate>
  16. {
  17. }
  18. @end
  19. @implementation PwdPopupView
  20. - (id)initFromNib {
  21. for (UIView *view in [CommonUtil nibViews:@"PwdPopupView"]) {
  22. if ([view isKindOfClass:[PwdPopupView class]]) {
  23. self = (PwdPopupView *)view;
  24. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  25. self.frame = [UIScreen mainScreen].bounds;
  26. self.lblTitle.text = NSLocalizedString(@"비밀번호 변경",nil);
  27. _txtPwd.secureTextEntry = YES;
  28. _txtPwd.keyboardType = UIKeyboardTypeDefault;
  29. _txtPwd.returnKeyType = UIReturnKeyDone;
  30. _txtPwdConfirm.delegate = self;
  31. _txtPwdConfirm.secureTextEntry = YES;
  32. _txtPwdConfirm.keyboardType = UIKeyboardTypeDefault;
  33. _txtPwdConfirm.returnKeyType = UIReturnKeyDone;
  34. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  35. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  36. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  37. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  38. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  39. //Localization
  40. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"취소") forState:UIControlStateNormal];
  41. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  42. }
  43. }
  44. return self;
  45. }
  46. - (void)didMoveToSuperview {
  47. _txtPwd.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  48. _txtPwdConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  49. }
  50. - (void)requestSetNewPassword {
  51. //parameters
  52. NSDictionary *parameter = @{@"new_password": _txtPwd.text,
  53. @"confirm_password": _txtPwdConfirm.text};
  54. NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, @"password"];
  55. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  56. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  57. return;
  58. }
  59. JDJSONModel *result = (JDJSONModel *) responseObject;
  60. if (result) {//API 성공 ,
  61. [JDFacade facade].tmpPassword = nil;
  62. [JDFacade facade].loginUser.tempPasswordYn = @"N";
  63. [[JDFacade facade] toast:@"비밀번호를 변경했습니다"];
  64. [super btnConfirmTouched:nil]; //closePopup
  65. }
  66. } failure:^(id errorObject) {
  67. JDErrorModel *error = (JDErrorModel *)errorObject;
  68. [[JDFacade facade] alert:error.errorMessage];
  69. }];
  70. }
  71. - (void)btnConfirmTouched:(id)sender {
  72. if (![ValidateUtil validateTextfiled:_txtPwd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  73. return;
  74. }
  75. if (![_txtPwd.text isEqualToString:_txtPwdConfirm.text]) {
  76. [[JDFacade facade] alert:@"두 비밀번호가 일치하지 않습니다"];
  77. return;
  78. }
  79. [self requestSetNewPassword];
  80. }
  81. #pragma mark - CustomTextField
  82. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  83. if ([textField isEqual:_txtPwdConfirm]) {
  84. [self btnConfirmTouched:nil];
  85. }
  86. return YES;
  87. }
  88. @end