LoginModel.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 QuizModel
  18. -(BOOL)isUserEditQuiz
  19. {
  20. BOOL result = NO;
  21. if ([_statusCode isEquestToIgnoreCase:@"1"]) {
  22. result = YES;
  23. }
  24. return result;
  25. }
  26. @end
  27. @implementation QuizListModel
  28. @end
  29. @implementation HomeMemberModel
  30. @end
  31. @implementation HomeMemberListModel
  32. @end
  33. @implementation MemberIconModel
  34. @end
  35. @implementation MemberIconListModel
  36. @end
  37. @implementation MobileDeviceListModel
  38. @end
  39. @implementation LoginModel
  40. @synthesize memberId = _memberId, homegrpId = _homegrpId, newEmailId = _newEmailId, modeChange = _modeChange, noticeReadTime = _noticeReadTime, personalNoticeReadTime = _personalNoticeReadTime;
  41. //+ (JSONKeyMapper *)keyMapper {
  42. //
  43. // NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
  44. //
  45. // //Self
  46. // [dictionary setValue:@"lang" forKey:@"lang"];
  47. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  48. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  49. //
  50. // [dictionary setValue:@"lang" forKey:@"lang"];
  51. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  52. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  53. // [dictionary setValue:@"member" forKey:@"member"];
  54. // [dictionary setValue:@"timezoneId" forKey:@"timezone_id"];
  55. // [dictionary setValue:@"timezone" forKey:@"timezone"];
  56. // [dictionary setValue:@"countryCode" forKey:@"country_code"];
  57. // [dictionary setValue:@"memberId" forKey:@"member_id"];
  58. // [dictionary setValue:@"serviceId" forKey:@"service_id"];
  59. // [dictionary setValue:@"imageFileName" forKey:@"image_file_name"];
  60. // [dictionary setValue:@"nickname" forKey:@"nickname"];
  61. // [dictionary setValue:@"key" forKey:@"key"];
  62. // [dictionary setValue:@"homegrpId" forKey:@"homegrp_id"];
  63. // [dictionary setValue:@"homegrpList" forKey:@"homegrp_list"];
  64. //
  65. // return [[JSONKeyMapper alloc] initWithDictionary:dictionary];
  66. //}
  67. - (void)setSelectedHomeHubID:(NSString *)selectedHomeHubID{
  68. // TODO : 홈허브를 선택했을 경우 저장하는 기능 구현
  69. if([self isExistHomeHubID:selectedHomeHubID])
  70. {
  71. _selectedHomeHubID = selectedHomeHubID;
  72. }
  73. }
  74. - (NSString *)getSelectedHomeHubID {
  75. // TODO : 홈허브 아이디를 선택했을 경우 저장된 홈허브 아이디를 가져오는 기능
  76. return _selectedHomeHubID;
  77. }
  78. - (BOOL)isExistHomeHubID:(NSString *)homeHubID {
  79. BOOL result = false;
  80. for (DeviceModel *info in _deviceList) {
  81. if([info.deviceId isEquestToIgnoreCase:homeHubID]) {
  82. result = true;
  83. }
  84. }
  85. return result;
  86. }
  87. - (BOOL)isMultiHomeHub {
  88. BOOL result = false;
  89. if (_deviceList.count > 1) {
  90. result = true;
  91. }
  92. return result;
  93. }
  94. - (void)setMemberId:(NSString *)memberId {
  95. _memberId = memberId;
  96. //사용자 아이디 리스트
  97. NSMutableArray *userList = [[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_USERID_LIST];
  98. BOOL isExist = NO;
  99. if (!userList) {
  100. userList = [[NSMutableArray alloc] init];
  101. } else {
  102. for (NSString *memberId in userList) {
  103. isExist = [_memberId isEqualToString:memberId];
  104. if (isExist) {
  105. break;
  106. }
  107. }
  108. }
  109. if (!isExist) {//기존에 없으면 추가함.
  110. [userList addObject:_memberId];
  111. }
  112. [[JDFacade facade] storeObjectToUserDefaults:userList forKey:USDEF_APP_USERID_LIST];
  113. }
  114. - (NSString *)emailId {
  115. if (!_emailId || [_emailId isEmptyString]) {
  116. _emailId = [JDFacade facade].tmpEmailId;
  117. }
  118. return _emailId;
  119. }
  120. //새 이메일 변경 시 - 체크를 위한 로컬 저장
  121. - (NSString *)newEmailId {
  122. if (!_newEmailId) {
  123. _newEmailId = [self.localStorage objectForKey:USDEF_SESSION_NEW_EMAIL];
  124. }
  125. return _newEmailId ? _newEmailId : nil;
  126. }
  127. - (void)setNewEmailId:(NSString *)newEmailId {
  128. _newEmailId = newEmailId;
  129. //로컬 저장소에 저장
  130. [self.localStorage setObject:_newEmailId forKey:USDEF_SESSION_NEW_EMAIL];
  131. [self synchronizeLocalStorage];
  132. }
  133. //모드 변경 저장
  134. - (NSString *)modeChange {
  135. if (!_modeChange) {
  136. _modeChange = [self.localStorage objectForKey:USDEF_SESSION_MODE_CHANGE];
  137. }
  138. return _modeChange ? _modeChange : nil;
  139. }
  140. - (void)setModeChange:(NSString *)modeChange {
  141. _modeChange = modeChange;
  142. //로컬 저장소에 저장
  143. [self.localStorage setObject:_modeChange forKey:USDEF_SESSION_MODE_CHANGE];
  144. [self synchronizeLocalStorage];
  145. }
  146. //세션 - 공지 읽음 날짜 확인
  147. - (NSString *)noticeReadTime {
  148. if (!_noticeReadTime) {
  149. _noticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_NOTICE_READ_DATE];
  150. }
  151. return _noticeReadTime ? _noticeReadTime : nil;
  152. }
  153. - (void)setNoticeReadTime:(NSString *)noticeReadTime {
  154. _noticeReadTime = noticeReadTime;
  155. //로컬 저장소에 저장
  156. [self.localStorage setObject:_noticeReadTime forKey:USDEF_SESSION_NOTICE_READ_DATE];
  157. [self synchronizeLocalStorage];
  158. }
  159. //세션 - 알림 읽음 날짜 확인
  160. - (NSString *)personalNoticeReadTime {
  161. if (!_personalNoticeReadTime) {
  162. _personalNoticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_PUSH_READ_DATE];
  163. }
  164. return _personalNoticeReadTime ? _personalNoticeReadTime : nil;
  165. }
  166. - (void)setPersonalNoticeReadTime:(NSString *)personalNoticeReadTime {
  167. _personalNoticeReadTime = personalNoticeReadTime;
  168. //로컬 저장소에 저장
  169. [self.localStorage setObject:_personalNoticeReadTime forKey:USDEF_SESSION_PUSH_READ_DATE];
  170. [self synchronizeLocalStorage];
  171. }
  172. - (NSInteger)level {
  173. _level = 0;
  174. if ([_gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  175. _level = 90;
  176. } else if ([_gradeCode isEqualToString:KNEET_MEMBER_SIMPLE]) {
  177. _level = 10;
  178. }
  179. return _level;
  180. }
  181. // TODO: 홈그룹 온라인 / 보유 여부 로직 변경하기
  182. - (BOOL)isHomehubOnline {
  183. BOOL result = NO;
  184. for (DeviceModel *deviceInfo in _deviceList) {
  185. NSLog(@"Device Info : %@", deviceInfo);
  186. if (deviceInfo.isDeviceOnlined && deviceInfo.isDeviceConn) {
  187. result = YES;
  188. break;
  189. }
  190. }
  191. NSLog(@"HomeHub Online : %@", BOOLToString(result));
  192. return result;
  193. }
  194. - (BOOL)hasHomeHub {
  195. BOOL result = NO;
  196. for (DeviceModel *deviceInfo in _deviceList) {
  197. if (deviceInfo.deviceId && ![deviceInfo.deviceId isEmptyString]) {
  198. result = YES;
  199. break;
  200. }
  201. }
  202. return result;
  203. }
  204. -(NSString *)authorization
  205. {
  206. // NSString *result = @"asura77:1f6bafe0801d52b557fc7b5277cb878bc36e54987b6eec036e713b1229096117";
  207. NSString *result = nil;
  208. if(_memberId !=nil && _authToken != nil)
  209. {
  210. result= [[NSString stringWithFormat:@"%@:%@", _memberId, _authToken] base64Enc];
  211. }
  212. return result;
  213. }
  214. #pragma mark - about Location Settings
  215. //로컬 저장소
  216. - (NSMutableDictionary *)localStorage {
  217. if (!self.memberId)
  218. return nil;
  219. if (!_localStorage) {
  220. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  221. _localStorage = [[JDFacade facade] objectForKeyFromUserDefaults:encryptedKey];
  222. if (!_localStorage) {//저장된 정보가 없을 경우,
  223. _localStorage = [[NSMutableDictionary alloc] init];
  224. }
  225. }
  226. return _localStorage;
  227. }
  228. - (void)synchronizeLocalStorage {
  229. if (!self.memberId)
  230. return;
  231. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  232. [[JDFacade facade] storeObjectToUserDefaults:self.localStorage forKey:encryptedKey];
  233. }
  234. @end