ResetPwdViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "CustomTextField.h"
  10. #import "ResetPwdViewController.h"
  11. #import "ValidateUtil.h"
  12. #import "RequestHandler.h"
  13. #import "JDJSONModel.h"
  14. #import "CustomLabel.h"
  15. #import "CustomButton.h"
  16. @interface ResetPwdViewController () <CustomTextFieldDelegate> {
  17. }
  18. @end
  19. #pragma mark - Class Definition
  20. @implementation ResetPwdViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. [self initUI];
  25. [self prepareViewDidLoad];
  26. }
  27. - (void)viewWillAppear:(BOOL)animated {
  28. [super viewWillAppear:animated];
  29. self.title = NSLocalizedString(@"비밀번호 재설정",nil);
  30. }
  31. - (void)initUI {
  32. _txtUserEmail.delegate = self;
  33. _txtUserEmail.keyboardType = UIKeyboardTypeEmailAddress;
  34. _txtUserEmail.returnKeyType = UIReturnKeyDone;
  35. _txtUserEmail.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  36. //Localization
  37. _txtUserEmail.placeholder = NSLocalizedString(@"이메일", @"이메일");
  38. _lblTitle.text = NSLocalizedString(@"비밀번호가 기억나지 않으세요?", @"비밀번호가 기억나지 않으세요?");
  39. _lblDesc.text = NSLocalizedString(@"이메일 인증을 통해서 임시 비밀번호를\n재설정 할 수 있습니다", @"이메일 인증을 통해서 임시 비밀번호를\n재설정 할 수 있습니다");
  40. [_btnRequestEmail setTitle:NSLocalizedString(@"인증메일 받기", @"인증메일 받기") forState:UIControlStateNormal];
  41. }
  42. - (void)prepareViewDidLoad {
  43. }
  44. #pragma mark - Main Logic
  45. - (void)requestResetPassword {
  46. //parameters
  47. NSDictionary *parameter = @{@"email_id": _txtUserEmail.text};
  48. NSString *path = [NSString stringWithFormat:API_POST_RESET_PWD];
  49. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  50. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  51. return;
  52. }
  53. JDJSONModel *result = (JDJSONModel *) responseObject;
  54. if (result) {//API 성공 ,
  55. NSString *msg = NSLocalizedString(@"인증 메일을 확인 후\n임시 비밀번호로 로그인하세요", @"인증 메일을 확인 후\n임시 비밀번호로 로그인하세요");
  56. [[JDFacade facade] alert:msg completionHander:^{
  57. [[JDFacade facade] dismissViewControllerByPush:self];
  58. }];
  59. }
  60. } failure:^(id errorObject) {
  61. JDErrorModel *error = (JDErrorModel *)errorObject;
  62. [[JDFacade facade] alert:error.errorMessage];
  63. }];
  64. }
  65. #pragma mark - UI Events
  66. - (IBAction)btnRequestEmailTouched:(id)sender {
  67. if (![ValidateUtil validateTextfiled:_txtUserEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  68. return;
  69. }
  70. //비밀번호 재설정 요청
  71. [self requestResetPassword];
  72. }
  73. #pragma mark - CustomTextField
  74. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  75. [self btnRequestEmailTouched:nil];
  76. return YES;
  77. }
  78. #pragma mark - MemoryWarning
  79. - (void)didReceiveMemoryWarning
  80. {
  81. [super didReceiveMemoryWarning];
  82. // Dispose of any resources that can be recreated.
  83. }
  84. @end