SettingsNumChangeViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // SettingsNumChangeViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 4. 19..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "SettingsNumChangeViewController.h"
  9. #import "CustomButton.h"
  10. #import "CustomLabel.h"
  11. #import "CustomTextField.h"
  12. #import "JDObject.h"
  13. #import "RequestHandler.h"
  14. #import "JDJSONModel.h"
  15. #import "ValidateUtil.h"
  16. #import "SettingsViewController.h"
  17. @interface SettingsNumChangeViewController () <CustomTextFieldDelegate> {
  18. BOOL certificate;
  19. }
  20. @end
  21. @implementation SettingsNumChangeViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self initUI];
  25. }
  26. - (void)initUI {
  27. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  28. statusBar.backgroundColor = [UIColor whiteColor];
  29. _lblMessage.hidden = YES;
  30. _btnSend.enabled = NO;
  31. _btnConfirm.enabled = NO;
  32. // _lblRemainTime.hidden = YES;
  33. _txtInputNum.returnKeyType = UIReturnKeyDone;
  34. _txtInputNum.keyboardType = UIKeyboardTypeNumberPad;
  35. _txtInputNum.delegate = self;
  36. _txtInputAuthNum.returnKeyType = UIReturnKeyDone;
  37. _txtInputAuthNum.keyboardType = UIKeyboardTypeNumberPad;
  38. _txtInputAuthNum.delegate = self;
  39. [self.navigationController.navigationBar setHidden:YES];
  40. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  41. }
  42. - (IBAction)btnSendTouched:(id)sender {
  43. // //validate
  44. // if (![ValidateUtil validateTextfiled:_txtInputNum type:ValidateTypeNumber title:NSLocalizedString(@"이름", @"이름")]) {
  45. // return;
  46. // }
  47. [self requestAuthNum];
  48. }
  49. - (IBAction)btnCancelTouched:(id)sender {
  50. // 설정 페이지로 이동
  51. if (_isPresente)
  52. [self dismissViewControllerAnimated:YES completion:nil];
  53. else
  54. [[self navigationController] popToRootViewControllerAnimated:YES];
  55. }
  56. - (IBAction)btnConfirmTouched:(id)sender {
  57. [self requestChangePhoneNumber];
  58. }
  59. - (void)requestChangePhoneNumber {
  60. //parameters
  61. NSDictionary *parameter = @{@"phone": _txtInputNum.text,
  62. @"auth_number": _txtInputAuthNum.text };
  63. NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_PUT_CHANGE_PHONE_NUM];
  64. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  65. // if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  66. // return;
  67. // }
  68. //
  69. // JDJSONModel *result = (JDJSONModel *) responseObject;
  70. //
  71. // if (result) {//API 성공 ,
  72. //
  73. // }
  74. [[JDFacade facade] toast:NSLocalizedString(@"휴대폰 번호가 변경되었습니다.", nil)];
  75. [JDFacade facade].loginUser.phone = _txtInputNum.text;
  76. if (_isPresente) {
  77. [JDFacade facade].loginUser.phoneAuthYn = @"Y";
  78. [self gotoMainView];
  79. }
  80. else
  81. [[self navigationController] popViewControllerAnimated:YES];
  82. } failure:^(id errorObject) {
  83. JDErrorModel *error = (JDErrorModel *)errorObject;
  84. [[JDFacade facade] alert:error.errorMessage];
  85. }];
  86. }
  87. - (void)requestAuthNum {
  88. //parameters
  89. NSDictionary *parameter = @{@"cust_id": [JDFacade facade].loginUser.custId,
  90. @"ctrt_grp_id": [JDFacade facade].loginUser.ctrtGrpId,
  91. @"phone": _txtInputNum.text,
  92. @"auth_type": @"1" };
  93. NSString *path = [NSString stringWithFormat:API_POST_REQUEST_AUTH_NUM];
  94. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  95. NSLog(@"requestAuthNum : %@", responseObject);
  96. certificate = YES;
  97. [_btnSend setTitle: @"인증번호 재전송" forState : UIControlStateNormal];
  98. _lblMessage.hidden = NO;
  99. } failure:^(id errorObject) {
  100. JDErrorModel *error = (JDErrorModel *)errorObject;
  101. [[JDFacade facade] alert:error.errorMessage];
  102. _lblMessage.hidden = NO;
  103. _lblMessage.text = error.errorMessage;
  104. }];
  105. }
  106. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  107. if ([textField isEqual:_txtInputNum]) {
  108. [_txtInputAuthNum becomeFirstResponder];
  109. }
  110. else {
  111. [_txtInputNum becomeFirstResponder];
  112. }
  113. return YES;
  114. }
  115. - (void)textFieldDidEndEditing:(UITextField *)textField{
  116. _btnConfirm.enabled = certificate && _txtInputAuthNum.text.length >= 4 ;
  117. }
  118. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  119. NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
  120. if ([textField isEqual:_txtInputNum]) {
  121. _btnSend.enabled = text.length >= 10;
  122. certificate = NO;
  123. }
  124. // 휴대폰 번호입력 최대 11글자
  125. if ([textField isEqual:_txtInputNum] && text.length > 11) {
  126. return NO;
  127. // 인증번호 최대 4글자
  128. } else if([textField isEqual:_txtInputAuthNum] && text.length > 4){
  129. return NO;
  130. }
  131. return YES;
  132. }
  133. //마스터 회원일때
  134. - (void)moveToNextField:(id)sender {
  135. [_txtInputAuthNum becomeFirstResponder];
  136. }
  137. - (void)moveToPrevField:(id)sender {
  138. [_txtInputNum becomeFirstResponder];
  139. }
  140. - (void)didReceiveMemoryWarning {
  141. [super didReceiveMemoryWarning];
  142. }
  143. - (void)gotoMainView {
  144. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"MainViewController" storyboardName:@"Main"];
  145. [JDFacade facade].mainViewController = (MainViewController *)vc;
  146. [[JDFacade facade].appDelegate.window setRootViewController:vc];
  147. }
  148. @end