LoginModel.m 8.5 KB

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