SignUpViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 "UIButton+WebCache.h"
  17. #import "WebBrowseViewController.h"
  18. #import "SignUpViewController.h"
  19. #import "ImageUtil.h"
  20. #import "CustomAlertView.h"
  21. @implementation SignUpProfileTableViewCell
  22. @end
  23. @implementation SignUpNameTableViewCell
  24. - (void)didMoveToSuperview {
  25. _txtNickname.placeholder = NSLocalizedString(@"이름", @"이름");
  26. _txtNickname.keyboardType = UIKeyboardTypeDefault;
  27. _txtNickname.returnKeyType = UIReturnKeyDone;
  28. _txtNickname.autoScrollUp = YES;
  29. _txtNickname.customTextFieldSuperview = CustomTextFieldSuperviewIsViewController;
  30. }
  31. @end
  32. @implementation SignUpEmailTableViewCell
  33. - (void)didMoveToSuperview {
  34. _txtEmail.placeholder = NSLocalizedString(@"이메일", @"이메일");
  35. _txtEmail.keyboardType = UIKeyboardTypeEmailAddress;
  36. _txtEmail.returnKeyType = UIReturnKeyDone;
  37. _txtEmail.autoScrollUp = YES;
  38. _txtEmail.customTextFieldSuperview = CustomTextFieldSuperviewIsViewController;
  39. }
  40. @end
  41. @implementation SignUpPasswdTableViewCell
  42. - (void)didMoveToSuperview {
  43. _txtPasswd.placeholder = NSLocalizedString(@"비밀번호", @"비밀번호");
  44. _txtPasswd.keyboardType = UIKeyboardTypeDefault;
  45. _txtPasswd.returnKeyType = UIReturnKeyDone;
  46. _txtPasswd.secureTextEntry = YES;
  47. _txtPasswd.autoScrollUp = YES;
  48. _txtPasswd.customTextFieldSuperview = CustomTextFieldSuperviewIsViewController;
  49. }
  50. @end
  51. @implementation SignUpPGuideTableViewCell
  52. @end
  53. @implementation SignUpPasswdConfirmTableViewCell
  54. - (void)didMoveToSuperview {
  55. _txtPasswdConfirm.placeholder = NSLocalizedString(@"비밀번호 확인", @"비밀번호 확인");
  56. _txtPasswdConfirm.keyboardType = UIKeyboardTypeDefault;
  57. _txtPasswdConfirm.secureTextEntry = YES;
  58. _txtPasswdConfirm.returnKeyType = UIReturnKeyDone;
  59. _txtPasswdConfirm.autoScrollUp = YES;
  60. _txtPasswdConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsViewController;
  61. }
  62. @end
  63. @interface SignUpViewController () <ImageUtilDelegate, CustomTextFieldDelegate> {
  64. CustomTextField *_txtNickname, *_txtEmail, *_txtPasswd, *_txtPasswdConfirm;
  65. CustomButton *_btnProfile;
  66. ImageUtil *_imageUtil;
  67. }
  68. @end
  69. #pragma mark - Class Definition
  70. @implementation SignUpViewController
  71. - (void)viewDidLoad {
  72. [super viewDidLoad];
  73. // Do any additional setup after loading the view.
  74. [self initUI];
  75. [self prepareViewDidLoad];
  76. }
  77. - (void)viewWillAppear:(BOOL)animated {
  78. [super viewWillAppear:animated];
  79. self.title = NSLocalizedString(@"AoTHome 가입", @"AoTHome 가입");
  80. }
  81. - (void)initUI {
  82. [self initTableViewAsDefaultStyle:_tableView];
  83. //Localization
  84. [_btnSignUp setTitle:NSLocalizedString(@"완료", @"완료") forState:UIControlStateNormal];
  85. }
  86. - (void)prepareViewDidLoad {
  87. }
  88. #pragma mark - Main Logic
  89. - (void)requestSignUp {
  90. // UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpInfoViewController" storyboardName:@"SignUp"];
  91. // [self.navigationController pushViewController:vc animated:YES];
  92. // return;
  93. // get gmt time like +09:00
  94. // float timezoneoffset = ([[NSTimeZone systemTimeZone] secondsFromGMT] / 3600.0);
  95. //
  96. // NSDateComponents *ds = [CommonUtil dateComponents:[NSDate date]];
  97. // ds.hour = (NSInteger)timezoneoffset;
  98. // NSDate *tmpDate = [[NSCalendar currentCalendar] dateFromComponents:ds];
  99. // NSDateFormatter *dateFormat = [CommonUtil dateFormatter];
  100. // [dateFormat setDateFormat:@"Z"];
  101. // NSMutableString *dateString = [NSMutableString stringWithString:[dateFormat stringFromDate:[NSDate date]]];
  102. // [dateString insertString:@":" atIndex:dateString.length-2];
  103. //parameters
  104. NSDictionary *parameter = @{@"nickname" : _txtNickname.text,
  105. @"email_id" : _txtEmail.text,
  106. @"password" : _txtPasswd.text,
  107. @"service_id" : MOBILE_SERVICE_ID,
  108. @"os_type" : MOBILE_DEVICE_TYPE,
  109. @"country_code" : [CommonUtil countryCode],
  110. @"timezone_name": [NSTimeZone localTimeZone].name,
  111. @"image_file": [_btnProfile imageForState:UIControlStateNormal]};
  112. [[RequestHandler handler] sendAsyncPostRequestAPIPath:API_POST_SIGN_UP parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  113. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  114. return;
  115. }
  116. LoginModel *result = (LoginModel *) responseObject;
  117. if (result) {//API 성공 ,
  118. //이메일, 이메일 키 저장
  119. [JDFacade facade].tmpEmailId = _txtEmail.text;
  120. NSString *message = [NSString stringWithFormat:@"%@에서\n인증 메일을 확인하세요\n\n메일을 확인할 수 없는 경우에는\n스팸 메일함을 확인해보세요", [JDFacade facade].tmpEmailId];
  121. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"메일을 확인하세요" message:message delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  122. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  123. if (buttonIndex == 0) {//OK
  124. [[JDFacade facade] dismissModalStack:YES completion:nil];
  125. }
  126. }];
  127. }
  128. } failure:^(id errorObject) {
  129. JDErrorModel *error = (JDErrorModel *)errorObject;
  130. [[JDFacade facade] alert:error.errorMessage];
  131. }];
  132. }
  133. #pragma mark - UITableView DataSource & Delegate
  134. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  135. return 1;
  136. }
  137. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  138. return 6;
  139. }
  140. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  141. CGFloat height = 40.0f;
  142. if (indexPath.row == 0) {
  143. height = 120.0f;
  144. }
  145. return height;
  146. }
  147. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  148. UITableViewCell *cell = nil;
  149. if (indexPath.row == 0) {
  150. SignUpProfileTableViewCell *tcell = (SignUpProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ProfileCellIdentifier"];
  151. if (!_btnProfile) {
  152. _btnProfile = tcell.btnProfile;
  153. }
  154. if (![_btnProfile actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  155. [_btnProfile addTarget:self action:@selector(btnProfileTouched:) forControlEvents:UIControlEventTouchUpInside];
  156. }
  157. cell = tcell;
  158. } else if (indexPath.row == 1) {
  159. SignUpNameTableViewCell *tcell = (SignUpNameTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"NameCellIdentifier"];
  160. if (!_txtNickname) {
  161. _txtNickname = tcell.txtNickname;
  162. _txtNickname.delegate = self;
  163. }
  164. cell = tcell;
  165. } else if (indexPath.row == 2) {
  166. SignUpEmailTableViewCell *tcell = (SignUpEmailTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"EmailCellIdentifier"];
  167. if (!_txtEmail) {
  168. _txtEmail = tcell.txtEmail;
  169. _txtEmail.delegate = self;
  170. }
  171. cell = tcell;
  172. } else if (indexPath.row == 3) {
  173. SignUpPasswdTableViewCell *tcell = (SignUpPasswdTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PasswdCellIdentifier"];
  174. if (!_txtPasswd) {
  175. _txtPasswd = tcell.txtPasswd;
  176. _txtPasswd.delegate = self;
  177. }
  178. cell = tcell;
  179. } else if (indexPath.row == 4) {
  180. SignUpPGuideTableViewCell *tcell = (SignUpPGuideTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PGuideCellIdentifier"];
  181. cell = tcell;
  182. } else if (indexPath.row == 5) {
  183. SignUpPasswdConfirmTableViewCell *tcell = (SignUpPasswdConfirmTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PasswdConfirmCellIdentifier"];
  184. if (!_txtPasswdConfirm) {
  185. _txtPasswdConfirm = tcell.txtPasswdConfirm;
  186. _txtPasswdConfirm.delegate = self;
  187. }
  188. cell = tcell;
  189. }
  190. return cell;
  191. }
  192. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  193. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  194. }
  195. #pragma mark - ImageUtil Delegate
  196. - (void)didFinishPickingImage:(UIImage *)image {
  197. [_btnProfile setImage:image forState:UIControlStateNormal];
  198. }
  199. #pragma mark - UI Events
  200. - (void)btnProfileTouched:(id)sender {
  201. if (!_imageUtil) {
  202. _imageUtil = [[ImageUtil alloc] init];
  203. _imageUtil.delegate = self;
  204. }
  205. [_imageUtil prepareImagePicker];
  206. }
  207. - (IBAction)btnSignUpTouched:(id)sender {
  208. #ifndef DEBUG
  209. if (![ValidateUtil validateTextfiled:_txtNickname type:ValidateTypeNickname title:@"이름"]) {
  210. return;
  211. }
  212. if (![ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  213. return;
  214. }
  215. if (![ValidateUtil validateTextfiled:_txtPasswd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  216. return;
  217. }
  218. if (![_txtPasswd.text isEqualToString:_txtPasswdConfirm.text]) {
  219. [[JDFacade facade] alert:NSLocalizedString(@"두 비밀번호가 일치하지 않습니다", @"두 비밀번호가 일치하지 않습니다")];
  220. return;
  221. }
  222. #else
  223. if ([_txtEmail.text isEmptyString]) {
  224. NSInteger rand = [CommonUtil dateComponents:[NSDate date]].second;
  225. _txtEmail.text = [NSString stringWithFormat:@"evoue%zd@ncomz.com", rand];
  226. }
  227. if ([_txtNickname.text isEmptyString]) {
  228. _txtNickname.text = @"이형석";
  229. }
  230. _txtPasswd.text = @"goj132!#@";
  231. #endif
  232. [self requestSignUp];
  233. }
  234. - (IBAction)btnCancelTouched:(id)sender {
  235. [self dismissViewControllerAnimated:YES completion:nil];
  236. }
  237. #pragma mark - CustomTextField Delegate
  238. - (void)textFieldDidEndEditing:(UITextField *)textField {
  239. if ([_txtNickname isEqual:textField]) {
  240. [ValidateUtil validateTextfiled:_txtNickname type:ValidateTypeNickname title:@"이름"];
  241. } else if ([_txtEmail isEqual:textField]) {
  242. [ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")];
  243. } else if ([_txtPasswd isEqual:textField]) {
  244. [ValidateUtil validateTextfiled:_txtPasswd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")];
  245. } else if ([_txtPasswdConfirm isEqual:textField]) {
  246. [ValidateUtil validateTextfiled:_txtPasswdConfirm type:ValidateTypePassword title:NSLocalizedString(@"비밀번호 확인", @"비밀번호 확인")];
  247. }
  248. }
  249. #pragma mark - MemoryWarning
  250. - (void)didReceiveMemoryWarning
  251. {
  252. [super didReceiveMemoryWarning];
  253. // Dispose of any resources that can be recreated.
  254. }
  255. @end