PwdPopupView.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. //Localization
  35. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"취소") forState:UIControlStateNormal];
  36. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  37. }
  38. }
  39. return self;
  40. }
  41. - (void)didMoveToSuperview {
  42. _txtPwd.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  43. _txtPwdConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  44. }
  45. - (void)requestSetNewPassword {
  46. //parameters
  47. NSDictionary *parameter = @{@"new_password": _txtPwd.text,
  48. @"confirm_password": _txtPwdConfirm.text};
  49. NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, @"password"];
  50. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  51. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  52. return;
  53. }
  54. JDJSONModel *result = (JDJSONModel *) responseObject;
  55. if (result) {//API 성공 ,
  56. [JDFacade facade].tmpPassword = nil;
  57. [JDFacade facade].loginUser.tempPasswordYn = @"N";
  58. [[JDFacade facade] toast:@"비밀번호를 변경했습니다"];
  59. [super btnConfirmTouched:nil]; //closePopup
  60. }
  61. } failure:^(id errorObject) {
  62. JDErrorModel *error = (JDErrorModel *)errorObject;
  63. [[JDFacade facade] alert:error.errorMessage];
  64. }];
  65. }
  66. - (void)btnConfirmTouched:(id)sender {
  67. if (![ValidateUtil validateTextfiled:_txtPwd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  68. return;
  69. }
  70. if (![_txtPwd.text isEqualToString:_txtPwdConfirm.text]) {
  71. [[JDFacade facade] alert:@"두 비밀번호가 일치하지 않습니다"];
  72. return;
  73. }
  74. [self requestSetNewPassword];
  75. }
  76. #pragma mark - CustomTextField
  77. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  78. if ([textField isEqual:_txtPwdConfirm]) {
  79. [self btnConfirmTouched:nil];
  80. }
  81. return YES;
  82. }
  83. @end