LoginModel.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 HomeGroupModel
  12. - (CLLocationCoordinate2D)coordinate {
  13. CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(0, 0);
  14. if (_locationCoordinate && ![_locationCoordinate isEmptyString]) {
  15. NSArray *geos = [_locationCoordinate componentsSeparatedByString:@","];
  16. coordinate.latitude = [geos[0] doubleValue];
  17. coordinate.longitude = [geos[1] doubleValue];
  18. }
  19. return coordinate;
  20. }
  21. - (NSInteger)level {
  22. _level = 0;
  23. if ([_gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  24. _level = 90;
  25. } else if ([_gradeCode isEqualToString:KNEET_MEMBER_POWER]) {
  26. _level = 80;
  27. } else if ([_gradeCode isEqualToString:KNEET_MEMBER_SIMPLE]) {
  28. _level = 10;
  29. }
  30. return _level;
  31. }
  32. @end
  33. @implementation HomeGroupListModel
  34. @end
  35. @implementation InvitationModel
  36. @end
  37. @implementation HomeMemberModel
  38. @end
  39. @implementation HomeMemberListModel
  40. @end
  41. @implementation MemberIconModel
  42. @end
  43. @implementation MemberIconListModel
  44. @end
  45. @implementation MobileDeviceListModel
  46. @end
  47. @implementation LoginModel
  48. @synthesize memberId = _memberId, mobileDeviceId = _mobileDeviceId, mobileDeviceAuthorization = _mobileDeviceAuthorization, homegrpId = _homegrpId, newEmailId = _newEmailId, modeChange = _modeChange;
  49. //+ (JSONKeyMapper *)keyMapper {
  50. //
  51. // NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
  52. //
  53. // //Self
  54. // [dictionary setValue:@"lang" forKey:@"lang"];
  55. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  56. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  57. //
  58. // [dictionary setValue:@"lang" forKey:@"lang"];
  59. // [dictionary setValue:@"emailId" forKey:@"email_id"];
  60. // [dictionary setValue:@"authToken" forKey:@"auth_token"];
  61. // [dictionary setValue:@"member" forKey:@"member"];
  62. // [dictionary setValue:@"timezoneId" forKey:@"timezone_id"];
  63. // [dictionary setValue:@"timezone" forKey:@"timezone"];
  64. // [dictionary setValue:@"countryCode" forKey:@"country_code"];
  65. // [dictionary setValue:@"memberId" forKey:@"member_id"];
  66. // [dictionary setValue:@"serviceId" forKey:@"service_id"];
  67. // [dictionary setValue:@"imageFileName" forKey:@"image_file_name"];
  68. // [dictionary setValue:@"nickname" forKey:@"nickname"];
  69. // [dictionary setValue:@"key" forKey:@"key"];
  70. // [dictionary setValue:@"homegrpId" forKey:@"homegrp_id"];
  71. // [dictionary setValue:@"homegrpList" forKey:@"homegrp_list"];
  72. //
  73. // return [[JSONKeyMapper alloc] initWithDictionary:dictionary];
  74. //}
  75. - (void)setMemberId:(NSString *)memberId {
  76. _memberId = memberId;
  77. //사용자 아이디 리스트
  78. NSMutableArray *userList = [[JDFacade facade] objectForKeyFromUserDefaults:USER_DEF_USERID_LIST];
  79. BOOL isExist = NO;
  80. if (!userList) {
  81. userList = [[NSMutableArray alloc] init];
  82. } else {
  83. for (NSString *memberId in userList) {
  84. isExist = [_memberId isEqualToString:memberId];
  85. if (isExist) {
  86. break;
  87. }
  88. }
  89. }
  90. if (!isExist) {//기존에 없으면 추가함.
  91. [userList addObject:_memberId];
  92. }
  93. [[JDFacade facade] storeObjectToUserDefaults:userList forKey:USER_DEF_USERID_LIST];
  94. }
  95. - (NSString *)emailId {
  96. if (!_emailId || [_emailId isEmptyString]) {
  97. _emailId = [JDFacade facade].tmpEmailId;
  98. }
  99. return _emailId;
  100. }
  101. #pragma mark - HomeGrp
  102. - (NSString *)homegrpId {
  103. if (!_homegrpId) {
  104. _homegrpId = [self.localStorage objectForKey:USER_DEF_HOMEGRP_ID];
  105. }
  106. return _homegrpId ? _homegrpId : nil;
  107. }
  108. - (void)setHomegrpId:(NSString *)homegrpId {
  109. _homegrpId = homegrpId;
  110. //로컬 저장소에 저장
  111. [self.localStorage setObject:_homegrpId forKey:USER_DEF_HOMEGRP_ID];
  112. [self synchronizeLocalStorage];
  113. }
  114. - (NSString *)newEmailId {
  115. if (!_newEmailId) {
  116. _newEmailId = [self.localStorage objectForKey:USER_DEF_NEW_EMAIL];
  117. }
  118. return _newEmailId ? _newEmailId : nil;
  119. }
  120. - (void)setNewEmailId:(NSString *)newEmailId {
  121. _newEmailId = newEmailId;
  122. //로컬 저장소에 저장
  123. [self.localStorage setObject:_newEmailId forKey:USER_DEF_NEW_EMAIL];
  124. [self synchronizeLocalStorage];
  125. }
  126. - (NSString *)modeChange {
  127. if (!_modeChange) {
  128. _modeChange = [self.localStorage objectForKey:USER_DEF_MODE_CHANGE];
  129. }
  130. return _modeChange ? _modeChange : nil;
  131. }
  132. - (void)setModeChange:(NSString *)modeChange {
  133. _modeChange = modeChange;
  134. //로컬 저장소에 저장
  135. [self.localStorage setObject:_modeChange forKey:USER_DEF_MODE_CHANGE];
  136. [self synchronizeLocalStorage];
  137. }
  138. #pragma mark - about Location Settings
  139. //로컬 저장소
  140. - (NSMutableDictionary *)localStorage {
  141. if (!self.memberId)
  142. return nil;
  143. if (!_localStorage) {
  144. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  145. _localStorage = [[JDFacade facade] objectForKeyFromUserDefaults:encryptedKey];
  146. if (!_localStorage) {//저장된 정보가 없을 경우,
  147. _localStorage = [[NSMutableDictionary alloc] init];
  148. }
  149. }
  150. return _localStorage;
  151. }
  152. - (void)synchronizeLocalStorage {
  153. if (!self.memberId)
  154. return;
  155. NSString *encryptedKey = [CypherUtil AES128Encrypt:self.memberId WithKey:self.memberId];
  156. [[JDFacade facade] storeObjectToUserDefaults:self.localStorage forKey:encryptedKey];
  157. }
  158. - (void)addHomegrp:(HomeGroupModel *)homegrp {
  159. if (!self.homegrpList) {
  160. self.homegrpList = (NSMutableArray<HomeGroupModel> *)[[NSMutableArray alloc] init];
  161. }
  162. for (HomeGroupModel *lhomegrp in self.homegrpList) {
  163. [[JDFacade facade] setRadioButtonStatus:@NO object:lhomegrp];
  164. }
  165. [self.homegrpList insertObject:homegrp atIndex:0];
  166. [JDFacade facade].loginHomeGroup = homegrp;
  167. }
  168. @end