| 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.HttpServletRequest;
|
3 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
4 |
import javax.servlet.http.HttpSession;
|
| 4 |
|
5 |
|
| 5 |
import org.hibernate.tool.schema.extract.internal.ForeignKeyInformationImpl;
|
- |
|
| 6 |
import org.slf4j.Logger;
|
6 |
import org.slf4j.Logger;
|
| 7 |
import org.slf4j.LoggerFactory;
|
7 |
import org.slf4j.LoggerFactory;
|
| 8 |
import org.springframework.beans.factory.annotation.Autowired;
|
8 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 9 |
import org.springframework.stereotype.Controller;
|
9 |
import org.springframework.stereotype.Controller;
|
| 10 |
import org.springframework.ui.ModelMap;
|
10 |
import org.springframework.ui.ModelMap;
|
| Line 15... |
Line 15... |
| 15 |
|
15 |
|
| 16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 17 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
17 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 18 |
import com.spice.profitmandi.web.model.FofoDetails;
|
18 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 19 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
19 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
| - |
|
20 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 20 |
|
21 |
|
| 21 |
@Controller
|
22 |
@Controller
|
| 22 |
public class LoginController {
|
23 |
public class LoginController {
|
| 23 |
|
24 |
|
| 24 |
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
|
25 |
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
|
| 25 |
|
26 |
|
| 26 |
@Autowired
|
27 |
@Autowired
|
| 27 |
GoogleLoginUtil googleLoginUtil;
|
28 |
GoogleLoginUtil googleLoginUtil;
|
| 28 |
|
29 |
|
| - |
|
30 |
@Autowired
|
| - |
|
31 |
MVCResponseSender mvcResponseSender;
|
| - |
|
32 |
|
| 29 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
33 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 30 |
public String loginPage(@ModelAttribute("model") ModelMap model) {
|
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{
|
| 31 |
return "login";
|
40 |
return "login";
|
| - |
|
41 |
}
|
| 32 |
}
|
42 |
}
|
| 33 |
|
43 |
|
| 34 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
44 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 35 |
public String login(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.TOKEN) String token){
|
45 |
public String login(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.TOKEN) String token) throws Exception{
|
| 36 |
try{
|
46 |
try{
|
| 37 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
47 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
| 38 |
request.getSession().setAttribute(ProfitMandiConstants.FOFO_DETAILS, fofoDetails);
|
48 |
request.getSession().setAttribute(ProfitMandiConstants.FOFO_DETAILS, fofoDetails);
|
| - |
|
49 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
| 39 |
return "redirect: dashboard";
|
50 |
return mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/dashboard");
|
| 40 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
51 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 41 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
52 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 42 |
return "redirect: error";
|
53 |
return mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error");
|
| 43 |
}
|
54 |
}
|
| 44 |
}
|
55 |
}
|
| - |
|
56 |
|
| 45 |
}
|
57 |
}
|