PwdPopupView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // PwdPopupView.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/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. //Localization
  35. _lblDesc1.text = NSLocalizedString(@"새로운 비밀번호를 입력하세요", @"새로운 비밀번호를 입력하세요");
  36. _lblDesc2.text = NSLocalizedString(@"영어, 숫자, 특수문자 중 2가지 이상을 사용해서\n8글자 이상으로 만들어 주세요", @"영어, 숫자, 특수문자 중 2가지 이상을 사용해서\n8글자 이상으로 만들어 주세요");
  37. //Localization
  38. [self.btnConfirm setTitle:NSLocalizedString(@"변경", @"변경") forState:UIControlStateNormal];
  39. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  40. }
  41. }
  42. return self;
  43. }
  44. - (void)didMoveToSuperview {
  45. _txtPwd.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  46. _txtPwdConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  47. }
  48. - (void)requestSetNewPassword {
  49. //parameters
  50. NSDictionary *parameter = @{@"new_password": _txtPwd.text,
  51. @"confirm_password": _txtPwdConfirm.text};
  52. NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, [JDFacade facade].loginUser.memberId, @"password"];
  53. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  54. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  55. return;
  56. }
  57. JDJSONModel *result = (JDJSONModel *) responseObject;
  58. if (result) {//API 성공 ,
  59. [JDFacade facade].tmpPassword = nil;
  60. [JDFacade facade].loginUser.tempPasswordYn = @"N";
  61. [[JDFacade facade] toast:NSLocalizedString(@"비밀번호가 변경되었습니다", @"비밀번호가 변경되었습니다")];
  62. [super btnConfirmTouched:nil]; //closePopup
  63. }
  64. } failure:^(id errorObject) {
  65. JDErrorModel *error = (JDErrorModel *)errorObject;
  66. [[JDFacade facade] alert:error.errorMessage];
  67. }];
  68. }
  69. - (void)btnConfirmTouched:(id)sender {
  70. if (![ValidateUtil validateTextfiled:_txtPwd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  71. return;
  72. }
  73. if (![_txtPwd.text isEqualToString:_txtPwdConfirm.text]) {
  74. [[JDFacade facade] alert:NSLocalizedString(@"비밀번호와 비밀번호 확인이 일치하지 않습니다\n다시 시도해주세요", @"비밀번호와 비밀번호 확인이 일치하지 않습니다\n다시 시도해주세요")];
  75. return;
  76. }
  77. [self requestSetNewPassword];
  78. }
  79. #pragma mark - CustomTextField
  80. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  81. if ([textField isEqual:_txtPwdConfirm]) {
  82. [self btnConfirmTouched:nil];
  83. }
  84. return YES;
  85. }
  86. @end