SettingsNumChangeViewController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. }
  19. @end
  20. @implementation SettingsNumChangeViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self initUI];
  24. }
  25. - (void)initUI {
  26. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  27. statusBar.backgroundColor = [UIColor whiteColor];
  28. _btnSend.enabled = NO;
  29. _btnConfirm.enabled = NO;
  30. // _lblRemainTime.hidden = YES;
  31. _txtInputNum.returnKeyType = UIReturnKeyDone;
  32. _txtInputNum.keyboardType = UIKeyboardTypeNumberPad;
  33. _txtInputNum.delegate = self;
  34. _txtInputAuthNum.returnKeyType = UIReturnKeyDone;
  35. _txtInputAuthNum.keyboardType = UIKeyboardTypeNumberPad;
  36. _txtInputAuthNum.delegate = self;
  37. [self.navigationController.navigationBar setHidden:YES];
  38. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  39. }
  40. - (IBAction)btnSendTouched:(id)sender {
  41. // //validate
  42. // if (![ValidateUtil validateTextfiled:_txtInputNum type:ValidateTypeNumber title:NSLocalizedString(@"이름", @"이름")]) {
  43. // return;
  44. // }
  45. [self requestAuthNum];
  46. }
  47. - (IBAction)btnCancelTouched:(id)sender {
  48. // 설정 페이지로 이동
  49. [[self navigationController] popToRootViewControllerAnimated:YES];
  50. }
  51. - (IBAction)btnConfirmTouched:(id)sender {
  52. [self requestChangePhoneNumber];
  53. }
  54. - (void)requestChangePhoneNumber {
  55. //parameters
  56. NSDictionary *parameter = @{@"phone": _txtInputNum.text,
  57. @"auth_number": _txtInputAuthNum.text };
  58. NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_PUT_CHANGE_PHONE_NUM];
  59. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  60. // if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  61. // return;
  62. // }
  63. //
  64. // JDJSONModel *result = (JDJSONModel *) responseObject;
  65. //
  66. // if (result) {//API 성공 ,
  67. //
  68. // }
  69. [[JDFacade facade] toast:NSLocalizedString(@"휴대폰 번호가 변경되었습니다.", nil)];
  70. [JDFacade facade].loginUser.phone = _txtInputNum.text;
  71. [[self navigationController] popViewControllerAnimated:YES];
  72. } failure:^(id errorObject) {
  73. JDErrorModel *error = (JDErrorModel *)errorObject;
  74. [[JDFacade facade] alert:error.errorMessage];
  75. }];
  76. }
  77. - (void)requestAuthNum {
  78. //parameters
  79. NSDictionary *parameter = @{@"phone": _txtInputNum.text,
  80. @"auth_type": @"1" };
  81. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_POST_AUTH_NUM arguments:nil];
  82. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  83. NSLog(@"requestAuthNum : %@", responseObject);
  84. [_btnSend setTitle: @"인증번호 재전송" forState : UIControlStateNormal];
  85. } failure:^(id errorObject) {
  86. JDErrorModel *error = (JDErrorModel *)errorObject;
  87. [[JDFacade facade] alert:error.errorMessage];
  88. }];
  89. }
  90. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  91. if ([textField isEqual:_txtInputNum]) {
  92. [textField resignFirstResponder];
  93. }
  94. if ([textField isEqual:_txtInputAuthNum]) {
  95. [textField resignFirstResponder];
  96. }
  97. return YES;
  98. }
  99. - (void)textFieldDidEndEditing:(UITextField *)textField{
  100. if (_txtInputNum.text.length >= 10) {
  101. _btnConfirm.enabled = YES;
  102. _btnSend.enabled = YES;
  103. } else {
  104. _btnSend.enabled = NO;
  105. }
  106. if (_txtInputAuthNum.text.length >= 1){
  107. _btnConfirm.enabled = YES;
  108. } else {
  109. _btnConfirm.enabled = NO;
  110. }
  111. }
  112. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  113. if ([textField isEqual:_txtInputNum]) {
  114. if (textField.text.length > 10 && range.length == 0) {
  115. return NO;
  116. }
  117. }
  118. // else {
  119. // if (textField.text.length >= 2 && range.length == 0) {
  120. // return NO;
  121. // }
  122. // }
  123. return YES;
  124. }
  125. - (void)didReceiveMemoryWarning {
  126. [super didReceiveMemoryWarning];
  127. }
  128. @end