PwdPopupView.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.delegate = self;
  28. _txtPwd.secureTextEntry = YES;
  29. _txtPwd.keyboardType = UIKeyboardTypeDefault;
  30. _txtPwd.returnKeyType = UIReturnKeyNext;
  31. _txtPwdConfirm.delegate = self;
  32. _txtPwdConfirm.secureTextEntry = YES;
  33. _txtPwdConfirm.keyboardType = UIKeyboardTypeDefault;
  34. _txtPwdConfirm.returnKeyType = UIReturnKeyDone;
  35. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  36. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  37. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  38. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  39. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  40. //Localization
  41. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"취소") forState:UIControlStateNormal];
  42. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  43. }
  44. }
  45. return self;
  46. }
  47. - (void)didMoveToSuperview {
  48. _txtPwd.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  49. _txtPwdConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  50. }
  51. - (void)requestSetNewPassword {
  52. //parameters
  53. // NSDictionary *parameter = @{@"password1": _txtPwd.text,
  54. // @"password2": _txtPwdConfirm.text};
  55. NSDictionary *parameter = @{@"type": @"password",
  56. @"password": _txtPwdConfirm.text};
  57. NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_PUT_MEMBER_UPDATE];
  58. // NSString *path = [NSString stringWithFormat:API_PUT_MEMBER_UPDATE, @"password"];
  59. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  60. // if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  61. // return;
  62. // }
  63. //
  64. // JDJSONModel *result = (JDJSONModel *) responseObject;
  65. //
  66. // if (result) {//API 성공 ,
  67. [JDFacade facade].tmpPassword = nil;
  68. [JDFacade facade].loginUser.tempPasswordYn = @"N";
  69. [[JDFacade facade] toast:@"비밀번호를 변경했습니다"];
  70. [super btnConfirmTouched:nil]; //closePopup
  71. // }
  72. } failure:^(id errorObject) {
  73. JDErrorModel *error = (JDErrorModel *)errorObject;
  74. [[JDFacade facade] alert:error.errorMessage];
  75. }];
  76. }
  77. - (void)btnConfirmTouched:(id)sender {
  78. if (![ValidateUtil validateTextfiled:_txtPwd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  79. return;
  80. }
  81. if (![_txtPwd.text isEqualToString:_txtPwdConfirm.text]) {
  82. [[JDFacade facade] alert:@"두 비밀번호가 일치하지 않습니다"];
  83. return;
  84. }
  85. [self requestSetNewPassword];
  86. }
  87. #pragma mark - CustomTextField
  88. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  89. if ([textField isEqual:_txtPwdConfirm]) {
  90. [self btnConfirmTouched:nil];
  91. }
  92. if ([textField isEqual:_txtPwd]) {
  93. [_txtPwdConfirm becomeFirstResponder];
  94. }
  95. return YES;
  96. }
  97. @end