| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.io.InputStream;
|
| - |
|
4 |
import java.util.Properties;
|
| - |
|
5 |
|
| 3 |
import javax.servlet.http.Cookie;
|
6 |
import javax.servlet.http.Cookie;
|
| 4 |
import javax.servlet.http.HttpServletRequest;
|
7 |
import javax.servlet.http.HttpServletRequest;
|
| 5 |
import javax.servlet.http.HttpServletResponse;
|
8 |
import javax.servlet.http.HttpServletResponse;
|
| 6 |
|
9 |
|
| 7 |
import org.slf4j.Logger;
|
10 |
import org.slf4j.Logger;
|
| 8 |
import org.slf4j.LoggerFactory;
|
11 |
import org.slf4j.LoggerFactory;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
13 |
import org.springframework.context.annotation.PropertySource;
|
| - |
|
14 |
import org.springframework.core.io.Resource;
|
| 10 |
import org.springframework.stereotype.Controller;
|
15 |
import org.springframework.stereotype.Controller;
|
| 11 |
import org.springframework.transaction.annotation.Transactional;
|
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 12 |
import org.springframework.ui.Model;
|
17 |
import org.springframework.ui.Model;
|
| 13 |
import org.springframework.ui.ModelMap;
|
18 |
import org.springframework.ui.ModelMap;
|
| 14 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
19 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| Line 16... |
Line 21... |
| 16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 17 |
import org.springframework.web.bind.annotation.RequestParam;
|
22 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 18 |
|
23 |
|
| 19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
26 |
import com.spice.profitmandi.web.config.AppConfig;
|
| 21 |
import com.spice.profitmandi.web.model.FofoDetails;
|
27 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 22 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
28 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
29 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
| 24 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
30 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 25 |
|
31 |
|
| 26 |
@Controller
|
32 |
@Controller
|
| 27 |
@Transactional(rollbackFor=Throwable.class)
|
33 |
@Transactional(rollbackFor=Throwable.class)
|
| Line 34... |
Line 40... |
| 34 |
|
40 |
|
| 35 |
@Autowired
|
41 |
@Autowired
|
| 36 |
MVCResponseSender mvcResponseSender;
|
42 |
MVCResponseSender mvcResponseSender;
|
| 37 |
|
43 |
|
| 38 |
@Autowired
|
44 |
@Autowired
|
| 39 |
CookiesFetcher cookiesFetcher;
|
45 |
CookiesProcessor cookiesProcessor;
|
| 40 |
|
46 |
|
| 41 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
47 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 42 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
48 |
public String loginPage(HttpServletRequest request, @ModelAttribute("model") ModelMap model) throws Exception{
|
| 43 |
try{
|
49 |
try{
|
| 44 |
cookiesFetcher.getCookiesObject(request);
|
50 |
cookiesProcessor.getCookiesObject(request);
|
| 45 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
51 |
LOGGER.info("Request session is already exist, should be redirect to /dashboard");
|
| 46 |
return "redirect:/dashboard";
|
52 |
return "redirect:/dashboard";
|
| 47 |
}catch(Exception | ProfitMandiBusinessException profitMandiBusinessException){
|
53 |
}catch(Exception | ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
54 |
Resource resource = AppConfig.getResource();
|
| - |
|
55 |
Properties properties = new Properties();
|
| - |
|
56 |
properties.load(resource.getInputStream());
|
| - |
|
57 |
model.addAttribute("googleApiKey", properties.getProperty("google.api.key"));
|
| 48 |
return "login";
|
58 |
return "login";
|
| 49 |
}
|
59 |
}
|
| 50 |
}
|
60 |
}
|
| 51 |
|
61 |
|
| 52 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
62 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 53 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token, Model model) throws Exception{
|
63 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token, Model model) throws Exception{
|
| 54 |
try{
|
64 |
try{
|
| 55 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
65 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
| 56 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
66 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
| 57 |
cookieFofoId.setDomain("localhost");
|
67 |
cookieFofoId.setDomain(request.getServerName());
|
| 58 |
cookieFofoId.setPath(request.getContextPath());
|
68 |
cookieFofoId.setPath(request.getContextPath());
|
| 59 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId());
|
69 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId());
|
| 60 |
cookieEmailId.setDomain("localhost");
|
70 |
cookieEmailId.setDomain(request.getServerName());
|
| 61 |
cookieEmailId.setPath(request.getContextPath());
|
71 |
cookieEmailId.setPath(request.getContextPath());
|
| 62 |
response.addCookie(cookieFofoId);
|
72 |
response.addCookie(cookieFofoId);
|
| 63 |
response.addCookie(cookieEmailId);
|
73 |
response.addCookie(cookieEmailId);
|
| 64 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
74 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
| 65 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/profitmandi-fofo/dashboard"));
|
75 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/profitmandi-fofo/dashboard"));
|
| Line 70... |
Line 80... |
| 70 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
80 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
| 71 |
return "response";
|
81 |
return "response";
|
| 72 |
}
|
82 |
}
|
| 73 |
}
|
83 |
}
|
| 74 |
|
84 |
|
| - |
|
85 |
@RequestMapping(value = "/logout", method = RequestMethod.GET)
|
| - |
|
86 |
public String logout(HttpServletRequest request, @ModelAttribute("model") ModelMap model, HttpServletResponse response) throws Exception{
|
| - |
|
87 |
try{
|
| - |
|
88 |
cookiesProcessor.removeCookies(request, response);
|
| - |
|
89 |
LOGGER.info("Logout is successfull, should be redirect to /login");
|
| - |
|
90 |
return "login";
|
| - |
|
91 |
}catch(Exception | ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
92 |
LOGGER.info("Error occured while removing requested cookies, should be redirect to /login");
|
| - |
|
93 |
return "login";
|
| - |
|
94 |
}
|
| - |
|
95 |
}
|
| - |
|
96 |
|
| - |
|
97 |
|
| - |
|
98 |
|
| 75 |
}
|
99 |
}
|