| 21561 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
| 21555 |
kshitij.so |
2 |
|
| 21561 |
ashik.ali |
3 |
import javax.servlet.http.HttpServletRequest;
|
| 21574 |
ashik.ali |
4 |
import javax.servlet.http.HttpSession;
|
| 21561 |
ashik.ali |
5 |
|
| 21568 |
ashik.ali |
6 |
import org.slf4j.Logger;
|
|
|
7 |
import org.slf4j.LoggerFactory;
|
| 21561 |
ashik.ali |
8 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21555 |
kshitij.so |
9 |
import org.springframework.stereotype.Controller;
|
|
|
10 |
import org.springframework.ui.ModelMap;
|
|
|
11 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
12 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
13 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21561 |
ashik.ali |
14 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21555 |
kshitij.so |
15 |
|
| 21561 |
ashik.ali |
16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
17 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
18 |
import com.spice.profitmandi.web.model.FofoDetails;
|
|
|
19 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
| 21574 |
ashik.ali |
20 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21561 |
ashik.ali |
21 |
|
| 21555 |
kshitij.so |
22 |
@Controller
|
|
|
23 |
public class LoginController {
|
|
|
24 |
|
| 21568 |
ashik.ali |
25 |
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
|
|
|
26 |
|
| 21561 |
ashik.ali |
27 |
@Autowired
|
|
|
28 |
GoogleLoginUtil googleLoginUtil;
|
|
|
29 |
|
| 21574 |
ashik.ali |
30 |
@Autowired
|
|
|
31 |
MVCResponseSender mvcResponseSender;
|
|
|
32 |
|
| 21555 |
kshitij.so |
33 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 21574 |
ashik.ali |
34 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
|
|
35 |
HttpSession session = request.getSession(false);
|
|
|
36 |
if(session == null || (FofoDetails)session.getAttribute(ProfitMandiConstants.FOFO_DETAILS) == null){
|
|
|
37 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
|
|
38 |
return mvcResponseSender.createResponseString("RTLR_OK_1001", true, "/dashboard");
|
|
|
39 |
}else{
|
|
|
40 |
return "login";
|
|
|
41 |
}
|
| 21555 |
kshitij.so |
42 |
}
|
|
|
43 |
|
|
|
44 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 21574 |
ashik.ali |
45 |
public String login(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.TOKEN) String token) throws Exception{
|
| 21561 |
ashik.ali |
46 |
try{
|
|
|
47 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
|
|
48 |
request.getSession().setAttribute(ProfitMandiConstants.FOFO_DETAILS, fofoDetails);
|
| 21574 |
ashik.ali |
49 |
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");
|
| 21561 |
ashik.ali |
51 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21568 |
ashik.ali |
52 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 21574 |
ashik.ali |
53 |
return mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error");
|
| 21561 |
ashik.ali |
54 |
}
|
| 21555 |
kshitij.so |
55 |
}
|
| 21574 |
ashik.ali |
56 |
|
| 21555 |
kshitij.so |
57 |
}
|