LoginModel.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // JDJSONModel.h
  3. // kneet
  4. //
  5. // Created by Jason Lee on 2/9/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "LoginModel.h"
  10. #import "CypherUtil.h"
  11. #import "NSData+AESCrypt.h"
  12. #import "NSString-Addtions.h"
  13. @implementation InvitationModel
  14. @end
  15. @implementation InvitationListModel
  16. @end
  17. @implementation HomeMemberModel
  18. @end
  19. @implementation HomeMemberListModel
  20. @end
  21. @implementation MemberIconModel
  22. @end
  23. @implementation MemberIconListModel
  24. @end
  25. @implementation MobileDeviceListModel
  26. @end
  27. @implementation LoginModel
  28. @synthesize memberId = _memberId, homegrpId = _homegrpId, newEmailId = _newEmailId, modeChange = _modeChange, noticeReadTime = _noticeReadTime, personalNoticeReadTime = _personalNoticeReadTime;
  29. //+ (JSONKeyMapper *)keyMapper {
  30. //
  31. // NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
  32. //
  33. // //Self
  34. // [dictionary setValue:@"lang" forKey:@"lang"];
  35. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  36. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  37. //
  38. // [dictionary setValue:@"lang" forKey:@"lang"];
  39. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  40. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  41. // [dictionary setValue:@"member" forKey:@"member"];
  42. // [dictionary setValue:@"timezoneId" forKey:@"timezone_id"];
  43. // [dictionary setValue:@"timezone" forKey:@"timezone"];
  44. // [dictionary setValue:@"countryCode" forKey:@"country_code"];
  45. // [dictionary setValue:@"memberId" forKey:@"member_id"];
  46. // [dictionary setValue:@"serviceId" forKey:@"service_id"];
  47. // [dictionary setValue:@"imageFileName" forKey:@"image_file_name"];
  48. // [dictionary setValue:@"nickname" forKey:@"nickname"];
  49. // [dictionary setValue:@"key" forKey:@"key"];
  50. // [dictionary setValue:@"homegrpId" forKey:@"homegrp_id"];
  51. // [dictionary setValue:@"homegrpList" forKey:@"homegrp_list"];
  52. //
  53. // return [[JSONKeyMapper alloc] initWithDictionary:dictionary];
  54. //}
  55. - (void)setMemberId:(NSString *)memberId {
  56. _memberId = memberId;
  57. //사용자 아이디 리스트
  58. NSMutableArray *userList = [[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_USERID_LIST];
  59. BOOL isExist = NO;
  60. if (!userList) {
  61. userList = [[NSMutableArray alloc] init];
  62. } else {
  63. for (NSString *memberId in userList) {
  64. isExist = [_memberId isEqualToString:memberId];
  65. if (isExist) {
  66. break;
  67. }
  68. }
  69. }
  70. if (!isExist) {//기존에 없으면 추가함.
  71. [userList addObject:_memberId];
  72. }
  73. [[JDFacade facade] storeObjectToUserDefaults:userList forKey:USDEF_APP_USERID_LIST];
  74. }
  75. - (NSString *)emailId {
  76. if (!_emailId || [_emailId isEmptyString]) {
  77. _emailId = [JDFacade facade].tmpEmailId;
  78. }
  79. return _emailId;
  80. }
  81. //새 이메일 변경 시 - 체크를 위한 로컬 저장
  82. - (NSString *)newEmailId {
  83. if (!_newEmailId) {
  84. _newEmailId = [self.localStorage objectForKey:USDEF_SESSION_NEW_EMAIL];
  85. }
  86. return _newEmailId ? _newEmailId : nil;
  87. }
  88. - (void)setNewEmailId:(NSString *)newEmailId {
  89. _newEmailId = newEmailId;
  90. //로컬 저장소에 저장
  91. [self.localStorage setObject:_newEmailId forKey:USDEF_SESSION_NEW_EMAIL];
  92. [self synchronizeLocalStorage];
  93. }
  94. //모드 변경 저장
  95. - (NSString *)modeChange {
  96. if (!_modeChange) {
  97. _modeChange = [self.localStorage objectForKey:USDEF_SESSION_MODE_CHANGE];
  98. }
  99. return _modeChange ? _modeChange : nil;
  100. }
  101. - (void)setModeChange:(NSString *)modeChange {
  102. _modeChange = modeChange;
  103. //로컬 저장소에 저장
  104. [self.localStorage setObject:_modeChange forKey:USDEF_SESSION_MODE_CHANGE];
  105. [self synchronizeLocalStorage];
  106. }
  107. //세션 - 공지 읽음 날짜 확인
  108. - (NSString *)noticeReadTime {
  109. if (!_noticeReadTime) {
  110. _noticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_NOTICE_READ_DATE];
  111. }
  112. return _noticeReadTime ? _noticeReadTime : nil;
  113. }
  114. - (void)setNoticeReadTime:(NSString *)noticeReadTime {
  115. _noticeReadTime = noticeReadTime;
  116. //로컬 저장소에 저장
  117. [self.localStorage setObject:_noticeReadTime forKey:USDEF_SESSION_NOTICE_READ_DATE];
  118. [self synchronizeLocalStorage];
  119. }
  120. //세션 - 알림 읽음 날짜 확인
  121. - (NSString *)personalNoticeReadTime {
  122. if (!_personalNoticeReadTime) {
  123. _personalNoticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_PUSH_READ_DATE];
  124. }
  125. return _personalNoticeReadTime ? _personalNoticeReadTime : nil;
  126. }
  127. - (void)setPersonalNoticeReadTime:(NSString *)personalNoticeReadTime {
  128. _personalNoticeReadTime = personalNoticeReadTime;
  129. //로컬 저장소에 저장
  130. [self.localStorage setObject:_personalNoticeReadTime forKey:USDEF_SESSION_PUSH_READ_DATE];
  131. [self synchronizeLocalStorage];
  132. }
  133. - (NSInteger)level {
  134. _level = 0;
  135. if ([_gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  136. _level = 90;
  137. } else if ([_gradeCode isEqualToString:KNEET_MEMBER_SIMPLE]) {
  138. _level = 10;
  139. }
  140. return _level;
  141. }
  142. // TODO: 홈그룹 온라인 / 보유 여부 로직 변경하기
  143. - (BOOL)isHomehubOnline {
  144. return _homehubOnlineState && ![_homehubOnlineState isEmptyString] && [_homehubOnlineState isEqualToString:@"ON"];
  145. }
  146. - (BOOL)hasHomeHub {
  147. NSLog(@"HomeHubDevice ID : %@", _homehubDeviceId);
  148. return _homehubDeviceId && ![_homehubDeviceId isEmptyString];
  149. }
  150. -(NSString *)authorization
  151. {
  152. // NSString *result = @"asura77:1f6bafe0801d52b557fc7b5277cb878bc36e54987b6eec036e713b1229096117";
  153. NSString *result = nil;
  154. if(_memberId !=nil && _authToken != nil)
  155. {
  156. result= [NSString stringWithFormat:@"%@:%@", _memberId, _authToken];
  157. }
  158. return [result base64Enc];
  159. }
  160. #pragma mark - about Location Settings
  161. //로컬 저장소
  162. - (NSMutableDictionary *)localStorage {
  163. if (!self.memberId)
  164. return nil;
  165. if (!_localStorage) {
  166. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  167. _localStorage = [[JDFacade facade] objectForKeyFromUserDefaults:encryptedKey];
  168. if (!_localStorage) {//저장된 정보가 없을 경우,
  169. _localStorage = [[NSMutableDictionary alloc] init];
  170. }
  171. }
  172. return _localStorage;
  173. }
  174. - (void)synchronizeLocalStorage {
  175. if (!self.memberId)
  176. return;
  177. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  178. [[JDFacade facade] storeObjectToUserDefaults:self.localStorage forKey:encryptedKey];
  179. }
  180. @end