| Line 156... |
Line 156... |
| 156 |
}
|
156 |
}
|
| 157 |
if (user != null) {
|
157 |
if (user != null) {
|
| 158 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
158 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 159 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
159 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 160 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
160 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| 161 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
161 |
List<RoleType> roleTypes = userRoleRepository.selectRoleTypesByUserId(user.getId());
|
| 162 |
LOGGER.info("userRoles {} ", userRoles);
|
162 |
//LOGGER.info("userRoles {} ", userRoles);
|
| 163 |
String[] roleTypes = new String[userRoles.size()];
|
- |
|
| 164 |
|
163 |
|
| 165 |
// generate new token if roles have been updated
|
164 |
// generate new token if roles have been updated
|
| 166 |
if (userInfo.getRoleNames() == null || userRoles.size() != userInfo.getRoleNames().size()) {
|
165 |
if (userInfo.getRoleNames() == null || roleTypes.size() != userInfo.getRoleNames().size()) {
|
| 167 |
// String[] roleTypes = new String[userRoles.size()];
|
- |
|
| 168 |
int index = 0;
|
- |
|
| 169 |
for (UserRole userRole : userRoles) {
|
- |
|
| 170 |
roleTypes[index++] = userRole.getRoleType().toString();
|
- |
|
| 171 |
}
|
- |
|
| 172 |
String newToken = JWTUtil.create(user.getId(), roleTypes);
|
166 |
String newToken = JWTUtil.create(user.getId(), roleTypes.stream().toArray(String[]::new));
|
| 173 |
responseMap.put("newAuthToken", newToken);
|
167 |
responseMap.put("newAuthToken", newToken);
|
| 174 |
}
|
168 |
}
|
| 175 |
|
169 |
|
| 176 |
// if user is retailer
|
170 |
// if user is retailer
|
| 177 |
if (userRoles.stream().anyMatch(new Predicate<UserRole>() {
|
- |
|
| 178 |
@Override
|
- |
|
| 179 |
public boolean test(UserRole t) {
|
- |
|
| 180 |
return t.getRoleType() == RoleType.RETAILER;
|
171 |
if (roleTypes.contains(RoleType.RETAILER)) {
|
| 181 |
}
|
- |
|
| 182 |
})) {
|
- |
|
| 183 |
|
- |
|
| 184 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
172 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 185 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
173 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
| 186 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
174 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
| 187 |
if(saholicUser.getAddressId() != null){
|
175 |
if(saholicUser.getAddressId() != null){
|
| 188 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
176 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
| Line 191... |
Line 179... |
| 191 |
// if retailer is activated 1 then verified retailer
|
179 |
// if retailer is activated 1 then verified retailer
|
| 192 |
// else if migrated is 1 then old retailer
|
180 |
// else if migrated is 1 then old retailer
|
| 193 |
// also lets incoporte old process i.e is user is activated then also retailer is verified retailer
|
181 |
// also lets incoporte old process i.e is user is activated then also retailer is verified retailer
|
| 194 |
// else retailer is not verifed
|
182 |
// else retailer is not verifed
|
| 195 |
if (retailer.isActive() || user.isActivated()) {
|
183 |
if (retailer.isActive() || user.isActivated()) {
|
| 196 |
if (retailer.isFofo()) {
|
184 |
if (roleTypes.contains(RoleType.FOFO)) {
|
| 197 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
|
185 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
|
| 198 |
} else {
|
186 |
} else {
|
| 199 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
187 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
| 200 |
}
|
188 |
}
|
| 201 |
} else if (retailer.isMigrated()) {
|
189 |
} else if (retailer.isMigrated()) {
|
| 202 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
190 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
| 203 |
} else {
|
191 |
} else {
|
| 204 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
192 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
| 205 |
}
|
193 |
}
|
| 206 |
} else if (userRoles.stream().anyMatch(new Predicate<UserRole>() {
|
- |
|
| 207 |
@Override
|
- |
|
| 208 |
public boolean test(UserRole t) {
|
- |
|
| 209 |
return t.getRoleType() == RoleType.USER;
|
194 |
} else if (roleTypes.contains(RoleType.USER)) {
|
| 210 |
}
|
- |
|
| 211 |
})) {
|
- |
|
| 212 |
responseMap.put("userInfo", getRegisteredUserInfo(user));
|
195 |
responseMap.put("userInfo", getRegisteredUserInfo(user));
|
| 213 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
196 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
| 214 |
}
|
197 |
}
|
| 215 |
} else {
|
198 |
} else {
|
| 216 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
199 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|