ResetPwdViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. @"service_id": MOBILE_SERVICE_ID};
  53. NSString *path = [NSString stringWithFormat:API_POST_RESET_PWD];
  54. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  55. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  56. return;
  57. }
  58. JDJSONModel *result = (JDJSONModel *) responseObject;
  59. if (result) {//API 성공 ,
  60. [JDFacade facade].tmpEmailId = _txtUserEmail.text;
  61. NSString *message1 = [NSString stringWithFormat:@"%@에서\n인증 메일을 확인하세요", [JDFacade facade].tmpEmailId];
  62. NSString *message2 = @"\n\n메일을 확인할 수 없는 경우에는\n스팸 메일함을 확인해보세요";
  63. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"메일을 확인하세요" message:[NSString stringWithFormat:@"%@%@", message1, message2] delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  64. [alert.lblMessage1 setColor:kUITextColor02 text:message1];
  65. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  66. if (buttonIndex == 0) {//OK
  67. [[JDFacade facade] dismissModalStack:YES completion:nil];
  68. }
  69. }];
  70. }
  71. } failure:^(id errorObject) {
  72. JDErrorModel *error = (JDErrorModel *)errorObject;
  73. [[JDFacade facade] alert:error.errorMessage];
  74. }];
  75. }
  76. #pragma mark - UITableView DataSource & Delegate
  77. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  78. return 1;
  79. }
  80. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  81. return 2;
  82. }
  83. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  84. CGFloat height = 225.0f;
  85. NSInteger row = indexPath.row;
  86. if (row == 1) {
  87. height = 205.0f;
  88. }
  89. return height;
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  92. UITableViewCell *cell = nil;
  93. NSInteger row = indexPath.row;
  94. if (row == 0) {
  95. ResetEmailTableViewCell *tcell = (ResetEmailTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"EmailCellIdentifier"];
  96. if (![tcell.btnFindId actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  97. [tcell.btnFindId addTarget:self action:@selector(btnFindIdTouched:) forControlEvents:UIControlEventTouchUpInside];
  98. }
  99. cell = tcell;
  100. } else if (row == 1) {
  101. ResetPasswdTableViewCell *tcell = (ResetPasswdTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"PasswdCellIdentifier"];
  102. if (!_txtUserEmail) {
  103. _txtUserEmail = tcell.txtUserEmail;
  104. }
  105. if (![tcell.btnFindPasswd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  106. [tcell.btnFindPasswd addTarget:self action:@selector(btnRequestPasswdTouched:) forControlEvents:UIControlEventTouchUpInside];
  107. }
  108. cell = tcell;
  109. }
  110. return cell;
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  113. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  114. }
  115. #pragma mark - UI Events
  116. - (IBAction)btnFindIdTouched:(id)sender {
  117. NSString *mailto = URL_HELP_MAIL;
  118. NSString *url = [mailto stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  119. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  120. }
  121. - (IBAction)btnRequestPasswdTouched:(id)sender {
  122. if (![ValidateUtil validateTextfiled:_txtUserEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  123. return;
  124. }
  125. //비밀번호 재설정 요청
  126. [self requestResetPassword];
  127. }
  128. - (IBAction)btnCancelTouched:(id)sender {
  129. [self dismissViewControllerAnimated:YES completion:nil];
  130. }
  131. #pragma mark - CustomTextField
  132. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  133. [self btnRequestPasswdTouched:nil];
  134. return YES;
  135. }
  136. #pragma mark - MemoryWarning
  137. - (void)didReceiveMemoryWarning
  138. {
  139. [super didReceiveMemoryWarning];
  140. // Dispose of any resources that can be recreated.
  141. }
  142. @end