CertificationViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // CertificationViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 3. 17..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "CertificationViewController.h"
  9. #import "CustomButton.h"
  10. #import "CustomTextField.h"
  11. #import "RequestHandler.h"
  12. #define kiZeroHeight 0;
  13. #define kiViewHeight 14;
  14. #define kiBtnSendHeight 50;
  15. @interface CertificationViewController () <CustomTextFieldDelegate>{
  16. }
  17. @end
  18. @implementation CertificationViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self initUI];
  22. }
  23. - (void)initUI {
  24. [self.navigationController.navigationBar setHidden:YES];
  25. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  26. _btnSend.enabled = NO;
  27. _btnNext.enabled = NO;
  28. [_lblStep setColor:kUITextColor03 text:[NSString stringWithFormat:@"%@", @"/ 5"]];
  29. _txtPhoneNum.returnKeyType = UIReturnKeyDone;
  30. _txtPhoneNum.keyboardType = UIKeyboardTypeNumberPad;
  31. _txtPhoneNum.delegate = self;
  32. _txtCertifyInput.returnKeyType = UIReturnKeyDone;
  33. _txtCertifyInput.keyboardType = UIKeyboardTypeNumberPad;
  34. _txtCertifyInput.delegate = self;
  35. [self.btnSend setBackgroundImage:[UIImage imageNamed:@"img_btn_common_active"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  36. [self.btnSend setBackgroundImage:[UIImage imageNamed:@"img_btn_common_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  37. [self.btnSend setBackgroundImage:[UIImage imageNamed:@"img_btn_common_disable"] forState:UIControlStateDisabled capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  38. [self hiddenSendButton:NO];
  39. }
  40. - (void)requestAuthNum {
  41. NSDictionary *parameter = @{@"phone": _txtPhoneNum.text,
  42. @"auth_number" : _txtCertifyInput.text,
  43. @"send_type" : @"U",
  44. @"auth_type" : @"2"};
  45. NSString *path = API_POST_AUTH_NUM_CHK;
  46. // NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_POST_AUTH_NUM_CHK arguments:nil];
  47. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JSONModel class] completion:^(id responseObject) {
  48. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  49. return;
  50. }
  51. // 마스터 : SignUpQuizSetViewController
  52. // 멤버 : QuizViewController
  53. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"QuizViewController" storyboardName:@"SignUp"];
  54. [self.navigationController pushViewController:vc animated:YES];
  55. } failure:^(id errorObject) {
  56. JDErrorModel *error = (JDErrorModel *)errorObject;
  57. [[JDFacade facade] alert:error.errorMessage];
  58. }];
  59. }
  60. - (void)requestAuthSendNum {
  61. //parameters
  62. NSDictionary *parameter = @{@"phone": _txtPhoneNum.text,
  63. @"auth_type": @"2" };
  64. NSString *path = API_POST_AUTH_NUM;
  65. // NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_POST_AUTH_NUM arguments:nil];
  66. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  67. NSLog(@"requestAuthNum : %@", responseObject);
  68. [_btnSend setTitle: @"인증번호 재전송" forState : UIControlStateNormal];
  69. } failure:^(id errorObject) {
  70. JDErrorModel *error = (JDErrorModel *)errorObject;
  71. [[JDFacade facade] alert:error.errorMessage];
  72. }];
  73. }
  74. - (void)hiddenSendButton:(BOOL)isHidden{
  75. if (isHidden) {
  76. _btnSend.hidden = YES;
  77. _btnSendHeight.constant = kiZeroHeight;
  78. _viewHeight.constant = kiZeroHeight;
  79. _lblMessage.text = @"설치기사님에게 인증번호 SMS를 받은 번호만\n인증이 가능합니다.";
  80. } else {
  81. _btnSend.hidden = NO;
  82. _btnSendHeight.constant = kiBtnSendHeight;
  83. _viewHeight.constant = kiViewHeight;
  84. _lblMessage.text = @"마스터 사용자에게 초대 SMS를 받은 번호만\n인증이 가능합니다.";
  85. }
  86. }
  87. - (IBAction)btnNextTouched:(id)sender {
  88. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"QuizViewController" storyboardName:@"SignUp"];
  89. [self.navigationController pushViewController:vc animated:YES];
  90. // [self requestAuthNum];
  91. }
  92. - (IBAction)btnCancelTouched:(id)sender {
  93. [self dismissViewControllerAnimated:YES completion:nil];
  94. }
  95. - (IBAction)btnSendTouched:(id)sender {
  96. [self requestAuthSendNum];
  97. }
  98. - (void)textFieldDidEndEditing:(UITextField *)textField{
  99. if (_txtPhoneNum.text.length >= 10) {
  100. _btnSend.enabled = YES;
  101. _btnNext.enabled = YES;
  102. } else {
  103. _btnSend.enabled = NO;
  104. _btnNext.enabled = NO;
  105. }
  106. if (_txtCertifyInput.text.length >= 4){
  107. _btnNext.enabled = YES;
  108. } else {
  109. _btnNext.enabled = NO;
  110. }
  111. }
  112. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  113. if ([textField isEqual:_txtPhoneNum]) {
  114. if (textField.text.length >= 11 && range.length == 0) {
  115. return NO;
  116. }
  117. } else if([textField isEqual:_txtCertifyInput]){
  118. if (textField.text.length >= 6 && range.length == 0) {
  119. return NO;
  120. }
  121. }
  122. return YES;
  123. }
  124. - (void)didReceiveMemoryWarning {
  125. [super didReceiveMemoryWarning];
  126. }
  127. @end