ChangeEmailViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // ChangeEmailViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/13/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "ChangeEmailViewController.h"
  10. #import "ValidateUtil.h"
  11. #import "CustomTextField.h"
  12. #import "RequestHandler.h"
  13. #import "JDJSONModel.h"
  14. #import "CustomLabel.h"
  15. #import "CustomButton.h"
  16. @interface ChangeEmailViewController () <CustomTextFieldDelegate> {
  17. }
  18. @end
  19. #pragma mark - Class Definition
  20. @implementation ChangeEmailViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. [self initUI];
  25. [self prepareViewDidLoad];
  26. }
  27. - (void)initUI {
  28. self.title = NSLocalizedString(@"이메일 변경",nil);
  29. _txtUserEmail.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  30. _txtUserEmail.delegate = self;
  31. _txtUserEmail.keyboardType = UIKeyboardTypeEmailAddress;
  32. _txtUserEmail.returnKeyType = UIReturnKeyDone;
  33. //Localization
  34. _txtUserEmail.placeholder = NSLocalizedString(@"이메일 입력", @"이메일 입력");
  35. _lblTitle.text = NSLocalizedString(@"변경할 이메일 주소를 입력하세요", @"변경할 이메일 주소를 입력하세요");
  36. _lblDesc1.text = NSLocalizedString(@"새로운 이메일 주소로 인증메일을 발송합니다", @"새로운 이메일 주소로 인증메일을 발송합니다");
  37. _lblDesc2.text = NSLocalizedString(@"인증메일은 24시간 동안만 유효하며,\n인증을 마치기 전까지는\n이메일이 변경되지 않습니다", @"인증메일은 24시간 동안만 유효하며,\n인증을 마치기 전까지는\n이메일이 변경되지 않습니다");
  38. [_btnConfirm setTitle:NSLocalizedString(@"인증메일발송", @"인증메일발송") forState:UIControlStateNormal];
  39. [_btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  40. }
  41. - (void)prepareViewDidLoad {
  42. }
  43. #pragma mark - Main Logic
  44. - (void)requestChangeEmail {
  45. //parameters
  46. NSDictionary *parameter = @{@"new_email_id": _txtUserEmail.text};
  47. NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, [JDFacade facade].loginUser.memberId, @"email"];
  48. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  49. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  50. return;
  51. }
  52. JDJSONModel *result = (JDJSONModel *) responseObject;
  53. if (result) {//API 성공 ,
  54. [JDFacade facade].loginUser.newEmailId = _txtUserEmail.text;
  55. [[JDFacade facade] alert:NSLocalizedString(@"인증메일이 발송되었습니다\n인증메일을 확인 후\n새로운 이메일로 로그인하세요", nil) completionHander:^{
  56. NSInteger count = self.navigationController.viewControllers.count;
  57. UIViewController *vc = self.navigationController.viewControllers[count-2];
  58. [self.navigationController popToViewController:vc animated:YES];
  59. }];
  60. }
  61. } failure:^(id errorObject) {
  62. JDErrorModel *error = (JDErrorModel *)errorObject;
  63. [[JDFacade facade] alert:error.errorMessage];
  64. }];
  65. }
  66. #pragma mark - UI Events
  67. - (IBAction)btnConfirmTouched:(id)sender {
  68. //validate
  69. if (![ValidateUtil validateTextfiled:_txtUserEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  70. return;
  71. }
  72. [self requestChangeEmail];
  73. }
  74. - (IBAction)btnCancelTouched:(id)sender {
  75. [self.navigationController popViewControllerAnimated:YES];
  76. }
  77. #pragma mark - CustomTextField
  78. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  79. [self btnConfirmTouched:nil];
  80. return YES;
  81. }
  82. #pragma mark - MemoryWarning
  83. - (void)didReceiveMemoryWarning
  84. {
  85. [super didReceiveMemoryWarning];
  86. // Dispose of any resources that can be recreated.
  87. }
  88. @end