SignUpViewController.m 8.8 KB

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