LoginModel.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 SignUpModel
  49. @end
  50. @implementation FindIdPwModel
  51. @end
  52. @implementation LoginModel
  53. @synthesize memberId = _memberId, homegrpId = _homegrpId, newEmailId = _newEmailId, modeChange = _modeChange, noticeReadTime = _noticeReadTime, personalNoticeReadTime = _personalNoticeReadTime;
  54. //+ (JSONKeyMapper *)keyMapper {
  55. //
  56. // NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
  57. //
  58. // //Self
  59. // [dictionary setValue:@"lang" forKey:@"lang"];
  60. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  61. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  62. //
  63. // [dictionary setValue:@"lang" forKey:@"lang"];
  64. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  65. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  66. // [dictionary setValue:@"member" forKey:@"member"];
  67. // [dictionary setValue:@"timezoneId" forKey:@"timezone_id"];
  68. // [dictionary setValue:@"timezone" forKey:@"timezone"];
  69. // [dictionary setValue:@"countryCode" forKey:@"country_code"];
  70. // [dictionary setValue:@"memberId" forKey:@"member_id"];
  71. // [dictionary setValue:@"serviceId" forKey:@"service_id"];
  72. // [dictionary setValue:@"imageFileName" forKey:@"image_file_name"];
  73. // [dictionary setValue:@"nickname" forKey:@"nickname"];
  74. // [dictionary setValue:@"key" forKey:@"key"];
  75. // [dictionary setValue:@"homegrpId" forKey:@"homegrp_id"];
  76. // [dictionary setValue:@"homegrpList" forKey:@"homegrp_list"];
  77. //
  78. // return [[JSONKeyMapper alloc] initWithDictionary:dictionary];
  79. //}
  80. - (void)setSelectedHomeHubID:(NSString *)selectedHomeHubID{
  81. // TODO : 홈허브를 선택했을 경우 저장하는 기능 구현
  82. if([self isExistHomeHubID:selectedHomeHubID])
  83. {
  84. _selectedHomeHubID = selectedHomeHubID;
  85. }
  86. }
  87. - (NSString *)getSelectedHomeHubID {
  88. // TODO : 홈허브 아이디를 선택했을 경우 저장된 홈허브 아이디를 가져오는 기능
  89. return _selectedHomeHubID;
  90. }
  91. -(void)setHomeHubID:(NSString *)homeHubID {
  92. if([self isExistHomeHubID:homeHubID])
  93. {
  94. if (![_selectedHomeHubID isEqualToString:homeHubID]) {
  95. _selectedHomeHubID = homeHubID;
  96. }
  97. }
  98. }
  99. -(NSString *)getHomeHubID {
  100. NSString *result = @"";
  101. DeviceModel *info = [self getHomeHub];
  102. if (info != nil) {
  103. result = info.deviceId;
  104. }
  105. return result;
  106. }
  107. -(DeviceModel *)getHomeHub:(NSString*)homeHubId {
  108. DeviceModel *result = nil;
  109. for (DeviceModel *info in _deviceList) {
  110. if ([info.deviceId isEquestToIgnoreCase:homeHubId]) {
  111. result = info;
  112. break;
  113. }
  114. }
  115. return result;
  116. }
  117. -(DeviceModel *)getHomeHub {
  118. DeviceModel *result = nil;
  119. if (![self isMultiHomeHub]) {
  120. for (DeviceModel *info in _deviceList) {
  121. result = info;
  122. break;
  123. }
  124. // if (_selectedHomeHubID == nil || [_selectedHomeHubID isEmptyString]) {
  125. // for (DeviceModel *info in _deviceList) {
  126. // result = info;
  127. // break;
  128. // }
  129. // }
  130. } else {
  131. for (DeviceModel *info in _deviceList) {
  132. if ([info.deviceId isEquestToIgnoreCase:_selectedHomeHubID]) {
  133. result = info;
  134. break;
  135. }
  136. }
  137. }
  138. return result;
  139. }
  140. - (BOOL)isExistHomeHubID:(NSString *)homeHubID {
  141. BOOL result = false;
  142. for (DeviceModel *info in _deviceList) {
  143. if([info.deviceId isEquestToIgnoreCase:homeHubID]) {
  144. result = true;
  145. }
  146. }
  147. return result;
  148. }
  149. - (BOOL)isMultiHomeHub {
  150. BOOL result = false;
  151. if (_deviceList.count > 1) {
  152. result = true;
  153. }
  154. return result;
  155. }
  156. - (BOOL)onlineHomeHubFromSelectedHub:(DeviceModel*)selectedHub {
  157. BOOL result = false;
  158. //멀티인경우
  159. if (_deviceList.count > 1) {
  160. for (DeviceModel *device in _deviceList) {
  161. if (selectedHub != nil) {
  162. if (EQUALS(selectedHub.deviceId, device.deviceId))
  163. return device.isDeviceOnlined;
  164. }
  165. else {
  166. if (device.isDeviceOnlined)
  167. return true;
  168. }
  169. }
  170. }
  171. //단일인 경우
  172. else {
  173. return [self getHomeHub].isDeviceOnlined;
  174. }
  175. return result;
  176. }
  177. - (BOOL)connectedHomeHubFromSelectedHub:(DeviceModel*)selectedHub {
  178. BOOL result = false;
  179. //멀티인경우
  180. if (_deviceList.count > 1) {
  181. for (DeviceModel *device in _deviceList) {
  182. if (selectedHub != nil) {
  183. if (EQUALS(selectedHub.deviceId, device.deviceId))
  184. return device.isDeviceConn;
  185. }
  186. else {
  187. if (device.isDeviceConn)
  188. return true;
  189. }
  190. }
  191. }
  192. //단일인 경우
  193. else {
  194. return [self getHomeHub].isDeviceConn;
  195. }
  196. return result;
  197. }
  198. - (void)setMemberId:(NSString *)memberId {
  199. _memberId = memberId;
  200. //사용자 아이디 리스트
  201. NSMutableArray *userList = [[JDFacade facade] objectForKeyFromUserDefaults:USDEF_APP_USERID_LIST];
  202. BOOL isExist = NO;
  203. if (!userList) {
  204. userList = [[NSMutableArray alloc] init];
  205. } else {
  206. for (NSString *memberId in userList) {
  207. isExist = [_memberId isEqualToString:memberId];
  208. if (isExist) {
  209. break;
  210. }
  211. }
  212. }
  213. if (!isExist) {//기존에 없으면 추가함.
  214. [userList addObject:_memberId];
  215. }
  216. [[JDFacade facade] storeObjectToUserDefaults:userList forKey:USDEF_APP_USERID_LIST];
  217. }
  218. - (NSString *)emailId {
  219. if (!_emailId || [_emailId isEmptyString]) {
  220. _emailId = [JDFacade facade].tmpEmailId;
  221. }
  222. return _emailId;
  223. }
  224. //새 이메일 변경 시 - 체크를 위한 로컬 저장
  225. - (NSString *)newEmailId {
  226. if (!_newEmailId) {
  227. _newEmailId = [self.localStorage objectForKey:USDEF_SESSION_NEW_EMAIL];
  228. }
  229. return _newEmailId ? _newEmailId : nil;
  230. }
  231. - (void)setNewEmailId:(NSString *)newEmailId {
  232. _newEmailId = newEmailId;
  233. //로컬 저장소에 저장
  234. [self.localStorage setObject:_newEmailId forKey:USDEF_SESSION_NEW_EMAIL];
  235. [self synchronizeLocalStorage];
  236. }
  237. - (NSString *)ctrtGrpId {
  238. return [self ctrtGrp].ctrtGrpId;
  239. }
  240. - (ContractGroupModel *)ctrtGrp {
  241. ContractGroupModel *result = nil;
  242. if ([_selectCtrtGrpId isEmptyString]) {
  243. result = _ctrtGrpList[0];
  244. }
  245. else {
  246. for (ContractGroupModel *groupInfo in _ctrtGrpList) {
  247. if ([groupInfo.ctrtGrpId isEquestToIgnoreCase:_selectCtrtGrpId]) {
  248. result = groupInfo;
  249. }
  250. }
  251. }
  252. return result;
  253. }
  254. - (NSString *)gradeCode {
  255. return [self ctrtGrp].gradeCode;
  256. }
  257. //모드 변경 저장
  258. - (NSString *)modeChange {
  259. if (!_modeChange) {
  260. _modeChange = [self.localStorage objectForKey:USDEF_SESSION_MODE_CHANGE];
  261. }
  262. return _modeChange ? _modeChange : nil;
  263. }
  264. - (void)setModeChange:(NSString *)modeChange {
  265. _modeChange = modeChange;
  266. //로컬 저장소에 저장
  267. [self.localStorage setObject:_modeChange forKey:USDEF_SESSION_MODE_CHANGE];
  268. [self synchronizeLocalStorage];
  269. }
  270. //세션 - 공지 읽음 날짜 확인
  271. - (NSString *)noticeReadTime {
  272. if (!_noticeReadTime) {
  273. _noticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_NOTICE_READ_DATE];
  274. }
  275. return _noticeReadTime ? _noticeReadTime : nil;
  276. }
  277. - (void)setNoticeReadTime:(NSString *)noticeReadTime {
  278. _noticeReadTime = noticeReadTime;
  279. //로컬 저장소에 저장
  280. [self.localStorage setObject:_noticeReadTime forKey:USDEF_SESSION_NOTICE_READ_DATE];
  281. [self synchronizeLocalStorage];
  282. }
  283. //세션 - 알림 읽음 날짜 확인
  284. - (NSString *)personalNoticeReadTime {
  285. if (!_personalNoticeReadTime) {
  286. _personalNoticeReadTime = [self.localStorage objectForKey:USDEF_SESSION_PUSH_READ_DATE];
  287. }
  288. return _personalNoticeReadTime ? _personalNoticeReadTime : nil;
  289. }
  290. - (void)setPersonalNoticeReadTime:(NSString *)personalNoticeReadTime {
  291. _personalNoticeReadTime = personalNoticeReadTime;
  292. //로컬 저장소에 저장
  293. [self.localStorage setObject:_personalNoticeReadTime forKey:USDEF_SESSION_PUSH_READ_DATE];
  294. [self synchronizeLocalStorage];
  295. }
  296. - (NSInteger)level {
  297. _level = 0;
  298. if ([[self gradeCode] isEqualToString:KNEET_MEMBER_MASTER]) {
  299. _level = 90;
  300. } else if ([[self gradeCode] isEqualToString:KNEET_MEMBER_SIMPLE]) {
  301. _level = 10;
  302. }
  303. return _level;
  304. }
  305. // TODO: 홈그룹 온라인 / 보유 여부 로직 변경하기
  306. - (BOOL)isHomehubOnline {
  307. BOOL result = YES;
  308. // for (DeviceModel *deviceInfo in _deviceList) {
  309. // NSLog(@"Device Info : %@", deviceInfo);
  310. // if (deviceInfo.isDeviceOnlined && deviceInfo.isDeviceConn) {
  311. // result = YES;
  312. // break;
  313. // }
  314. // }
  315. return result;
  316. }
  317. - (BOOL)hasHomeHub {
  318. BOOL result = YES;
  319. // for (DeviceModel *deviceInfo in _deviceList) {
  320. // if (deviceInfo.deviceId && ![deviceInfo.deviceId isEmptyString]) {
  321. // result = YES;
  322. // break;
  323. // }
  324. // }
  325. return result;
  326. }
  327. -(NSString *)authorization
  328. {
  329. // NSString *result = @"asura77:1f6bafe0801d52b557fc7b5277cb878bc36e54987b6eec036e713b1229096117";
  330. NSString *result = nil;
  331. if(_memberId !=nil && _authToken != nil)
  332. {
  333. result= [[NSString stringWithFormat:@"%@:%@", _memberId, _authToken] base64Enc];
  334. }
  335. return result;
  336. }
  337. #pragma mark - about Location Settings
  338. //로컬 저장소
  339. - (NSMutableDictionary *)localStorage {
  340. if (!self.memberId)
  341. return nil;
  342. if (!_localStorage) {
  343. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  344. _localStorage = [[JDFacade facade] objectForKeyFromUserDefaults:encryptedKey];
  345. if (!_localStorage) {//저장된 정보가 없을 경우,
  346. _localStorage = [[NSMutableDictionary alloc] init];
  347. }
  348. }
  349. return _localStorage;
  350. }
  351. - (void)synchronizeLocalStorage {
  352. if (!self.memberId)
  353. return;
  354. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  355. [[JDFacade facade] storeObjectToUserDefaults:self.localStorage forKey:encryptedKey];
  356. }
  357. @end