CertificationViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #import "SignUpQuizSetViewController.h"
  13. #import "QuizViewController.h"
  14. #define kiZeroHeight 0;
  15. #define kiViewHeight 14; // 전송 버튼 위 여백뷰 높이 값
  16. #define kiBtnSendHeight 50; // 전송 버튼 높이 값
  17. #define ksSimpleSignUp @"2"; // 일반 회원가입
  18. #define ksMasterSignUP @"3"; // 마스터 회원가입
  19. @interface CertificationViewController () <CustomTextFieldDelegate>{
  20. NSString *signType;
  21. }
  22. @end
  23. @implementation CertificationViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self initUI];
  27. }
  28. // UI 설정
  29. - (void)initUI {
  30. [self.navigationController.navigationBar setHidden:YES];
  31. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  32. _btnSend.enabled = NO;
  33. _btnNext.enabled = NO;
  34. [_lblStep setColor:kUITextColor03 text:[NSString stringWithFormat:@"%@", @"/ 5"]];
  35. _txtPhoneNum.returnKeyType = UIReturnKeyDone;
  36. _txtPhoneNum.keyboardType = UIKeyboardTypeNumberPad;
  37. _txtPhoneNum.delegate = self;
  38. _txtCertifyInput.returnKeyType = UIReturnKeyDone;
  39. _txtCertifyInput.keyboardType = UIKeyboardTypeNumberPad;
  40. _txtCertifyInput.delegate = self;
  41. [self.btnSend setBackgroundImage:[UIImage imageNamed:@"img_btn_common_active"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  42. [self.btnSend setBackgroundImage:[UIImage imageNamed:@"img_btn_common_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  43. [self.btnSend setBackgroundImage:[UIImage imageNamed:@"img_btn_common_disable"] forState:UIControlStateDisabled capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  44. // 마스터,멤버 여부에 따라 전송 버튼 Hidden 여부설정
  45. if ([[JDFacade facade].signType isEqualToString:KNEET_MEMBER_MASTER]) {
  46. [self hiddenSendButton:YES];
  47. } else {
  48. [self hiddenSendButton:NO];
  49. }
  50. }
  51. // 휴대폰 번호 인증 확인 요청
  52. - (void)requestValidNum {
  53. NSDictionary *parameter = @{@"phone": _txtPhoneNum.text,
  54. @"auth_number" : _txtCertifyInput.text,
  55. @"send_type" : @"U",
  56. @"auth_type" : signType};
  57. NSString *path = API_POST_RESPONSE_AUTH_NUM;
  58. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[SignUpModel class] completion:^(id responseObject) {
  59. SignUpModel *signUpModel = (SignUpModel *)responseObject;
  60. NSLog(@"Response : %@",signUpModel);
  61. // 마스터 회원가입일 경우 퀴즈 선택 메뉴로 이동
  62. if ([[JDFacade facade].signType isEqualToString:KNEET_MEMBER_MASTER]) {
  63. SignUpQuizSetViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpQuizSetViewController" storyboardName:@"SignUp"];
  64. vc.signUpModel = signUpModel;
  65. vc.phoneNum = _txtPhoneNum.text;
  66. [JDFacade facade].signUpUser = signUpModel;
  67. [self.navigationController pushViewController:vc animated:YES];
  68. // 멤버 회원가입일 경우 퀴즈 정답 입력 메뉴로 이동
  69. } else {
  70. QuizViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"QuizViewController" storyboardName:@"SignUp"];
  71. vc.signUpModel = signUpModel;
  72. vc.phoneNum = _txtPhoneNum.text;
  73. [JDFacade facade].signUpUser = signUpModel;
  74. [self.navigationController pushViewController:vc animated:YES];
  75. }
  76. } failure:^(id errorObject) {
  77. JDErrorModel *error = (JDErrorModel *)errorObject;
  78. [[JDFacade facade] alert:error.errorMessage];
  79. }];
  80. }
  81. // 인증번호 전송 ( 멤버 회원가입만 해당 )
  82. - (void)requestAuthSendNum {
  83. //parameters
  84. NSDictionary *parameter = @{@"phone": _txtPhoneNum.text,
  85. @"auth_type": signType};
  86. NSString *path = API_POST_REQUEST_AUTH_NUM;
  87. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  88. _lblMessage.text = @"인증번호는 전송 후 3분 동안 유효 합니다";
  89. [_btnSend setTitle: @"인증번호 재전송" forState : UIControlStateNormal];
  90. } failure:^(id errorObject) {
  91. JDErrorModel *error = (JDErrorModel *)errorObject;
  92. [[JDFacade facade] alert:error.errorMessage];
  93. _lblMessage.text = error.errorMessage;
  94. }];
  95. }
  96. // 인증번호 전송 여부 설정
  97. - (void)hiddenSendButton:(BOOL)isHidden{
  98. if (isHidden) {
  99. _btnSend.hidden = YES;
  100. _btnSendHeight.constant = kiZeroHeight; // 버튼 높이 값 0 설정
  101. _viewHeight.constant = kiZeroHeight; // 뷰 높이 값 0 설정
  102. _lblMessage.text = @"설치기사님에게 인증번호 SMS를 받은 번호만\n인증이 가능합니다.";
  103. signType = ksMasterSignUP; // 인증 타입 마스터로 설정
  104. } else {
  105. _btnSend.hidden = NO;
  106. _btnSendHeight.constant = kiBtnSendHeight; // 버튼 높이 값 50 설정
  107. _viewHeight.constant = kiViewHeight; // 뷰 높이 값 14 설정
  108. _lblMessage.text = @"마스터 사용자에게 초대 SMS를 받은 번호만\n인증이 가능합니다.";
  109. signType = ksSimpleSignUp; // 인증 타입 멤버로 설정
  110. }
  111. }
  112. // 다음 버튼 터치시 인증번호 유효성 체크
  113. - (IBAction)btnNextTouched:(id)sender {
  114. [self requestValidNum];
  115. }
  116. // 메뉴 닫기
  117. - (IBAction)btnCancelTouched:(id)sender {
  118. [self dismissViewControllerAnimated:YES completion:nil];
  119. }
  120. // 인증 번호 전송 버튼 터치시 입력 된 휴대폰 번호로 인증번호 전송
  121. - (IBAction)btnSendTouched:(id)sender {
  122. [self requestAuthSendNum];
  123. }
  124. // 휴대폰 번호 및 인증번호에 입력 된 글자 수에따라 다음 버튼 Enable여부 설정
  125. - (void)textFieldDidEndEditing:(UITextField *)textField{
  126. // 휴대폰 번호가 10자리 이상 입력 된 경우 다음 버튼 활성화
  127. if (_txtPhoneNum.text.length >= 10) {
  128. _btnSend.enabled = YES;
  129. _btnNext.enabled = YES;
  130. } else {
  131. _btnSend.enabled = NO;
  132. _btnNext.enabled = NO;
  133. }
  134. // 인증번호가 4자리가 입력 된 경우 다음 버튼 활성화
  135. if (_txtCertifyInput.text.length >= 4){
  136. _btnNext.enabled = YES;
  137. } else {
  138. _btnNext.enabled = NO;
  139. }
  140. }
  141. // 휴대폰 번호 및 인증번호 최대 입력가능한 텍스트 설정
  142. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  143. // 휴대폰 번호입력 최대 11글자
  144. if ([textField isEqual:_txtPhoneNum]) {
  145. if (textField.text.length >= 11 && range.length == 0) {
  146. return NO;
  147. }
  148. // 인증번호 최대 4글자
  149. } else if([textField isEqual:_txtCertifyInput]){
  150. if (textField.text.length >= 4 && range.length == 0) {
  151. return NO;
  152. }
  153. }
  154. return YES;
  155. }
  156. - (void)didReceiveMemoryWarning {
  157. [super didReceiveMemoryWarning];
  158. }
  159. @end