| Line 15... |
Line 15... |
| 15 |
import org.springframework.web.bind.annotation.RequestParam;
|
15 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 16 |
|
16 |
|
| 17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 19 |
import com.spice.profitmandi.web.model.FofoDetails;
|
19 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| - |
|
20 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
| 20 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
21 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
| 21 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
22 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22 |
|
23 |
|
| 23 |
@Controller
|
24 |
@Controller
|
| 24 |
public class LoginController {
|
25 |
public class LoginController {
|
| Line 29... |
Line 30... |
| 29 |
GoogleLoginUtil googleLoginUtil;
|
30 |
GoogleLoginUtil googleLoginUtil;
|
| 30 |
|
31 |
|
| 31 |
@Autowired
|
32 |
@Autowired
|
| 32 |
MVCResponseSender mvcResponseSender;
|
33 |
MVCResponseSender mvcResponseSender;
|
| 33 |
|
34 |
|
| - |
|
35 |
@Autowired
|
| - |
|
36 |
CookiesFetcher cookiesFetcher;
|
| - |
|
37 |
|
| 34 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
38 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 35 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
39 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
| 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{
|
40 |
try{
|
| - |
|
41 |
cookiesFetcher.getCookiesObject(request);
|
| 40 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
42 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
| 41 |
return mvcResponseSender.createResponseString("RTLR_OK_1001", true, "/dashboard");
|
43 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1001", true, "/dashboard"));
|
| - |
|
44 |
return "response";
|
| - |
|
45 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
46 |
return "login";
|
| 42 |
}
|
47 |
}
|
| 43 |
}
|
48 |
}
|
| 44 |
|
49 |
|
| 45 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
50 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 46 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token) throws Exception{
|
51 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token, @ModelAttribute ModelMap model) throws Exception{
|
| 47 |
try{
|
52 |
try{
|
| 48 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
53 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
| 49 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
54 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
| 50 |
cookieFofoId.setDomain("localhost");
|
55 |
cookieFofoId.setDomain("localhost");
|
| 51 |
cookieFofoId.setMaxAge(30);
|
56 |
cookieFofoId.setMaxAge(30);
|
| 52 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.FOFO_ID, fofoDetails.getEmailId());
|
57 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId());
|
| 53 |
cookieEmailId.setDomain("localhost");
|
58 |
cookieEmailId.setDomain("localhost");
|
| 54 |
cookieEmailId.setMaxAge(30);
|
59 |
cookieEmailId.setMaxAge(30);
|
| 55 |
response.addCookie(cookieFofoId);
|
60 |
response.addCookie(cookieFofoId);
|
| 56 |
response.addCookie(cookieEmailId);
|
61 |
response.addCookie(cookieEmailId);
|
| 57 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
62 |
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");
|
63 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/dashboard"));
|
| - |
|
64 |
return "response";
|
| 59 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
65 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 60 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
66 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 61 |
return mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error");
|
67 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
| - |
|
68 |
return "response";
|
| 62 |
}
|
69 |
}
|
| 63 |
}
|
70 |
}
|
| 64 |
|
71 |
|
| 65 |
}
|
72 |
}
|