CertificationViewController.m 8.1 KB

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