SignUpViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. }
  80. - (void)initUI {
  81. [self initTableViewAsDefaultStyle:_tableView];
  82. _txtPasswd.customTextFieldSuperview = CustomTextFieldSuperviewIsChildViewController;
  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 backgroundImageForState:UIControlStateNormal]};
  112. [[RequestHandler handler] sendAsyncPostRequestAPIPath:@"" 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 *message1 = [NSString stringWithFormat:@"%@에서\n인증 메일을 확인하세요", [JDFacade facade].tmpEmailId];
  121. NSString *message2 = @"\n\n메일을 확인할 수 없는 경우에는\n스팸 메일함을 확인해보세요";
  122. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"메일을 확인하세요" message:[NSString stringWithFormat:@"%@%@", message1, message2] delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  123. [alert.lblMessage1 setColor:kUITextColor02 text:message1];
  124. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  125. if (buttonIndex == 0) {//OK
  126. [[JDFacade facade] dismissModalStack:YES completion:nil];
  127. }
  128. }];
  129. }
  130. } failure:^(id errorObject) {
  131. JDErrorModel *error = (JDErrorModel *)errorObject;
  132. [[JDFacade facade] alert:error.errorMessage];
  133. }];
  134. }
  135. #pragma mark - UITableView DataSource & Delegate
  136. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  137. return 1;
  138. }
  139. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  140. return 6;
  141. }
  142. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  143. CGFloat height = 40.0f;
  144. if (indexPath.row == 0) {
  145. height = 120.0f;
  146. }
  147. return height;
  148. }
  149. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  150. UITableViewCell *cell = nil;
  151. if (indexPath.row == 0) {
  152. SignUpProfileTableViewCell *tcell = (SignUpProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ProfileCellIdentifier"];
  153. if (!_btnProfile) {
  154. _btnProfile = tcell.btnProfile;
  155. }
  156. if (![_btnProfile actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  157. [_btnProfile addTarget:self action:@selector(btnProfileTouched:) forControlEvents:UIControlEventTouchUpInside];
  158. }
  159. if (![tcell.btnSetProfile actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  160. [tcell.btnSetProfile addTarget:self action:@selector(btnProfileTouched:) forControlEvents:UIControlEventTouchUpInside];
  161. }
  162. cell = tcell;
  163. } else if (indexPath.row == 1) {
  164. SignUpNameTableViewCell *tcell = (SignUpNameTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"NameCellIdentifier"];
  165. if (!_txtNickname) {
  166. _txtNickname = tcell.txtNickname;
  167. _txtNickname.delegate = self;
  168. }
  169. cell = tcell;
  170. } else if (indexPath.row == 2) {
  171. SignUpEmailTableViewCell *tcell = (SignUpEmailTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"EmailCellIdentifier"];
  172. if (!_txtEmail) {
  173. _txtEmail = tcell.txtEmail;
  174. _txtEmail.delegate = self;
  175. }
  176. cell = tcell;
  177. } else if (indexPath.row == 3) {
  178. SignUpPasswdTableViewCell *tcell = (SignUpPasswdTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PasswdCellIdentifier"];
  179. if (!_txtPasswd) {
  180. _txtPasswd = tcell.txtPasswd;
  181. _txtPasswd.delegate = self;
  182. }
  183. cell = tcell;
  184. } else if (indexPath.row == 4) {
  185. SignUpPGuideTableViewCell *tcell = (SignUpPGuideTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PGuideCellIdentifier"];
  186. cell = tcell;
  187. } else if (indexPath.row == 5) {
  188. SignUpPasswdConfirmTableViewCell *tcell = (SignUpPasswdConfirmTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PasswdConfirmCellIdentifier"];
  189. if (!_txtPasswdConfirm) {
  190. _txtPasswdConfirm = tcell.txtPasswdConfirm;
  191. _txtPasswdConfirm.delegate = self;
  192. }
  193. cell = tcell;
  194. }
  195. return cell;
  196. }
  197. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  198. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  199. }
  200. #pragma mark - ImageUtil Delegate
  201. - (void)didFinishPickingImage:(UIImage *)image {
  202. // UIImage *maskImage = [ImageUtil resizeImage:[UIImage imageNamed:@"common_mask_circle"] width:65 height:65];
  203. // UIImage *thumbImage = [ImageUtil getMaskedImageWithSourchImage:image andMaskImage:maskImage];
  204. [_btnProfile setBackgroundImage:image forState:UIControlStateNormal];
  205. }
  206. #pragma mark - UI Events
  207. - (void)btnProfileTouched:(id)sender {
  208. if (!_imageUtil) {
  209. _imageUtil = [[ImageUtil alloc] init];
  210. _imageUtil.delegate = self;
  211. }
  212. [_imageUtil prepareImagePicker:self];
  213. }
  214. - (IBAction)btnSignUpTouched:(id)sender {
  215. #ifndef DEBUG
  216. if (![ValidateUtil validateTextfiled:_txtNickname type:ValidateTypeNickname title:@"이름"]) {
  217. return;
  218. }
  219. if (![ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
  220. return;
  221. }
  222. if (![ValidateUtil validateTextfiled:_txtPasswd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")]) {
  223. return;
  224. }
  225. if (![_txtPasswd.text isEqualToString:_txtPasswdConfirm.text]) {
  226. [[JDFacade facade] alert:NSLocalizedString(@"두 비밀번호가 일치하지 않습니다", @"두 비밀번호가 일치하지 않습니다")];
  227. return;
  228. }
  229. #else
  230. if ([_txtEmail.text isEmptyString]) {
  231. NSInteger rand = [CommonUtil dateComponents:[NSDate date]].second;
  232. _txtEmail.text = [NSString stringWithFormat:@"evoue%zd@ncomz.com", rand];
  233. }
  234. if ([_txtNickname.text isEmptyString]) {
  235. _txtNickname.text = @"이형석";
  236. }
  237. _txtPasswd.text = @"goj132!#@";
  238. #endif
  239. [self requestSignUp];
  240. }
  241. - (IBAction)btnCancelTouched:(id)sender {
  242. [self dismissViewControllerAnimated:YES completion:nil];
  243. }
  244. #pragma mark - CustomTextField Delegate
  245. - (void)textFieldDidEndEditing:(UITextField *)textField {
  246. // if ([_txtNickname isEqual:textField]) {
  247. // [ValidateUtil validateTextfiled:_txtNickname type:ValidateTypeNickname title:@"이름"];
  248. //
  249. // } else if ([_txtEmail isEqual:textField]) {
  250. // [ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")];
  251. //
  252. // } else if ([_txtPasswd isEqual:textField]) {
  253. // [ValidateUtil validateTextfiled:_txtPasswd type:ValidateTypePassword title:NSLocalizedString(@"비밀번호", @"비밀번호")];
  254. //
  255. // } else if ([_txtPasswdConfirm isEqual:textField]) {
  256. // [ValidateUtil validateTextfiled:_txtPasswdConfirm type:ValidateTypePassword title:NSLocalizedString(@"비밀번호 확인", @"비밀번호 확인")];
  257. // }
  258. }
  259. #pragma mark - MemoryWarning
  260. - (void)didReceiveMemoryWarning
  261. {
  262. [super didReceiveMemoryWarning];
  263. // Dispose of any resources that can be recreated.
  264. }
  265. @end