ResetPwdViewController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // ResetPwdViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/23/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "ValidateUtil.h"
  12. #import "CustomTextField.h"
  13. #import "CustomLabel.h"
  14. #import "CustomButton.h"
  15. #import "CustomAlertView.h"
  16. #import "ResetPwdViewController.h"
  17. @implementation ResetEmailTableViewCell
  18. - (void)didMoveToSuperview {
  19. }
  20. @end
  21. @implementation ResetPasswdTableViewCell
  22. - (void)didMoveToSuperview {
  23. _txtUserEmail.autoScrollUp = YES;
  24. _txtUserEmail.keyboardType = UIKeyboardTypeEmailAddress;
  25. _txtUserEmail.returnKeyType = UIReturnKeyDone;
  26. _txtUserEmail.customTextFieldSuperview = CustomTextFieldSuperviewIsContentView;
  27. _txtUserEmail.placeholder = NSLocalizedString(@"이메일", @"이메일");
  28. }
  29. @end
  30. @interface ResetPwdViewController () <CustomTextFieldDelegate> {
  31. CustomTextField *_txtUserEmail;
  32. }
  33. @end
  34. #pragma mark - Class Definition
  35. @implementation ResetPwdViewController
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. // Do any additional setup after loading the view.
  39. [self initUI];
  40. [self prepareViewDidLoad];
  41. }
  42. - (void)initUI {
  43. //init table view
  44. [self initTableViewAsDefaultStyle:_tableView];
  45. }
  46. - (void)prepareViewDidLoad {
  47. }
  48. #pragma mark - Main Logic
  49. - (void)requestResetPassword {
  50. //parameters
  51. NSDictionary *parameter = @{@"email_id": _txtUserEmail.text};
  52. NSString *path = [NSString stringWithFormat:API_POST_RESET_PWD];
  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].tmpEmailId = _txtUserEmail.text;
  60. NSString *message = [NSString stringWithFormat:@"%@에서\n인증 메일을 확인하세요\n\n메일을 확인할 수 없는 경우에는\n스팸 메일함을 확인해보세요", [JDFacade facade].tmpEmailId];
  61. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"메일을 확인하세요" message:message delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  62. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  63. if (buttonIndex == 0) {//OK
  64. [[JDFacade facade] dismissModalStack:YES completion:nil];
  65. }
  66. }];
  67. }
  68. } failure:^(id errorObject) {
  69. JDErrorModel *error = (JDErrorModel *)errorObject;
  70. [[JDFacade facade] alert:error.errorMessage];
  71. }];
  72. }
  73. #pragma mark - UITableView DataSource & Delegate
  74. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  75. return 1;
  76. }
  77. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  78. return 2;
  79. }
  80. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  81. CGFloat height = 225.0f;
  82. NSInteger row = indexPath.row;
  83. if (row == 1) {
  84. height = 205.0f;
  85. }
  86. return height;
  87. }
  88. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  89. UITableViewCell *cell = nil;
  90. NSInteger row = indexPath.row;
  91. if (row == 0) {
  92. ResetEmailTableViewCell *tcell = (ResetEmailTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"EmailCellIdentifier"];
  93. if (![tcell.btnFindId actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  94. [tcell.btnFindId addTarget:self action:@selector(btnFindIdTouched:) forControlEvents:UIControlEventTouchUpInside];
  95. }
  96. cell = tcell;
  97. } else if (row == 1) {
  98. ResetPasswdTableViewCell *tcell = (ResetPasswdTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"PasswdCellIdentifier"];
  99. if (!_txtUserEmail) {
  100. _txtUserEmail = tcell.txtUserEmail;
  101. }
  102. if (![tcell.btnFindPasswd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  103. [tcell.btnFindPasswd addTarget:self action:@selector(btnRequestPasswdTouched:) forControlEvents:UIControlEventTouchUpInside];
  104. }
  105. cell = tcell;
  106. }
  107. return cell;
  108. }
  109. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  110. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  111. }
  112. #pragma mark - UI Events
  113. - (IBAction)btnFindIdTouched:(id)sender {
  114. NSString *mailto = URL_HELP_MAIL;
  115. NSString *url = [mailto stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  116. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  117. }
  118. - (IBAction)btnRequestPasswdTouched:(id)sender {
  119. if (![ValidateUtil validateTextfiled:_txtUserEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  120. return;
  121. }
  122. //비밀번호 재설정 요청
  123. [self requestResetPassword];
  124. }
  125. - (IBAction)btnCancelTouched:(id)sender {
  126. [self dismissViewControllerAnimated:YES completion:nil];
  127. }
  128. #pragma mark - CustomTextField
  129. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  130. [self btnRequestPasswdTouched:nil];
  131. return YES;
  132. }
  133. #pragma mark - MemoryWarning
  134. - (void)didReceiveMemoryWarning
  135. {
  136. [super didReceiveMemoryWarning];
  137. // Dispose of any resources that can be recreated.
  138. }
  139. @end