LoginModel.m 6.0 KB

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