SignUpViewController.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // SignUpViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/23/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "CustomLabel.h"
  9. #import "CustomCheckBox.h"
  10. #import "SignUpViewController.h"
  11. #import "JDObject.h"
  12. #import "CustomTextField.h"
  13. #import "ValidateUtil.h"
  14. #import "RequestHandler.h"
  15. #import "JDJSONModel.h"
  16. #import "WebBrowseViewController.h"
  17. #import "CustomButton.h"
  18. @interface SignUpViewController () {
  19. }
  20. @end
  21. #pragma mark - Class Definition
  22. @implementation SignUpViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self initUI];
  27. [self prepareViewDidLoad];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated {
  30. [super viewWillAppear:animated];
  31. self.title = NSLocalizedString(@"AoTHome 가입", @"AoTHome 가입");
  32. }
  33. - (void)initUI {
  34. [_lblTermUse setText:NSLocalizedString(@"이용약관 동의", @"이용약관 동의")];
  35. [_lblPolicy setText:NSLocalizedString(@"개인정보 취급정책 동의", @"개인정보 취급정책 동의")];
  36. [_lblLocation setText:NSLocalizedString(@"위치정보 활용 동의", @"위치정보 활용 동의")];
  37. [_lblMinor setText:NSLocalizedString(@"14세 미만인가요?", @"14세 미만인가요?")];
  38. [_lblTermUse setUnderLine:_lblTermUse.text];
  39. [_lblPolicy setUnderLine:_lblPolicy.text];
  40. [_lblLocation setUnderLine:_lblLocation.text];
  41. [_lblMinor setUnderLine:_lblMinor.text];
  42. [_lblTermUse addTouchEventHandler:^{
  43. [self showTermUse];
  44. }];
  45. [_lblPolicy addTouchEventHandler:^{
  46. [self showPolicy];
  47. }];
  48. [_lblLocation addTouchEventHandler:^{
  49. [self showLocation];
  50. }];
  51. [_lblMinor addTouchEventHandler:^{
  52. [self showMinor];
  53. }];
  54. _txtUserEmail.keyboardType = UIKeyboardTypeEmailAddress;
  55. _txtUserEmail.returnKeyType = UIReturnKeyDone;
  56. _txtUserName.keyboardType = UIKeyboardTypeDefault;
  57. _txtUserName.returnKeyType = UIReturnKeyDone;
  58. _txtPasswd.keyboardType = UIKeyboardTypeDefault;
  59. _txtPasswd.returnKeyType = UIReturnKeyDone;
  60. _txtPasswd.secureTextEntry = YES;
  61. _txtPasswdConfirm.keyboardType = UIKeyboardTypeDefault;
  62. _txtPasswdConfirm.secureTextEntry = YES;
  63. _txtPasswdConfirm.returnKeyType = UIReturnKeyDone;
  64. //Localization
  65. _txtUserName.placeholder = NSLocalizedString(@"이름", @"이름");
  66. _txtUserEmail.placeholder = NSLocalizedString(@"이메일", @"이메일");
  67. _txtPasswd.placeholder = NSLocalizedString(@"비밀번호", @"비밀번호");
  68. _txtPasswdConfirm.placeholder = NSLocalizedString(@"비밀번호 확인", @"비밀번호 확인");
  69. _lblUserName.text = NSLocalizedString(@"홈 멤버끼리는 이름으로 보여집니다", @"홈 멤버끼리는 이름으로 보여집니다");
  70. _lblUserEmail.text = NSLocalizedString(@"이메일은 로그인과 비밀번호 찾기 등\n서비스 이용 인증이 필요한 경우에 사용됩니다", @"이메일은 로그인과 비밀번호 찾기 등\n서비스 이용 인증이 필요한 경우에 사용됩니다");
  71. _lblPasswd.text = NSLocalizedString(@"영어, 숫자, 특수문자 중 2가지 이상을\n사용해서 8글자 이상으로 만들어주세요", @"영어, 숫자, 특수문자 중 2가지 이상을\n사용해서 8글자 이상으로 만들어주세요");
  72. [_btnSignUp setTitle:NSLocalizedString(@"가입하기", @"가입하기") forState:UIControlStateNormal];
  73. }
  74. - (void)prepareViewDidLoad {
  75. }
  76. #pragma mark - Main Logic
  77. - (void)requestSignUp {
  78. // UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpInfoViewController" storyboardName:@"SignUp"];
  79. // [self.navigationController pushViewController:vc animated:YES];
  80. // return;
  81. // get gmt time like +09:00
  82. // float timezoneoffset = ([[NSTimeZone systemTimeZone] secondsFromGMT] / 3600.0);
  83. //
  84. // NSDateComponents *ds = [CommonUtil dateComponents:[NSDate date]];
  85. // ds.hour = (NSInteger)timezoneoffset;
  86. // NSDate *tmpDate = [[NSCalendar currentCalendar] dateFromComponents:ds];
  87. // NSDateFormatter *dateFormat = [CommonUtil dateFormatter];
  88. // [dateFormat setDateFormat:@"Z"];
  89. // NSMutableString *dateString = [NSMutableString stringWithString:[dateFormat stringFromDate:[NSDate date]]];
  90. // [dateString insertString:@":" atIndex:dateString.length-2];
  91. //parameters
  92. NSDictionary *parameter = @{@"nickname" : _txtUserName.text,
  93. @"email_id" : _txtUserEmail.text,
  94. @"password" : _txtPasswd.text,
  95. @"service_id" : MOBILE_SERVICE_ID,
  96. @"os_type" : MOBILE_DEVICE_TYPE,
  97. @"country_code" : [CommonUtil countryCode],
  98. @"timezone_name": [NSTimeZone localTimeZone].name};
  99. [[RequestHandler handler] sendAsyncPostRequestAPIPath:API_POST_SIGN_UP parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  100. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  101. return;
  102. }
  103. LoginModel *result = (LoginModel *) responseObject;
  104. if (result) {//API 성공 ,
  105. //이메일, 이메일 키 저장
  106. [JDFacade facade].tmpEmailId = _txtUserEmail.text;
  107. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpInfoViewController" storyboardName:@"SignUp"];
  108. [self.navigationController pushViewController:vc animated:YES];
  109. }
  110. } failure:^(id errorObject) {
  111. JDErrorModel *error = (JDErrorModel *)errorObject;
  112. [[JDFacade facade] alert:error.errorMessage];
  113. }];
  114. }
  115. #pragma mark - UI Events
  116. - (void)showTermUse {
  117. WebBrowseViewController *vc = (WebBrowseViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"WebBrowseViewController" storyboardName:@"Common"];
  118. vc.titleString = NSLocalizedString(@"서비스 이용약관", @"서비스 이용약관");
  119. vc.URLString = [NSString stringWithFormat:@"%@/guide/service", kAPIServer];
  120. [self.navigationController pushViewController:vc animated:YES];
  121. }
  122. - (void)showPolicy {
  123. WebBrowseViewController *vc = (WebBrowseViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"WebBrowseViewController" storyboardName:@"Common"];
  124. vc.titleString = NSLocalizedString(@"개인정보 취급정책", @"개인정보 취급정책");
  125. vc.URLString = [NSString stringWithFormat:@"%@/guide/policy", kAPIServer];
  126. [self.navigationController pushViewController:vc animated:YES];
  127. }
  128. - (void)showLocation {
  129. WebBrowseViewController *vc = (WebBrowseViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"WebBrowseViewController" storyboardName:@"Common"];
  130. vc.titleString = NSLocalizedString(@"위치기반 서비스 이용약관", @"위치기반 서비스 이용약관");
  131. vc.URLString = [NSString stringWithFormat:@"%@/guide/geo", kAPIServer];
  132. [self.navigationController pushViewController:vc animated:YES];
  133. }
  134. - (void)showMinor {
  135. [[JDFacade facade] alert:NSLocalizedString(@"만14세 미만이 가입할 때에는 부모님께 도움을 받으세요\n부모님이 동의하지 않을 경우 이용이 제한될 수 있습니다", @"만14세 미만이 가입할 때에는 부모님께 도움을 받으세요 \n부모님이 동의하지 않을 경우 이용이 제한될 수 있습니다")];
  136. }
  137. - (IBAction)btnMinorTouched:(id)sender {
  138. [self showMinor];
  139. }
  140. - (IBAction)btnSignUpTouched:(id)sender {
  141. #ifndef DEBUG
  142. //validate
  143. NSString *warn = NSLocalizedString(@"미입력 또는 미동의 항목이 남아있습니다\n확인해주세요", @"미입력 또는 미동의 항목이 남아있습니다\n확인해주세요");
  144. NSString *tmpUserName = [_txtUserName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  145. if ([tmpUserName isEmptyString]) {
  146. [[JDFacade facade] alert:warn];
  147. return;
  148. }
  149. if (![ValidateUtil validateTextfiled:_txtUserEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  150. return;
  151. }
  152. if (![ValidateUtil validateTextfiled:_txtPasswd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  153. return;
  154. }
  155. if (![_txtPasswd.text isEqualToString:_txtPasswdConfirm.text]) {
  156. [[JDFacade facade] alert:NSLocalizedString(@"비밀번호와 비밀번호 확인이 일치하지 않습니다\n다시 시도해주세요", @"비밀번호와 비밀번호 확인이 일치하지 않습니다\n다시 시도해주세요")];
  157. return;
  158. }
  159. if (!_chkTermUse.checked) {
  160. [[JDFacade facade] alert:warn];
  161. return;
  162. }
  163. if (!_chkPolicy.checked) {
  164. [[JDFacade facade] alert:warn];
  165. return;
  166. }
  167. if (!_chkLocation.checked) {
  168. [[JDFacade facade] alert:warn];
  169. return;
  170. }
  171. #else
  172. if ([_txtUserEmail.text isEmptyString]) {
  173. NSInteger rand = [CommonUtil dateComponents:[NSDate date]].second;
  174. _txtUserEmail.text = [NSString stringWithFormat:@"evoue%zd@ncomz.com", rand];
  175. }
  176. if ([_txtUserName.text isEmptyString]) {
  177. _txtUserName.text = @"이형석";
  178. }
  179. _txtPasswd.text = @"goj132!#@";
  180. #endif
  181. [self requestSignUp];
  182. }
  183. #pragma mark - MemoryWarning
  184. - (void)didReceiveMemoryWarning
  185. {
  186. [super didReceiveMemoryWarning];
  187. // Dispose of any resources that can be recreated.
  188. }
  189. @end