| 21248 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 21428 |
amit.gupta |
4 |
import java.util.HashMap;
|
| 21277 |
ashik.ali |
5 |
import java.util.Map;
|
| 21428 |
amit.gupta |
6 |
import java.util.Set;
|
| 21469 |
amit.gupta |
7 |
import java.util.function.Predicate;
|
| 21248 |
ashik.ali |
8 |
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
|
|
11 |
import org.slf4j.Logger;
|
|
|
12 |
import org.slf4j.LoggerFactory;
|
| 21278 |
ashik.ali |
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21414 |
kshitij.so |
14 |
import org.springframework.beans.factory.annotation.Value;
|
| 21248 |
ashik.ali |
15 |
import org.springframework.http.HttpStatus;
|
|
|
16 |
import org.springframework.http.ResponseEntity;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
| 21366 |
kshitij.so |
18 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21248 |
ashik.ali |
19 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
22 |
|
|
|
23 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21469 |
amit.gupta |
26 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21282 |
ashik.ali |
27 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 21426 |
ashik.ali |
28 |
import com.spice.profitmandi.dao.entity.Permission;
|
| 21485 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.entity.Retailer;
|
| 21414 |
kshitij.so |
30 |
import com.spice.profitmandi.dao.entity.Role;
|
| 21278 |
ashik.ali |
31 |
import com.spice.profitmandi.dao.entity.User;
|
| 21426 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.entity.UserRole;
|
| 21469 |
amit.gupta |
33 |
import com.spice.profitmandi.dao.enumuration.RoleType;
|
| 21426 |
ashik.ali |
34 |
import com.spice.profitmandi.dao.repository.PermissionRepository;
|
| 21485 |
amit.gupta |
35 |
import com.spice.profitmandi.dao.repository.RetailerRepository;
|
| 21426 |
ashik.ali |
36 |
import com.spice.profitmandi.dao.repository.RoleRepository;
|
| 21485 |
amit.gupta |
37 |
import com.spice.profitmandi.dao.repository.UserAccountRepository;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.UserCart;
|
| 21248 |
ashik.ali |
39 |
import com.spice.profitmandi.dao.repository.UserRepository;
|
| 21426 |
ashik.ali |
40 |
import com.spice.profitmandi.dao.repository.UserRoleRepository;
|
| 21487 |
ashik.ali |
41 |
import com.spice.profitmandi.dao.util.UserToRetailerMigrationUtil;
|
| 21469 |
amit.gupta |
42 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 21248 |
ashik.ali |
43 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
|
|
44 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
| 21277 |
ashik.ali |
45 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 21426 |
ashik.ali |
46 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
| 21366 |
kshitij.so |
47 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 21448 |
ashik.ali |
48 |
import com.spice.profitmandi.web.util.ResponseSender;
|
| 21248 |
ashik.ali |
49 |
|
| 21469 |
amit.gupta |
50 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
51 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
52 |
|
| 21248 |
ashik.ali |
53 |
/**
|
|
|
54 |
* @author ashikali
|
|
|
55 |
*
|
|
|
56 |
*/
|
|
|
57 |
@Controller
|
|
|
58 |
public class UserController {
|
| 21469 |
amit.gupta |
59 |
|
| 21448 |
ashik.ali |
60 |
@Autowired
|
|
|
61 |
ResponseSender<?> responseSender;
|
| 21469 |
amit.gupta |
62 |
|
|
|
63 |
private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
|
|
|
64 |
|
| 21414 |
kshitij.so |
65 |
@Value("${admin.token}")
|
|
|
66 |
private String validAdminToken;
|
| 21469 |
amit.gupta |
67 |
|
| 21278 |
ashik.ali |
68 |
@Autowired
|
|
|
69 |
UserRepository userRepository;
|
| 21469 |
amit.gupta |
70 |
|
| 21278 |
ashik.ali |
71 |
@Autowired
|
| 21485 |
amit.gupta |
72 |
RetailerRepository retailerRepository;
|
|
|
73 |
|
|
|
74 |
@Autowired
|
| 21426 |
ashik.ali |
75 |
RoleRepository roleRepository;
|
| 21469 |
amit.gupta |
76 |
|
| 21426 |
ashik.ali |
77 |
@Autowired
|
|
|
78 |
UserRoleRepository userRoleRepository;
|
| 21469 |
amit.gupta |
79 |
|
| 21426 |
ashik.ali |
80 |
@Autowired
|
| 21485 |
amit.gupta |
81 |
UserAccountRepository userAccountRepository;
|
|
|
82 |
|
|
|
83 |
@Autowired
|
| 21426 |
ashik.ali |
84 |
PermissionRepository permissionRepository;
|
| 21469 |
amit.gupta |
85 |
|
| 21426 |
ashik.ali |
86 |
@Autowired
|
| 21278 |
ashik.ali |
87 |
GoogleLoginProcessor googleLoginProcessor;
|
| 21487 |
ashik.ali |
88 |
|
|
|
89 |
@Autowired
|
|
|
90 |
UserToRetailerMigrationUtil userToRetailerMigrationUtil;
|
| 21469 |
amit.gupta |
91 |
|
| 21277 |
ashik.ali |
92 |
@SuppressWarnings("unchecked")
|
| 21469 |
amit.gupta |
93 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
|
|
|
94 |
public ResponseEntity<?> googleLogin(HttpServletRequest request) {
|
|
|
95 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
96 |
final Map<String, Object> googleLoginMap = (Map<String, Object>) request
|
|
|
97 |
.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
| 21277 |
ashik.ali |
98 |
request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
|
|
99 |
try {
|
| 21448 |
ashik.ali |
100 |
return responseSender.ok(googleLoginProcessor.process(googleLoginMap));
|
| 21469 |
amit.gupta |
101 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
102 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
103 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21277 |
ashik.ali |
104 |
}
|
|
|
105 |
}
|
| 21469 |
amit.gupta |
106 |
|
|
|
107 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
|
|
|
108 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token) {
|
|
|
109 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21282 |
ashik.ali |
110 |
try {
|
| 21448 |
ashik.ali |
111 |
return responseSender.ok(JWTUtil.isExpired(token));
|
| 21469 |
amit.gupta |
112 |
|
|
|
113 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
114 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
115 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21282 |
ashik.ali |
116 |
}
|
|
|
117 |
}
|
| 21469 |
amit.gupta |
118 |
|
|
|
119 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_INFO, method = RequestMethod.GET)
|
|
|
120 |
@ApiImplicitParams({
|
|
|
121 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
122 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
|
|
123 |
Map<String, Object> responseMap = new HashMap<>();
|
|
|
124 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
125 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 21483 |
amit.gupta |
126 |
User user = null;
|
|
|
127 |
if(userInfo.getUserId()>-1){
|
|
|
128 |
user = userRepository.selectById(userInfo.getUserId());
|
|
|
129 |
} else {
|
|
|
130 |
try {
|
|
|
131 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
|
|
132 |
} catch (ProfitMandiBusinessException e1) {
|
|
|
133 |
LOGGER.info("Uneregistered user");
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
if (user != null) {
|
| 21491 |
amit.gupta |
137 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 21483 |
amit.gupta |
138 |
|
|
|
139 |
Set<Role> roles = user.getRoles();
|
|
|
140 |
//generate new token if roles size is different
|
|
|
141 |
if(userInfo.getRoleNames() == null || roles.size() != userInfo.getRoleNames().size()) {
|
|
|
142 |
String[] roleTypes = new String[roles.size()];
|
|
|
143 |
int index = 0;
|
|
|
144 |
for (Role role : roles) {
|
|
|
145 |
roleTypes[index++] = role.getType().toString();
|
|
|
146 |
}
|
|
|
147 |
String newToken = JWTUtil.create(user.getId(), roleTypes);
|
|
|
148 |
responseMap.put("newAuthToken", newToken);
|
|
|
149 |
}
|
|
|
150 |
|
| 21469 |
amit.gupta |
151 |
// if user is retailer
|
|
|
152 |
if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
|
|
|
153 |
@Override
|
|
|
154 |
public boolean test(Role t) {
|
|
|
155 |
return t.getType().equals(RoleType.RETAILER);
|
|
|
156 |
}
|
|
|
157 |
})) {
|
| 21485 |
amit.gupta |
158 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
159 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
|
|
160 |
// if retailer is activated 1 then verified retailer
|
|
|
161 |
// else if migrated is 1 then old retailer
|
|
|
162 |
// else retailer is not verifed
|
|
|
163 |
if (retailer.isActive()) {
|
| 21469 |
amit.gupta |
164 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
| 21485 |
amit.gupta |
165 |
} else if (retailer.isMigrated()){
|
|
|
166 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
| 21469 |
amit.gupta |
167 |
} else {
|
| 21485 |
amit.gupta |
168 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
| 21469 |
amit.gupta |
169 |
}
|
|
|
170 |
} else if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
|
|
|
171 |
@Override
|
|
|
172 |
public boolean test(Role t) {
|
|
|
173 |
return t.getType().equals(RoleType.USER);
|
|
|
174 |
}
|
|
|
175 |
})) {
|
|
|
176 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
|
|
177 |
}
|
| 21491 |
amit.gupta |
178 |
} else {
|
|
|
179 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
|
|
180 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 21469 |
amit.gupta |
181 |
}
|
|
|
182 |
|
|
|
183 |
return responseSender.ok(responseMap);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
|
|
|
187 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest) {
|
|
|
188 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21368 |
kshitij.so |
189 |
User user = new User();
|
|
|
190 |
user.setFirstName(userRequest.getFirstName());
|
|
|
191 |
user.setLastName(userRequest.getLastName());
|
|
|
192 |
user.setCity(userRequest.getCity());
|
|
|
193 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
|
|
194 |
user.setEmailId(userRequest.getEmailId());
|
|
|
195 |
user.setUsername("");
|
|
|
196 |
user.setPassword("");
|
|
|
197 |
user.setMobile_verified(false);
|
|
|
198 |
user.setReferral_url("");
|
|
|
199 |
user.setGroup_id(1);
|
|
|
200 |
user.setStatus(0);
|
|
|
201 |
user.setActivated(false);
|
| 21414 |
kshitij.so |
202 |
|
| 21278 |
ashik.ali |
203 |
try {
|
|
|
204 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
205 |
user.setUpdateTimestamp(LocalDateTime.now());
|
|
|
206 |
userRepository.persist(user);
|
| 21448 |
ashik.ali |
207 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
| 21469 |
amit.gupta |
208 |
|
|
|
209 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
210 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
211 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21278 |
ashik.ali |
212 |
}
|
|
|
213 |
}
|
| 21469 |
amit.gupta |
214 |
|
|
|
215 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL, method = RequestMethod.GET)
|
| 21497 |
ashik.ali |
216 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) {
|
| 21469 |
amit.gupta |
217 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21497 |
ashik.ali |
218 |
return responseSender.ok(userRepository.selectAll(pageNumber, pageSize));
|
| 21248 |
ashik.ali |
219 |
}
|
| 21469 |
amit.gupta |
220 |
|
|
|
221 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
|
|
|
222 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
223 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
224 |
try {
|
| 21448 |
ashik.ali |
225 |
return responseSender.ok(userRepository.selectById(id));
|
| 21469 |
amit.gupta |
226 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
227 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
228 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
229 |
}
|
|
|
230 |
}
|
| 21469 |
amit.gupta |
231 |
|
|
|
232 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
|
|
|
233 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
|
|
|
234 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
235 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
236 |
try {
|
| 21448 |
ashik.ali |
237 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
| 21469 |
amit.gupta |
238 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
239 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
240 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
241 |
}
|
|
|
242 |
}
|
| 21469 |
amit.gupta |
243 |
|
| 21426 |
ashik.ali |
244 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
| 21469 |
amit.gupta |
245 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
|
|
|
246 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
247 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
248 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
| 21426 |
ashik.ali |
249 |
}
|
| 21469 |
amit.gupta |
250 |
|
|
|
251 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
|
|
|
252 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId) {
|
|
|
253 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
254 |
try {
|
| 21448 |
ashik.ali |
255 |
return responseSender.ok(userRepository.selectByEmailId(emailId));
|
| 21469 |
amit.gupta |
256 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
257 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
258 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
259 |
}
|
|
|
260 |
}
|
| 21469 |
amit.gupta |
261 |
|
|
|
262 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method = RequestMethod.POST)
|
|
|
263 |
public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest) {
|
|
|
264 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
265 |
try {
|
| 21426 |
ashik.ali |
266 |
User user = userRepository.selectById(userAddRoleRequest.getUserId());
|
| 21469 |
amit.gupta |
267 |
|
| 21426 |
ashik.ali |
268 |
Role role = null;
|
| 21469 |
amit.gupta |
269 |
try {
|
|
|
270 |
role = roleRepository.selectByNameAndType(userAddRoleRequest.getRole().getName(),
|
|
|
271 |
userAddRoleRequest.getRole().getType());
|
|
|
272 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 21426 |
ashik.ali |
273 |
role = new Role();
|
|
|
274 |
role.setName(userAddRoleRequest.getRole().getName());
|
|
|
275 |
role.setType(userAddRoleRequest.getRole().getType());
|
|
|
276 |
roleRepository.persist(role);
|
|
|
277 |
}
|
|
|
278 |
Permission permission = new Permission();
|
|
|
279 |
permission.setType(userAddRoleRequest.getRole().getPermissionType());
|
|
|
280 |
permission.setRoleId(role.getId());
|
|
|
281 |
permissionRepository.persist(permission);
|
|
|
282 |
UserRole userRole = new UserRole();
|
|
|
283 |
userRole.setRoleId(role.getId());
|
|
|
284 |
userRole.setUserId(user.getId());
|
|
|
285 |
userRoleRepository.persist(userRole);
|
| 21448 |
ashik.ali |
286 |
return responseSender.ok("");
|
| 21469 |
amit.gupta |
287 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
288 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
289 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
290 |
}
|
|
|
291 |
}
|
| 21469 |
amit.gupta |
292 |
|
|
|
293 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_REMOVE, method = RequestMethod.DELETE)
|
|
|
294 |
public ResponseEntity<?> removeRole(HttpServletRequest request, @RequestParam(name = "roleId") int roleId,
|
|
|
295 |
@RequestParam(name = "userId") int userId) {
|
|
|
296 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
297 |
try {
|
| 21426 |
ashik.ali |
298 |
roleRepository.selectById(roleId);
|
|
|
299 |
userRepository.selectById(userId);
|
|
|
300 |
userRoleRepository.deleteByUserAndRoleId(userId, roleId);
|
|
|
301 |
permissionRepository.deleteByRoleId(roleId);
|
| 21448 |
ashik.ali |
302 |
return responseSender.ok("");
|
| 21469 |
amit.gupta |
303 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
304 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
305 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
306 |
}
|
|
|
307 |
}
|
| 21469 |
amit.gupta |
308 |
|
|
|
309 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
|
|
310 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
311 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
312 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
| 21248 |
ashik.ali |
313 |
}
|
| 21414 |
kshitij.so |
314 |
|
|
|
315 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
| 21469 |
amit.gupta |
316 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request,
|
|
|
317 |
@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
|
|
|
318 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
319 |
if (!adminToken.equals(validAdminToken)) {
|
|
|
320 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
|
|
321 |
request.getRequestURL().toString(), HttpStatus.FORBIDDEN.toString(), HttpStatus.FORBIDDEN,
|
|
|
322 |
ResponseStatus.FAILURE, null);
|
| 21414 |
kshitij.so |
323 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.FORBIDDEN);
|
|
|
324 |
}
|
| 21469 |
amit.gupta |
325 |
|
| 21414 |
kshitij.so |
326 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 21469 |
amit.gupta |
327 |
try {
|
| 21414 |
kshitij.so |
328 |
User user = userRepository.selectByEmailId(emailId);
|
|
|
329 |
Set<Role> roles = user.getRoles();
|
|
|
330 |
String[] roleTypes = new String[roles.size()];
|
|
|
331 |
int index = 0;
|
| 21469 |
amit.gupta |
332 |
for (Role role : roles) {
|
| 21414 |
kshitij.so |
333 |
roleTypes[index++] = role.getType().toString();
|
|
|
334 |
}
|
|
|
335 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
|
|
|
336 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 21469 |
amit.gupta |
337 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
338 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
| 21414 |
kshitij.so |
339 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
|
|
340 |
}
|
| 21448 |
ashik.ali |
341 |
return responseSender.ok(responseMap);
|
| 21469 |
amit.gupta |
342 |
|
| 21414 |
kshitij.so |
343 |
}
|
| 21248 |
ashik.ali |
344 |
}
|