LoginViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. //
  2. // LoginViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 2/4/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. @import QuartzCore;
  9. #import "RequestHandler.h"
  10. #import "CustomTextField.h"
  11. #import "CustomButton.h"
  12. #import "JDJSONModel.h"
  13. #import "LoginModel.h"
  14. #import "LoginViewController.h"
  15. #import "CustomLabel.h"
  16. #import "CustomCheckBox.h"
  17. #import "KeychainItemWrapper.h"
  18. #import "NewMobileViewController.h"
  19. #import "ValidateUtil.h"
  20. #import "CustomAlertView.h"
  21. #import "CustomImageView.h"
  22. #import "PwdPopupView.h"
  23. #import "QuizSetViewController.h"
  24. #import "TempPwViewController.h"
  25. #import "SettingsNumChangeViewController.h"
  26. //#import "MobilesOverViewController.h"
  27. //#import "InvitationListViewController.h"
  28. /**
  29. ID / PW Input Box Text Color
  30. - 기본 : kUITextColor01
  31. - Hint : kUITextColor03
  32. - Disable : kUITextColor06
  33. 로그인 유지 / 아이디 저장 Text Color : kUITextColor01
  34. 아이디 찾기 / 비밀번호 찾기 / 회원가입하기 Text Color
  35. - 아이디 찾기,비밀번호 찾기 : kUITextColor01
  36. - 회원가입 하기 : kUITextColor04
  37. **/
  38. @interface LoginViewController () <CustomTextFieldDelegate,dismissQuizViewDelegate> {
  39. }
  40. @end
  41. #pragma mark - Class Definition
  42. @implementation LoginViewController
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. // Do any additional setup after loading the view.
  46. [self initUI];
  47. [self prepareViewDidLoad];
  48. }
  49. - (void)initUI {
  50. _btnLogin.enabled = NO;
  51. [self.btnLogin setBackgroundImage:[UIImage imageNamed:@"img_btn_common_active"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  52. [self.btnLogin setBackgroundImage:[UIImage imageNamed:@"img_btn_common_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  53. [self.btnLogin setBackgroundImage:[UIImage imageNamed:@"img_btn_common_disable"] forState:UIControlStateDisabled capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  54. [self.lblFindId setHidden:YES];
  55. CGRect screen = [UIScreen mainScreen].bounds;
  56. if (screen.size.height == 480) {//iphone4s
  57. [_imgvBg setImage:[UIImage imageNamed:@"img_login_bg_4inch"]];
  58. } if (screen.size.height == 667.0f) {//iphone6
  59. _constraintLeftPadding.constant *= 1.25;
  60. _constraintRightPadding.constant *= 1.25;
  61. } else if (screen.size.height == 736.0f) {//iphone6 plus
  62. _constraintLeftPadding.constant *= 1.5;
  63. _constraintRightPadding.constant *= 1.5;
  64. }
  65. // [self.view layoutIfNeeded];
  66. _txtEmail.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  67. _txtPasswd.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  68. _txtPasswd.secureTextEntry = YES;
  69. _txtEmail.keyboardType = UIKeyboardTypeDefault;
  70. _txtPasswd.keyboardType = UIKeyboardTypeDefault;
  71. _txtEmail.returnKeyType = UIReturnKeyNext;
  72. _txtPasswd.returnKeyType = UIReturnKeyDone;
  73. _txtPasswd.delegate = self;
  74. _txtEmail.delegate = self;
  75. //Localization
  76. [_chkAutoLogin setTitle:NSLocalizedString(@"로그인 유지", @"로그인 유지") forState:UIControlStateNormal];
  77. [_chkIdSave setTitle:NSLocalizedString(@"아이디 저장", @"아이디 저장") forState:UIControlStateNormal];
  78. _txtEmail.placeholder = NSLocalizedString(@"아이디", @"아이디");
  79. _txtPasswd.placeholder = NSLocalizedString(@"비밀번호", @"비밀번호");
  80. _lblSignUp.text = NSLocalizedString(@"회원가입", @"회원가입");
  81. _lblFindId.text = NSLocalizedString(@"아이디/비번찾기", @"아이디/비번찾기");
  82. // [_lblSignUp setUnderLine:_lblSignUp.text];
  83. [_lblSignUp addTouchEventHandler:^(id label) {
  84. [self lblSignUpTouched];
  85. }];
  86. [_lblFindId setUnderLine:_lblFindId.text];
  87. [_lblFindId addTouchEventHandler:^(id label) {
  88. [self lblFindIdTouched];
  89. }];
  90. }
  91. - (void)prepareViewDidLoad {
  92. [RequestHandler handler].authorization = nil;
  93. BOOL autoLogin = [[[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_AUTO_LOGIN] boolValue];
  94. BOOL idSave = [[[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_SAVE_ID] boolValue];
  95. _chkAutoLogin.checked = [[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_AUTO_LOGIN] != nil ? autoLogin : YES;
  96. _chkIdSave.checked = [[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_SAVE_ID] != nil ? idSave : YES;
  97. if (autoLogin) {
  98. [self requestAutoLogin];
  99. // _txtEmail.text = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_LOGIN_ID];
  100. // _txtPasswd.text = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_LOGIN_PWD];
  101. //
  102. // [self btnLogInTouched:_btnLogin];
  103. }
  104. if (idSave) {
  105. _txtEmail.text = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_LOGIN_ID];
  106. }
  107. }
  108. #pragma mark - Main Logic
  109. - (void)requestLogin {
  110. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_LOGIN];
  111. NSDictionary *param = @{@"member_id": [_txtEmail.text trim],
  112. @"password": [_txtPasswd.text trim],
  113. @"os_type": MOBILE_DEVICE_TYPE,
  114. @"device_token": [JDFacade facade].APNSToken ? [JDFacade facade].APNSToken : ksEmptyString};
  115. [request setRequestMsg:param];
  116. [self sendDataToSocket:request modelClass:[LoginModel class] isLoading:YES];
  117. }
  118. //자동로그인 요청
  119. - (void)requestAutoLogin {;
  120. LoginModel *tmpInfo = [[LoginModel alloc] init];
  121. tmpInfo.memberId = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_LOGIN_ID];
  122. tmpInfo.authToken = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_AUTOTOKEN];
  123. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_AUTO_LOGIN];
  124. NSDictionary *param = @{@"Authorization": tmpInfo.authorization,
  125. @"device_token": [JDFacade facade].APNSToken ? [JDFacade facade].APNSToken : ksEmptyString,
  126. @"os_type": MOBILE_DEVICE_TYPE};
  127. [request setRequestMsg:param];
  128. [self sendDataToSocket:request modelClass:[LoginModel class] isLoading:YES];
  129. // NSString *path = [NSString stringWithFormat:API_GET_SIGN_IN_AUTO];
  130. //
  131. // [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  132. // if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  133. // return;
  134. // }
  135. //
  136. // LoginModel *loginInfo = (LoginModel *)responseObject;
  137. //
  138. // if (loginInfo) {//API 성공 ,함
  139. // [self actionForLoginSucceed:loginInfo];
  140. //
  141. // }
  142. // } failure:^(id errorObject) {
  143. // JDErrorModel *error = (JDErrorModel *)errorObject;
  144. //
  145. // if ([error.errorCode isEqualToString:API_RESPONSE_UNAUTHORIZED_DEVICE]) {//새로운 단말 인증 필요
  146. // [self actionForNeedsRegisteringNewDevice:error.nickname];
  147. // } else {
  148. // [[JDFacade facade] alert:error.errorMessage];
  149. // }
  150. // }];
  151. }
  152. //인증 메일 재요청
  153. - (void)requestAuthMail {
  154. //parameters
  155. NSDictionary *parameter = @{@"email_id": [JDFacade facade].tmpEmailId};
  156. NSString *path = [NSString stringWithFormat:API_POST_AUTH_MAIL];
  157. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  158. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  159. return;
  160. }
  161. JDJSONModel *result = (JDJSONModel *) responseObject;
  162. if (result) {//API 성공 ,
  163. [[JDFacade facade] toast:NSLocalizedString(@"인증 메일이 발송되었습니다", @"인증 메일이 발송되었습니다")];
  164. }
  165. } failure:^(id errorObject) {
  166. JDErrorModel *error = (JDErrorModel *)errorObject;
  167. [[JDFacade facade] alert:error.errorMessage];
  168. }];
  169. }
  170. //로그인 이후 처리.
  171. - (void)actionForLoginSucceed:(LoginModel *)loginInfo {
  172. if (loginInfo) {//API 성공함
  173. [JDFacade facade].loginUser = loginInfo;
  174. // [JDFacade facade].loginUser.gradeCode = KNEET_MEMBER_MASTER;
  175. // [JDFacade facade].loginUser.level = 90;
  176. NSLog(@"loginUser : %@", [JDFacade facade].loginUser);
  177. if ([[JDFacade facade].loginUser.emailId isEqualToString:[JDFacade facade].tmpEmailId]) {
  178. [JDFacade facade].tmpEmailId = ksEmptyString;
  179. }
  180. if ([[JDFacade facade].loginUser.emailId isEqualToString:[JDFacade facade].loginUser.newEmailId]) {//이메일 변경 요청 중
  181. [JDFacade facade].loginUser.newEmailId = ksEmptyString;
  182. }
  183. [RequestHandler handler].authorization = loginInfo.authorization;
  184. [[JDFacade facade] storeObjectToUserDefaults:@(_chkAutoLogin.checked) forKey:USDEF_APP_AUTO_LOGIN];
  185. [[JDFacade facade] storeObjectToUserDefaults:@(_chkIdSave.checked) forKey:USDEF_APP_SAVE_ID];
  186. if (_chkAutoLogin.checked) {//자동로그인 설정 시, 인증 토큰 저장
  187. [[JDFacade facade] storeObjectToKeychain:loginInfo.memberId forKey:USDEF_SESSION_LOGIN_ID];
  188. [[JDFacade facade] storeObjectToKeychain:loginInfo.authToken forKey:USDEF_SESSION_AUTOTOKEN];
  189. } else {
  190. [[JDFacade facade] removeObjectAtKeychain:USDEF_SESSION_AUTOTOKEN];
  191. [[JDFacade facade] removeObjectAtKeychain:USDEF_SESSION_LOGIN_PWD];
  192. if (!_chkIdSave.checked) {
  193. [[JDFacade facade] removeObjectAtKeychain:USDEF_SESSION_LOGIN_ID];
  194. }
  195. }
  196. if (_chkIdSave.checked) {
  197. [[JDFacade facade] storeObjectToKeychain:[_txtEmail.text trim] forKey:USDEF_SESSION_LOGIN_ID];
  198. } else {
  199. if (!_chkAutoLogin.checked) {
  200. [[JDFacade facade] removeObjectAtKeychain:USDEF_SESSION_LOGIN_ID];
  201. }
  202. }
  203. [self gotoMainView];
  204. }
  205. }
  206. //퀴즈 설정 메뉴 dismiss 시
  207. - (void)dismissQuizView {
  208. [self gotoMainView];
  209. }
  210. //홈그룹 체크 및 대시보드 이동
  211. - (void)actionAfterLogin {
  212. if ([[JDFacade facade].loginUser.quiz isEqualToString:@""]) {
  213. QuizSetViewController *vc = (QuizSetViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"QuizSetViewController" storyboardName:@"Main"];
  214. vc.delegate = self;
  215. [self presentViewController:vc animated:YES completion:nil];
  216. return;
  217. }
  218. if ([[JDFacade facade].loginUser.invitationsCount integerValue] > 0) {
  219. [[JDFacade facade] loadInvitationView];
  220. return;
  221. }
  222. //로그인 성공 후
  223. //1. 임시 비밀번호 발급 Y인 경우 체크 후 이동
  224. if ([JDFacade facade].loginUser.tempPasswordYn && [[JDFacade facade].loginUser.tempPasswordYn boolValue]) {
  225. TempPwViewController *vc = (TempPwViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"TempPwSetViewController" storyboardName:@"SignUp"];
  226. [self presentViewController:vc animated:YES completion:nil];
  227. return;
  228. }
  229. //2.휴대폰 번호 유효성 체크후 이동
  230. if ([JDFacade facade].loginUser.phoneAuthYn && ![[JDFacade facade].loginUser.phoneAuthYn boolValue]) {
  231. [self precessPhoneAuth];
  232. return;
  233. }
  234. [self gotoMainView];
  235. }
  236. - (void)precessPhoneAuth {
  237. [[JDFacade facade] confirmTitle:@"알림"
  238. message:@"현재 사용 중인 휴대폰 번호로 계정 정보를 업데이트 하세요. 휴대폰 번호를 재등록 하지 않으면 비밀번호 찾기를 할 수 없습니다."
  239. btnOKLabel:@"지금"
  240. btnCancelLabel:@"나중에"
  241. completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  242. if (buttonIndex == 0) {
  243. SettingsNumChangeViewController *vc = (SettingsNumChangeViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"SettingsNumChangeViewController" storyboardName:@"Settings"];
  244. vc.isPresente = YES;
  245. vc.moveToMain = YES;
  246. [self presentViewController:vc animated:YES completion:nil];
  247. }
  248. else{
  249. [self gotoMainView];
  250. }
  251. }];
  252. }
  253. //새로운 단말 인증 필요 - 화면 이동
  254. - (void)actionForNeedsRegisteringNewDevice:(NSString *)nickname {
  255. NewMobileViewController *vc = (NewMobileViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"NewMobileViewController" storyboardName:@"SignUp"];
  256. vc.checkedAutoLogin = _chkAutoLogin.checked;
  257. vc.nickname = nickname;
  258. [[JDFacade facade] presentViewControllerByPush:vc pvc:self];
  259. }
  260. //단말대수 초과
  261. - (void)actionForMobilesOver:(NSArray<MobileDeviceModel> *)deviceList {
  262. //SHA-2
  263. }
  264. //인증대기중 - 화면 이동
  265. - (void)actionForWaiting {
  266. NSString *message1 = [NSString stringWithFormat:@"%@에서\n인증 메일을 확인하세요", [JDFacade facade].tmpEmailId];
  267. NSString *message2 = @"\n\n메일을 확인할 수 없는 경우에는\n스팸 메일함을 확인해보세요";
  268. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"메일을 확인하세요" message:[NSString stringWithFormat:@"%@%@", message1, message2] delegate:nil OKButtonTitle:@"확인" cancelButtonTitle:nil];
  269. [alert.lblMessage1 setColor:kUITextColor02 text:message1];
  270. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  271. if (buttonIndex == 1) {//재발송
  272. [self requestAuthMail];
  273. }
  274. }];
  275. }
  276. - (void)gotoMainView {
  277. // UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpCompleteViewController" storyboardName:@"SignUp"];
  278. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"MainViewController" storyboardName:@"Main"];
  279. [JDFacade facade].mainViewController = (MainViewController *)vc;
  280. [[JDFacade facade].appDelegate.window setRootViewController:vc];
  281. }
  282. - (void)requestLogout {
  283. [JDFacade facade].loginUser = nil;
  284. [self actionAfterLogout];
  285. // NSDictionary *param = @{API_AUTHORIZATION_KEY: [[JDFacade facade].loginUser authorization],
  286. // @"message_type": @"auth.out"};
  287. //
  288. // [self sendDataToSocket:param];
  289. //parameters
  290. // [self actionAfterLogout];
  291. // NSString *path = [NSString stringWithFormat:API_POST_SIGN_OUT];
  292. //
  293. // [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[JDJSONModel class] completion:^(id responseObject) {
  294. // [self actionAfterLogout];
  295. //
  296. // } failure:^(id errorObject) {
  297. // JDErrorModel *error = (JDErrorModel *)errorObject;
  298. // [[JDFacade facade] alert:error.errorMessage];
  299. // }];
  300. }
  301. - (void)actionAfterLogout {
  302. //자동 로그인 설정 - 취소
  303. [[JDFacade facade] storeObjectToUserDefaults:@(NO) forKey:USDEF_APP_AUTO_LOGIN];
  304. [[JDFacade facade] removeObjectAtKeychain:USDEF_SESSION_AUTOTOKEN];
  305. if (![[[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_SAVE_ID] boolValue]) {
  306. [[JDFacade facade] removeObjectAtKeychain:USDEF_SESSION_LOGIN_ID];
  307. }
  308. [JDFacade facade].loginUser = nil;
  309. [self closeSocket];
  310. [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_LOGIN_ID];
  311. //root view 변경
  312. [[JDFacade facade].appDelegate.window setRootViewController:self];
  313. }
  314. #pragma mark - UI Events
  315. - (IBAction)btnLogInTouched:(id)sender {
  316. //#ifdef DEBUG_MODE
  317. // if ([_txtEmail.text isEmptyString]) {
  318. // _txtEmail.text = @"asura77";//@"smiles1080";
  319. // }
  320. //
  321. // if ([_txtPasswd.text isEmptyString]) {
  322. // _txtPasswd.text = @"12345678a";//@"12341234aa";
  323. //
  324. // }
  325. //#endif
  326. // TODO : 아이디 형식 검사할것
  327. // if (![ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeEmail title:@"이메일" ]) {
  328. // return;
  329. // }
  330. // if (![ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeNull title:@"비밀번호" ]) {
  331. // return;
  332. // }
  333. [JDFacade facade].tmpEmailId = [_txtEmail.text trim];
  334. [JDFacade facade].tmpPassword = [_txtPasswd.text trim];
  335. [self requestLogin];
  336. }
  337. //회원가입 호출
  338. - (void)lblSignUpTouched {
  339. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpTypeSelectViewController" storyboardName:@"SignUp"];
  340. UINavigationController *m_navi =[[UINavigationController alloc]initWithRootViewController:vc];
  341. [self presentViewController:m_navi animated:YES completion:nil];
  342. }
  343. - (void)lblFindIdTouched {
  344. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ResetPwdViewController" storyboardName:@"SignUp"];
  345. [self presentViewController:vc animated:YES completion:nil];
  346. }
  347. // 아이디 찾기 호출
  348. - (IBAction)btnIdFindTouched:(id)sender {
  349. NSLog(@"아이디 찾기");
  350. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"IdFindViewController" storyboardName:@"SignUp"];
  351. UINavigationController *m_navi =[[UINavigationController alloc]initWithRootViewController:vc];
  352. [self presentViewController:m_navi animated:YES completion:nil];
  353. }
  354. // 비밀번호 찾기 호출
  355. - (IBAction)btnPwFindTouched:(id)sender {
  356. NSLog(@"비밀번호 찾기");
  357. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"PwFindViewController" storyboardName:@"SignUp"];
  358. UINavigationController *m_navi =[[UINavigationController alloc]initWithRootViewController:vc];
  359. [self presentViewController:m_navi animated:YES completion:nil];
  360. }
  361. #pragma mark - CustomTextField
  362. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  363. if ([textField isEqual:_txtEmail])
  364. {
  365. [_txtPasswd becomeFirstResponder];
  366. }
  367. if ([textField isEqual:_txtPasswd])
  368. {
  369. [self btnLogInTouched:nil];
  370. }
  371. return YES;
  372. }
  373. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  374. NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
  375. NSString *userID = [textField isEqual:_txtEmail] ? text : _txtEmail.text;
  376. NSString *userPW = [textField isEqual:_txtPasswd] ? text : _txtPasswd.text;
  377. _btnLogin.enabled = userID.length >= 6 && userPW.length >= 8;
  378. return YES;
  379. }
  380. //다음
  381. - (void)moveToNextField:(id)sender {
  382. [_txtPasswd becomeFirstResponder] ;
  383. }
  384. #pragma mark - SocketService
  385. - (void) socketDidReceiveMessage:(id)message result:(SocketModel *)result
  386. {
  387. SWITCH(result.messageType)
  388. {
  389. CASE (MSG_TYPE_LOGIN)
  390. {
  391. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  392. if (result.isSuccess) {
  393. LoginModel *loginInfo = (LoginModel *)message;
  394. [self actionForLoginSucceed:loginInfo];
  395. }
  396. else {
  397. [self loginErrorAlert:result];
  398. }
  399. break;
  400. }
  401. CASE (MSG_TYPE_AUTO_LOGIN)
  402. {
  403. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  404. if (result.isSuccess) {
  405. LoginModel *loginInfo = (LoginModel *)message;
  406. loginInfo.memberId = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_LOGIN_ID];
  407. loginInfo.authToken = [[JDFacade facade] objectForKeyFromKeychain:USDEF_SESSION_AUTOTOKEN];
  408. [self actionForLoginSucceed:loginInfo];
  409. }
  410. else {
  411. [self loginErrorAlert:result];
  412. }
  413. break;
  414. }
  415. CASE(@"auth.out")
  416. {
  417. if (result.isSuccess) {
  418. [self actionAfterLogout];
  419. }
  420. else {
  421. NSLog(@"Result Info : %@", result);
  422. }
  423. }
  424. DEFAULT
  425. {
  426. break;
  427. }
  428. }
  429. }
  430. - (void) loginErrorAlert:(SocketModel*)result {
  431. if (EQUALS(result.resultCode, @"102")) {
  432. [[JDFacade facade] confirmTitle:@"로그인 오류" message:@"로그인이 제한됩니다. 비밀번호 찾기 후 로그인 하세요." btnOKLabel:@"지금" btnCancelLabel:@"나중에" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  433. if (buttonIndex == 0) {
  434. [self btnPwFindTouched:nil];
  435. }
  436. }];
  437. }
  438. else {
  439. [[JDFacade facade] alertTitle:@"알림" message:result.resultMsg];
  440. }
  441. }
  442. - (void) socketDidFailWithError:(NSError *)error {
  443. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  444. }
  445. #pragma mark - MemoryWarning
  446. - (void)didReceiveMemoryWarning
  447. {
  448. [super didReceiveMemoryWarning];
  449. // Dispose of any resources that can be recreated.
  450. }
  451. @end