| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import javax.servlet.http.Cookie;
|
| 3 |
import javax.servlet.http.HttpServletRequest;
|
4 |
import javax.servlet.http.HttpServletRequest;
|
| 4 |
import javax.servlet.http.HttpSession;
|
5 |
import javax.servlet.http.HttpServletResponse;
|
| 5 |
|
6 |
|
| 6 |
import org.slf4j.Logger;
|
7 |
import org.slf4j.Logger;
|
| 7 |
import org.slf4j.LoggerFactory;
|
8 |
import org.slf4j.LoggerFactory;
|
| 8 |
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 9 |
import org.springframework.stereotype.Controller;
|
10 |
import org.springframework.stereotype.Controller;
|
| Line 30... |
Line 31... |
| 30 |
@Autowired
|
31 |
@Autowired
|
| 31 |
MVCResponseSender mvcResponseSender;
|
32 |
MVCResponseSender mvcResponseSender;
|
| 32 |
|
33 |
|
| 33 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
34 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 34 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
35 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
| 35 |
HttpSession session = request.getSession(false);
|
36 |
Cookie[] cookies = request.getCookies();
|
| 36 |
if(session == null || (FofoDetails)session.getAttribute(ProfitMandiConstants.FOFO_DETAILS) == null){
|
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{
|
| 37 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
40 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
| 38 |
return mvcResponseSender.createResponseString("RTLR_OK_1001", true, "/dashboard");
|
41 |
return mvcResponseSender.createResponseString("RTLR_OK_1001", true, "/dashboard");
|
| 39 |
}else{
|
- |
|
| 40 |
return "login";
|
- |
|
| 41 |
}
|
42 |
}
|
| 42 |
}
|
43 |
}
|
| 43 |
|
44 |
|
| 44 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
45 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 45 |
public String login(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.TOKEN) String token) throws Exception{
|
46 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token) throws Exception{
|
| 46 |
try{
|
47 |
try{
|
| 47 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
48 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
| - |
|
49 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
| - |
|
50 |
cookieFofoId.setDomain("localhost");
|
| - |
|
51 |
cookieFofoId.setMaxAge(30);
|
| 48 |
request.getSession().setAttribute(ProfitMandiConstants.FOFO_DETAILS, fofoDetails);
|
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);
|
| 49 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
57 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
| 50 |
return mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/dashboard");
|
58 |
return mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/dashboard");
|
| 51 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
59 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 52 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
60 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 53 |
return mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error");
|
61 |
return mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error");
|