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