| 21561 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
| 21555 |
kshitij.so |
2 |
|
| 23419 |
ashik.ali |
3 |
import java.time.LocalDateTime;
|
| 22139 |
amit.gupta |
4 |
import java.util.ArrayList;
|
| 22111 |
ashik.ali |
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Set;
|
| 24976 |
amit.gupta |
8 |
import java.util.stream.Collectors;
|
| 22069 |
ashik.ali |
9 |
|
| 21577 |
ashik.ali |
10 |
import javax.servlet.http.Cookie;
|
| 21561 |
ashik.ali |
11 |
import javax.servlet.http.HttpServletRequest;
|
| 21577 |
ashik.ali |
12 |
import javax.servlet.http.HttpServletResponse;
|
| 21561 |
ashik.ali |
13 |
|
| 23784 |
ashik.ali |
14 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
15 |
import org.apache.logging.log4j.Logger;
|
| 21561 |
ashik.ali |
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 22079 |
amit.gupta |
17 |
import org.springframework.beans.factory.annotation.Value;
|
| 21555 |
kshitij.so |
18 |
import org.springframework.stereotype.Controller;
|
| 21987 |
kshitij.so |
19 |
import org.springframework.transaction.annotation.Transactional;
|
| 21615 |
kshitij.so |
20 |
import org.springframework.ui.Model;
|
| 21555 |
kshitij.so |
21 |
import org.springframework.ui.ModelMap;
|
|
|
22 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| 24383 |
amit.gupta |
23 |
import org.springframework.web.bind.annotation.PostMapping;
|
| 24016 |
amit.gupta |
24 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21555 |
kshitij.so |
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21561 |
ashik.ali |
27 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21555 |
kshitij.so |
28 |
|
| 21561 |
ashik.ali |
29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24976 |
amit.gupta |
30 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24016 |
amit.gupta |
31 |
import com.spice.profitmandi.common.model.Location;
|
| 21561 |
ashik.ali |
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24383 |
amit.gupta |
33 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 22111 |
ashik.ali |
34 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 23784 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 22111 |
ashik.ali |
36 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 23271 |
ashik.ali |
37 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 22111 |
ashik.ali |
38 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 24016 |
amit.gupta |
39 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 22111 |
ashik.ali |
40 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
41 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 24383 |
amit.gupta |
42 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 24016 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 22111 |
ashik.ali |
44 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 23784 |
ashik.ali |
45 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 22111 |
ashik.ali |
46 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
47 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
48 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 24383 |
amit.gupta |
49 |
import com.spice.profitmandi.service.AuthService;
|
| 24976 |
amit.gupta |
50 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
|
|
51 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22139 |
amit.gupta |
52 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
53 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 22111 |
ashik.ali |
54 |
import com.spice.profitmandi.web.util.GoogleTokenUtil;
|
| 21574 |
ashik.ali |
55 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21561 |
ashik.ali |
56 |
|
| 21555 |
kshitij.so |
57 |
@Controller
|
| 22148 |
amit.gupta |
58 |
@Transactional
|
| 21555 |
kshitij.so |
59 |
public class LoginController {
|
|
|
60 |
|
| 23568 |
govind |
61 |
private static final Logger LOGGER = LogManager.getLogger(LoginController.class);
|
| 24016 |
amit.gupta |
62 |
|
| 21561 |
ashik.ali |
63 |
@Autowired
|
| 22927 |
ashik.ali |
64 |
private GoogleTokenUtil googleTokenUtil;
|
| 24016 |
amit.gupta |
65 |
|
| 21574 |
ashik.ali |
66 |
@Autowired
|
| 24976 |
amit.gupta |
67 |
private RoleManager roleManager;
|
|
|
68 |
|
|
|
69 |
@Autowired
|
| 22927 |
ashik.ali |
70 |
private RetailerRepository retailerRepository;
|
| 24016 |
amit.gupta |
71 |
|
| 22111 |
ashik.ali |
72 |
@Autowired
|
| 24976 |
amit.gupta |
73 |
private RetailerService retailerService;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
| 22927 |
ashik.ali |
76 |
private UserRepository userRepository;
|
| 24016 |
amit.gupta |
77 |
|
| 22111 |
ashik.ali |
78 |
@Autowired
|
| 22927 |
ashik.ali |
79 |
private UserAccountRepository userAccountRepository;
|
| 24016 |
amit.gupta |
80 |
|
| 22111 |
ashik.ali |
81 |
@Autowired
|
| 22927 |
ashik.ali |
82 |
private UserRoleRepository userRoleRepository;
|
| 24016 |
amit.gupta |
83 |
|
| 22111 |
ashik.ali |
84 |
@Autowired
|
| 23784 |
ashik.ali |
85 |
private RoleRepository roleRepository;
|
| 24016 |
amit.gupta |
86 |
|
| 23784 |
ashik.ali |
87 |
@Autowired
|
| 24016 |
amit.gupta |
88 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
89 |
|
|
|
90 |
@Autowired
|
| 22927 |
ashik.ali |
91 |
private MVCResponseSender mvcResponseSender;
|
| 24016 |
amit.gupta |
92 |
|
| 21578 |
ashik.ali |
93 |
@Autowired
|
| 22927 |
ashik.ali |
94 |
private CookiesProcessor cookiesProcessor;
|
| 22079 |
amit.gupta |
95 |
|
|
|
96 |
@Value("${google.api.key}")
|
|
|
97 |
private String googleApiKey;
|
| 24016 |
amit.gupta |
98 |
|
| 24383 |
amit.gupta |
99 |
@Autowired
|
|
|
100 |
private AuthService authService;
|
|
|
101 |
|
|
|
102 |
@Autowired
|
|
|
103 |
private AuthRepository authRepository;
|
|
|
104 |
|
| 21555 |
kshitij.so |
105 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 24016 |
amit.gupta |
106 |
public String loginPage(HttpServletRequest request, Model model) throws Exception {
|
| 22088 |
amit.gupta |
107 |
LOGGER.info("Context Path is {}", request.getContextPath());
|
| 24016 |
amit.gupta |
108 |
try {
|
| 23784 |
ashik.ali |
109 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 22139 |
amit.gupta |
110 |
LOGGER.info("Request session is already exist, should be redirect to as per roles assigned");
|
| 23784 |
ashik.ali |
111 |
String redirectUrl = null;
|
| 24016 |
amit.gupta |
112 |
|
| 23784 |
ashik.ali |
113 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
114 |
Role roleFofo = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
115 |
Role roleFofoAdmin = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 24016 |
amit.gupta |
116 |
if ((fofoDetails.getRoleIds().contains(roleRetailer.getId())
|
|
|
117 |
&& fofoDetails.getRoleIds().contains(roleFofo.getId())
|
|
|
118 |
|| (fofoDetails.getRoleIds().contains(roleFofoAdmin.getId())))) {
|
| 23784 |
ashik.ali |
119 |
redirectUrl = "/dashboard";
|
|
|
120 |
} else {
|
|
|
121 |
redirectUrl = "/login";
|
|
|
122 |
}
|
|
|
123 |
return "redirect:" + redirectUrl;
|
| 24016 |
amit.gupta |
124 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22079 |
amit.gupta |
125 |
model.addAttribute("googleApiKey", googleApiKey);
|
| 22086 |
amit.gupta |
126 |
model.addAttribute("appContextPath", request.getContextPath());
|
| 21577 |
ashik.ali |
127 |
return "login";
|
| 21574 |
ashik.ali |
128 |
}
|
| 21555 |
kshitij.so |
129 |
}
|
| 24016 |
amit.gupta |
130 |
|
| 22155 |
amit.gupta |
131 |
@RequestMapping(value = "/", method = RequestMethod.GET)
|
| 24016 |
amit.gupta |
132 |
public String home() {
|
| 22860 |
ashik.ali |
133 |
return "redirect:/login";
|
| 22155 |
amit.gupta |
134 |
}
|
| 24016 |
amit.gupta |
135 |
|
| 24976 |
amit.gupta |
136 |
@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
|
|
|
137 |
public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
|
|
|
138 |
@RequestParam int fofoId) throws Exception {
|
|
|
139 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
140 |
if(roleManager.isAdmin(fofoDetails.getRoleIds())){
|
|
|
141 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
142 |
Set<Integer> roleIds = userRoleRepository.selectByUserId(fofoId).stream().map(x->x.getRoleId()).collect(Collectors.toSet());
|
|
|
143 |
LoginDetails newFofoDetails = new LoginDetails();
|
|
|
144 |
newFofoDetails.setFofoId(fofoId);
|
|
|
145 |
newFofoDetails.setRoleIds(roleIds);
|
|
|
146 |
newFofoDetails.setEmailId(customRetailer.getEmail());
|
| 24981 |
amit.gupta |
147 |
model.addAttribute("response", true);
|
| 24983 |
amit.gupta |
148 |
this.addCookiesToResponse(newFofoDetails, request, response);
|
| 24976 |
amit.gupta |
149 |
} else {
|
|
|
150 |
throw new ProfitMandiBusinessException("", "", "");
|
|
|
151 |
}
|
| 24981 |
amit.gupta |
152 |
return "response";
|
| 24976 |
amit.gupta |
153 |
}
|
|
|
154 |
|
| 21555 |
kshitij.so |
155 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 24016 |
amit.gupta |
156 |
public String login(HttpServletRequest request, HttpServletResponse response,
|
| 24383 |
amit.gupta |
157 |
@RequestParam(name = ProfitMandiConstants.TOKEN) String token,
|
|
|
158 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER, defaultValue = "") String emailIdOrMobileNumber,
|
|
|
159 |
@RequestParam(name = "password", defaultValue = "") String password, Model model) throws Exception {
|
|
|
160 |
|
| 22139 |
amit.gupta |
161 |
LoginDetails fofoDetails = new LoginDetails();
|
| 23784 |
ashik.ali |
162 |
Set<Integer> roleIds = new HashSet<>();
|
|
|
163 |
fofoDetails.setRoleIds(roleIds);
|
| 24383 |
amit.gupta |
164 |
String emailId = null;
|
| 24976 |
amit.gupta |
165 |
String name = null;
|
| 24016 |
amit.gupta |
166 |
try {
|
|
|
167 |
// if role is retailer then FOFO_ID is retailerId else it is userid as normal
|
|
|
168 |
// user's wont have retailer id.
|
| 24383 |
amit.gupta |
169 |
if (token == "") {
|
|
|
170 |
if (authService.authenticate(emailIdOrMobileNumber, password)) {
|
|
|
171 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailIdOrMobileNumber);
|
| 24976 |
amit.gupta |
172 |
if (authUser == null) {
|
|
|
173 |
throw new ProfitMandiBusinessException("Authentication", "Email or Mobile",
|
|
|
174 |
"Invalid Email Or Mobile");
|
| 24383 |
amit.gupta |
175 |
}
|
|
|
176 |
emailId = authUser.getEmailId();
|
| 24976 |
amit.gupta |
177 |
name = authUser.getFirstName() + " " + authUser.getLastName();
|
| 24383 |
amit.gupta |
178 |
authUser.setLastLoginTimestamp(LocalDateTime.now());
|
|
|
179 |
authRepository.persist(authUser);
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
} else {
|
|
|
183 |
emailId = googleTokenUtil.getEmailId(token);
|
| 24976 |
amit.gupta |
184 |
if (ProfitMandiConstants.BLOCKED_EMAILS.contains(emailId)) {
|
| 24527 |
amit.gupta |
185 |
}
|
| 24383 |
amit.gupta |
186 |
}
|
| 22139 |
amit.gupta |
187 |
fofoDetails.setEmailId(emailId);
|
|
|
188 |
fofoDetails.setFofoId(-1);
|
| 24016 |
amit.gupta |
189 |
// fofoDetails.setFofo(false);
|
| 22111 |
ashik.ali |
190 |
User user = null;
|
| 24016 |
amit.gupta |
191 |
try {
|
| 22111 |
ashik.ali |
192 |
user = userRepository.selectByEmailId(emailId);
|
| 24016 |
amit.gupta |
193 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23628 |
ashik.ali |
194 |
LOGGER.error("User not found with given emailId [{}]", emailId);
|
| 23203 |
ashik.ali |
195 |
}
|
| 24016 |
amit.gupta |
196 |
if (user == null) {
|
|
|
197 |
try {
|
| 23203 |
ashik.ali |
198 |
user = userRepository.selectBySecondryEmailId(emailId);
|
| 24016 |
amit.gupta |
199 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23203 |
ashik.ali |
200 |
LOGGER.error("User not found with given emailId", profitMandiBusinessException);
|
| 24527 |
amit.gupta |
201 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
| 24976 |
amit.gupta |
202 |
request.getContextPath() + "/login", "Email"));
|
| 24527 |
amit.gupta |
203 |
return "response";
|
| 23203 |
ashik.ali |
204 |
}
|
|
|
205 |
}
|
| 24016 |
amit.gupta |
206 |
if (user != null) {
|
| 22139 |
amit.gupta |
207 |
fofoDetails.setFofoId(user.getId());
|
|
|
208 |
try {
|
|
|
209 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 24016 |
amit.gupta |
210 |
for (int index = 0; index < userRoles.size(); index++) {
|
| 23784 |
ashik.ali |
211 |
roleIds.add(userRoles.get(index).getRoleId());
|
| 22139 |
amit.gupta |
212 |
}
|
| 23784 |
ashik.ali |
213 |
List<Role> roles = roleRepository.selectByIds(roleIds);
|
| 24016 |
amit.gupta |
214 |
for (Role role : roles) {
|
|
|
215 |
if (role.getName().equals(RoleType.RETAILER.toString())) {
|
|
|
216 |
UserAccount userAccounts = userAccountRepository.selectByUserIdType(user.getId(),
|
|
|
217 |
AccountType.saholic);
|
| 23784 |
ashik.ali |
218 |
Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
|
|
|
219 |
fofoDetails.setFofoId(retailer.getId());
|
| 24016 |
amit.gupta |
220 |
// fofoDetails.setFofo(retailer.isFofo());
|
| 23784 |
ashik.ali |
221 |
}
|
| 22166 |
amit.gupta |
222 |
}
|
| 24016 |
amit.gupta |
223 |
} catch (ProfitMandiBusinessException pmbe) {
|
| 22139 |
amit.gupta |
224 |
LOGGER.error("Data Inconsistent", pmbe);
|
|
|
225 |
}
|
| 22111 |
ashik.ali |
226 |
}
|
| 23784 |
ashik.ali |
227 |
String redirectUrl = null;
|
| 24016 |
amit.gupta |
228 |
|
| 23784 |
ashik.ali |
229 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
230 |
Role roleFofo = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
231 |
Role roleFofoAdmin = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 24016 |
amit.gupta |
232 |
|
|
|
233 |
if ((fofoDetails.getRoleIds().contains(roleRetailer.getId())
|
|
|
234 |
&& fofoDetails.getRoleIds().contains(roleFofo.getId())
|
|
|
235 |
|| (fofoDetails.getRoleIds().contains(roleFofoAdmin.getId())))) {
|
| 23784 |
ashik.ali |
236 |
redirectUrl = "/dashboard";
|
|
|
237 |
} else {
|
|
|
238 |
redirectUrl = "/login";
|
|
|
239 |
}
|
| 24016 |
amit.gupta |
240 |
|
|
|
241 |
if (!redirectUrl.equals("/login")) {
|
| 23419 |
ashik.ali |
242 |
user.setLoginTimestamp(LocalDateTime.now());
|
|
|
243 |
userRepository.persist(user);
|
| 23173 |
ashik.ali |
244 |
this.addCookiesToResponse(fofoDetails, request, response);
|
| 24016 |
amit.gupta |
245 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
|
|
246 |
redirectUrl);
|
|
|
247 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
| 24976 |
amit.gupta |
248 |
request.getContextPath() + redirectUrl, name));
|
| 24016 |
amit.gupta |
249 |
} else {
|
| 23173 |
ashik.ali |
250 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
| 24016 |
amit.gupta |
251 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
|
|
252 |
"RTLR_1000");
|
| 23173 |
ashik.ali |
253 |
}
|
| 21578 |
ashik.ali |
254 |
return "response";
|
| 24016 |
amit.gupta |
255 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 21568 |
ashik.ali |
256 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 24016 |
amit.gupta |
257 |
model.addAttribute("response",
|
|
|
258 |
mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
| 21578 |
ashik.ali |
259 |
return "response";
|
| 21561 |
ashik.ali |
260 |
}
|
| 21555 |
kshitij.so |
261 |
}
|
| 24976 |
amit.gupta |
262 |
|
| 24383 |
amit.gupta |
263 |
@PostMapping(value = "/forgetPassword")
|
| 24976 |
amit.gupta |
264 |
public String forgetPasswordPage(
|
|
|
265 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID, defaultValue = "") String emailId, Model model)
|
|
|
266 |
throws Exception {
|
| 24383 |
amit.gupta |
267 |
LOGGER.info(emailId);
|
|
|
268 |
authService.resetPassword(emailId);
|
|
|
269 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
270 |
LOGGER.info("completed");
|
|
|
271 |
return "response";
|
|
|
272 |
}
|
| 24016 |
amit.gupta |
273 |
|
|
|
274 |
private void addCookiesToResponse(LoginDetails fofoDetails, HttpServletRequest request,
|
|
|
275 |
HttpServletResponse response) {
|
| 23784 |
ashik.ali |
276 |
List<String> roleIds = new ArrayList<>();
|
| 24016 |
amit.gupta |
277 |
|
|
|
278 |
for (int roleId : fofoDetails.getRoleIds()) {
|
| 23784 |
ashik.ali |
279 |
roleIds.add(String.valueOf(roleId));
|
| 22139 |
amit.gupta |
280 |
}
|
| 23784 |
ashik.ali |
281 |
Cookie cookieRoleIds = new Cookie(ProfitMandiConstants.ROLE_IDS, String.join(",", roleIds));
|
|
|
282 |
cookieRoleIds.setDomain(request.getServerName());
|
|
|
283 |
cookieRoleIds.setPath(request.getContextPath());
|
| 24016 |
amit.gupta |
284 |
|
| 22139 |
amit.gupta |
285 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
|
|
286 |
cookieFofoId.setDomain(request.getServerName());
|
| 22160 |
amit.gupta |
287 |
cookieFofoId.setPath(request.getContextPath());
|
| 24016 |
amit.gupta |
288 |
|
| 22139 |
amit.gupta |
289 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId());
|
|
|
290 |
cookieEmailId.setDomain(request.getServerName());
|
| 22160 |
amit.gupta |
291 |
cookieEmailId.setPath(request.getContextPath());
|
| 24983 |
amit.gupta |
292 |
|
| 22139 |
amit.gupta |
293 |
response.addCookie(cookieFofoId);
|
|
|
294 |
response.addCookie(cookieEmailId);
|
| 23784 |
ashik.ali |
295 |
response.addCookie(cookieRoleIds);
|
| 22139 |
amit.gupta |
296 |
}
|
| 24016 |
amit.gupta |
297 |
|
| 22069 |
ashik.ali |
298 |
@RequestMapping(value = "/logout", method = RequestMethod.GET)
|
| 24016 |
amit.gupta |
299 |
public String logout(HttpServletRequest request, @ModelAttribute("model") ModelMap model,
|
|
|
300 |
HttpServletResponse response) throws Exception {
|
|
|
301 |
try {
|
| 23419 |
ashik.ali |
302 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
303 |
User user = null;
|
| 24016 |
amit.gupta |
304 |
try {
|
| 23419 |
ashik.ali |
305 |
user = userRepository.selectByEmailId(loginDetails.getEmailId());
|
| 24016 |
amit.gupta |
306 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23419 |
ashik.ali |
307 |
LOGGER.error("User not found with given emailId", profitMandiBusinessException);
|
|
|
308 |
}
|
| 24016 |
amit.gupta |
309 |
if (user == null) {
|
| 23419 |
ashik.ali |
310 |
user = userRepository.selectBySecondryEmailId(loginDetails.getEmailId());
|
|
|
311 |
}
|
|
|
312 |
user.setLogoutTimestamp(LocalDateTime.now());
|
|
|
313 |
userRepository.persist(user);
|
| 22069 |
ashik.ali |
314 |
cookiesProcessor.removeCookies(request, response);
|
|
|
315 |
LOGGER.info("Logout is successfull, should be redirect to /login");
|
| 22085 |
amit.gupta |
316 |
return "redirect:/login";
|
| 24016 |
amit.gupta |
317 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22069 |
ashik.ali |
318 |
LOGGER.info("Error occured while removing requested cookies, should be redirect to /login");
|
| 22085 |
amit.gupta |
319 |
return "redirect:/login";
|
| 22069 |
ashik.ali |
320 |
}
|
|
|
321 |
}
|
| 24016 |
amit.gupta |
322 |
|
|
|
323 |
@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
|
|
|
324 |
public String setLocation(HttpServletRequest request, Model model, @RequestBody Location location)
|
|
|
325 |
throws Exception {
|
|
|
326 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
327 |
boolean response = true;
|
| 24976 |
amit.gupta |
328 |
try {
|
|
|
329 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
|
|
330 |
if (fs.getLatitude() == null) {
|
|
|
331 |
fs.setLatitude(location.getLatitude());
|
|
|
332 |
fs.setLongitude(location.getLongitude());
|
|
|
333 |
fofoStoreRepository.persist(fs);
|
|
|
334 |
}
|
|
|
335 |
model.addAttribute("response", response);
|
|
|
336 |
} catch (Exception e) {
|
| 24383 |
amit.gupta |
337 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
|
|
338 |
}
|
| 24016 |
amit.gupta |
339 |
return "response";
|
|
|
340 |
}
|
| 21555 |
kshitij.so |
341 |
}
|