PwdPopupView.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_POST_MEMBER_UPDATE];
  56. // NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, @"password"];
  57. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  58. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  59. return;
  60. }
  61. JDJSONModel *result = (JDJSONModel *) responseObject;
  62. if (result) {//API 성공 ,
  63. [JDFacade facade].tmpPassword = nil;
  64. [JDFacade facade].loginUser.tempPasswordYn = @"N";
  65. [[JDFacade facade] toast:@"비밀번호를 변경했습니다"];
  66. [super btnConfirmTouched:nil]; //closePopup
  67. }
  68. } failure:^(id errorObject) {
  69. JDErrorModel *error = (JDErrorModel *)errorObject;
  70. [[JDFacade facade] alert:error.errorMessage];
  71. }];
  72. }
  73. - (void)btnConfirmTouched:(id)sender {
  74. if (![ValidateUtil validateTextfiled:_txtPwd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  75. return;
  76. }
  77. if (![_txtPwd.text isEqualToString:_txtPwdConfirm.text]) {
  78. [[JDFacade facade] alert:@"두 비밀번호가 일치하지 않습니다"];
  79. return;
  80. }
  81. [self requestSetNewPassword];
  82. }
  83. #pragma mark - CustomTextField
  84. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  85. if ([textField isEqual:_txtPwdConfirm]) {
  86. [self btnConfirmTouched:nil];
  87. }
  88. if ([textField isEqual:_txtPwd]) {
  89. [_txtPwdConfirm becomeFirstResponder];
  90. }
  91. return YES;
  92. }
  93. @end