LoginModel.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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)setSelectedHomeHubID:(NSString *)selectedHomeHubID{
  56. // TODO : 홈허브를 선택했을 경우 저장하는 기능 구현
  57. if([self isExistHomeHubID:selectedHomeHubID])
  58. {
  59. _selectedHomeHubID = selectedHomeHubID;
  60. }
  61. }
  62. - (NSString *)getSelectedHomeHubID {
  63. // TODO : 홈허브 아이디를 선택했을 경우 저장된 홈허브 아이디를 가져오는 기능
  64. return _selectedHomeHubID;
  65. }
  66. - (BOOL)isExistHomeHubID:(NSString *)homeHubID {
  67. BOOL result = false;
  68. for (DeviceModel *info in _deviceList) {
  69. if([info.deviceId isEquestToIgnoreCase:homeHubID]) {
  70. result = true;
  71. }
  72. }
  73. return result;
  74. }
  75. - (BOOL)isMultiHomeHub {
  76. BOOL result = false;
  77. if (_deviceList.count > 1) {
  78. result = true;
  79. }
  80. return result;
  81. }
  82. - (void)setMemberId:(NSString *)memberId {
  83. _memberId = memberId;
  84. //사용자 아이디 리스트
  85. NSMutableArray *userList = [[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_USERID_LIST];
  86. BOOL isExist = NO;
  87. if (!userList) {
  88. userList = [[NSMutableArray alloc] init];
  89. } else {
  90. for (NSString *memberId in userList) {
  91. isExist = [_memberId isEqualToString:memberId];
  92. if (isExist) {
  93. break;
  94. }
  95. }
  96. }
  97. if (!isExist) {//기존에 없으면 추가함.
  98. [userList addObject:_memberId];
  99. }
  100. [[JDFacade facade] storeObjectToUserDefaults:userList forKey:USDEF_APP_USERID_LIST];
  101. }
  102. - (NSString *)emailId {
  103. if (!_emailId || [_emailId isEmptyString]) {
  104. _emailId = [JDFacade facade].tmpEmailId;
  105. }
  106. return _emailId;
  107. }
  108. //새 이메일 변경 시 - 체크를 위한 로컬 저장
  109. - (NSString *)newEmailId {
  110. if (!_newEmailId) {
  111. _newEmailId = [self.localStorage objectForKey:USDEF_SESSION_NEW_EMAIL];
  112. }
  113. return _newEmailId ? _newEmailId : nil;
  114. }
  115. - (void)setNewEmailId:(NSString *)newEmailId {
  116. _newEmailId = newEmailId;
  117. //로컬 저장소에 저장
  118. [self.localStorage setObject:_newEmailId forKey:USDEF_SESSION_NEW_EMAIL];
  119. [self synchronizeLocalStorage];
  120. }
  121. //모드 변경 저장
  122. - (NSString *)modeChange {
  123. if (!_modeChange) {
  124. _modeChange = [self.localStorage objectForKey:USDEF_SESSION_MODE_CHANGE];
  125. }
  126. return _modeChange ? _modeChange : nil;
  127. }
  128. - (void)setModeChange:(NSString *)modeChange {
  129. _modeChange = modeChange;
  130. //로컬 저장소에 저장
  131. [self.localStorage setObject:_modeChange forKey:USDEF_SESSION_MODE_CHANGE];
  132. [self synchronizeLocalStorage];
  133. }
  134. //세션 - 공지 읽음 날짜 확인
  135. - (NSString *)noticeReadTime {
  136. if (!_noticeReadTime) {
  137. _noticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_NOTICE_READ_DATE];
  138. }
  139. return _noticeReadTime ? _noticeReadTime : nil;
  140. }
  141. - (void)setNoticeReadTime:(NSString *)noticeReadTime {
  142. _noticeReadTime = noticeReadTime;
  143. //로컬 저장소에 저장
  144. [self.localStorage setObject:_noticeReadTime forKey:USDEF_SESSION_NOTICE_READ_DATE];
  145. [self synchronizeLocalStorage];
  146. }
  147. //세션 - 알림 읽음 날짜 확인
  148. - (NSString *)personalNoticeReadTime {
  149. if (!_personalNoticeReadTime) {
  150. _personalNoticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_PUSH_READ_DATE];
  151. }
  152. return _personalNoticeReadTime ? _personalNoticeReadTime : nil;
  153. }
  154. - (void)setPersonalNoticeReadTime:(NSString *)personalNoticeReadTime {
  155. _personalNoticeReadTime = personalNoticeReadTime;
  156. //로컬 저장소에 저장
  157. [self.localStorage setObject:_personalNoticeReadTime forKey:USDEF_SESSION_PUSH_READ_DATE];
  158. [self synchronizeLocalStorage];
  159. }
  160. - (NSInteger)level {
  161. _level = 0;
  162. if ([_gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  163. _level = 90;
  164. } else if ([_gradeCode isEqualToString:KNEET_MEMBER_SIMPLE]) {
  165. _level = 10;
  166. }
  167. return _level;
  168. }
  169. // TODO: 홈그룹 온라인 / 보유 여부 로직 변경하기
  170. - (BOOL)isHomehubOnline {
  171. BOOL result = false;
  172. for (DeviceModel *deviceInfo in _deviceList) {
  173. if (deviceInfo.isDeviceOnline && deviceInfo.isDeviceConn) {
  174. result = true;
  175. break;
  176. }
  177. }
  178. return result;
  179. }
  180. - (BOOL)hasHomeHub {
  181. BOOL result = false;
  182. for (DeviceModel *deviceInfo in _deviceList) {
  183. if (deviceInfo.deviceId && ![deviceInfo.deviceId isEmptyString]) {
  184. result = true;
  185. break;
  186. }
  187. }
  188. return result;
  189. }
  190. -(NSString *)authorization
  191. {
  192. // NSString *result = @"asura77:1f6bafe0801d52b557fc7b5277cb878bc36e54987b6eec036e713b1229096117";
  193. NSString *result = nil;
  194. if(_memberId !=nil && _authToken != nil)
  195. {
  196. result= [[NSString stringWithFormat:@"%@:%@", _memberId, _authToken] base64Enc];
  197. }
  198. return result;
  199. }
  200. #pragma mark - about Location Settings
  201. //로컬 저장소
  202. - (NSMutableDictionary *)localStorage {
  203. if (!self.memberId)
  204. return nil;
  205. if (!_localStorage) {
  206. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  207. _localStorage = [[JDFacade facade] objectForKeyFromUserDefaults:encryptedKey];
  208. if (!_localStorage) {//저장된 정보가 없을 경우,
  209. _localStorage = [[NSMutableDictionary alloc] init];
  210. }
  211. }
  212. return _localStorage;
  213. }
  214. - (void)synchronizeLocalStorage {
  215. if (!self.memberId)
  216. return;
  217. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  218. [[JDFacade facade] storeObjectToUserDefaults:self.localStorage forKey:encryptedKey];
  219. }
  220. @end