| 21561 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
| 21555 |
kshitij.so |
2 |
|
| 21577 |
ashik.ali |
3 |
import javax.servlet.http.Cookie;
|
| 21561 |
ashik.ali |
4 |
import javax.servlet.http.HttpServletRequest;
|
| 21577 |
ashik.ali |
5 |
import javax.servlet.http.HttpServletResponse;
|
| 21561 |
ashik.ali |
6 |
|
| 21568 |
ashik.ali |
7 |
import org.slf4j.Logger;
|
|
|
8 |
import org.slf4j.LoggerFactory;
|
| 21561 |
ashik.ali |
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21555 |
kshitij.so |
10 |
import org.springframework.stereotype.Controller;
|
|
|
11 |
import org.springframework.ui.ModelMap;
|
|
|
12 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
13 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21561 |
ashik.ali |
15 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21555 |
kshitij.so |
16 |
|
| 21561 |
ashik.ali |
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
19 |
import com.spice.profitmandi.web.model.FofoDetails;
|
|
|
20 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
| 21574 |
ashik.ali |
21 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21561 |
ashik.ali |
22 |
|
| 21555 |
kshitij.so |
23 |
@Controller
|
|
|
24 |
public class LoginController {
|
|
|
25 |
|
| 21568 |
ashik.ali |
26 |
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
|
|
|
27 |
|
| 21561 |
ashik.ali |
28 |
@Autowired
|
|
|
29 |
GoogleLoginUtil googleLoginUtil;
|
|
|
30 |
|
| 21574 |
ashik.ali |
31 |
@Autowired
|
|
|
32 |
MVCResponseSender mvcResponseSender;
|
|
|
33 |
|
| 21555 |
kshitij.so |
34 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 21574 |
ashik.ali |
35 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
| 21577 |
ashik.ali |
36 |
Cookie[] cookies = request.getCookies();
|
|
|
37 |
if(cookies == null || cookies.length != 2 || !(cookies[0].getName().equals(ProfitMandiConstants.FOFO_ID) && cookies[1].getName().equals(ProfitMandiConstants.EMAIL_ID))){
|
|
|
38 |
return "login";
|
|
|
39 |
}else{
|
| 21574 |
ashik.ali |
40 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
|
|
41 |
return mvcResponseSender.createResponseString("RTLR_OK_1001", true, "/dashboard");
|
|
|
42 |
}
|
| 21555 |
kshitij.so |
43 |
}
|
|
|
44 |
|
|
|
45 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 21577 |
ashik.ali |
46 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token) throws Exception{
|
| 21561 |
ashik.ali |
47 |
try{
|
|
|
48 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
| 21577 |
ashik.ali |
49 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
|
|
50 |
cookieFofoId.setDomain("localhost");
|
|
|
51 |
cookieFofoId.setMaxAge(30);
|
|
|
52 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.FOFO_ID, fofoDetails.getEmailId());
|
|
|
53 |
cookieEmailId.setDomain("localhost");
|
|
|
54 |
cookieEmailId.setMaxAge(30);
|
|
|
55 |
response.addCookie(cookieFofoId);
|
|
|
56 |
response.addCookie(cookieEmailId);
|
| 21574 |
ashik.ali |
57 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
|
|
58 |
return mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/dashboard");
|
| 21561 |
ashik.ali |
59 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21568 |
ashik.ali |
60 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 21574 |
ashik.ali |
61 |
return mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error");
|
| 21561 |
ashik.ali |
62 |
}
|
| 21555 |
kshitij.so |
63 |
}
|
| 21574 |
ashik.ali |
64 |
|
| 21555 |
kshitij.so |
65 |
}
|