| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.util.HashSet;
|
| - |
|
4 |
import java.util.List;
|
| 3 |
import java.util.Properties;
|
5 |
import java.util.Set;
|
| 4 |
|
6 |
|
| 5 |
import javax.servlet.http.Cookie;
|
7 |
import javax.servlet.http.Cookie;
|
| 6 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
| 7 |
import javax.servlet.http.HttpServletResponse;
|
9 |
import javax.servlet.http.HttpServletResponse;
|
| 8 |
|
10 |
|
| 9 |
import org.slf4j.Logger;
|
11 |
import org.slf4j.Logger;
|
| 10 |
import org.slf4j.LoggerFactory;
|
12 |
import org.slf4j.LoggerFactory;
|
| 11 |
import org.springframework.beans.factory.annotation.Autowired;
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 12 |
import org.springframework.beans.factory.annotation.Value;
|
14 |
import org.springframework.beans.factory.annotation.Value;
|
| 13 |
import org.springframework.core.io.Resource;
|
- |
|
| 14 |
import org.springframework.stereotype.Controller;
|
15 |
import org.springframework.stereotype.Controller;
|
| 15 |
import org.springframework.transaction.annotation.Transactional;
|
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 16 |
import org.springframework.ui.Model;
|
17 |
import org.springframework.ui.Model;
|
| 17 |
import org.springframework.ui.ModelMap;
|
18 |
import org.springframework.ui.ModelMap;
|
| 18 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
19 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| Line 20... |
Line 21... |
| 20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21 |
import org.springframework.web.bind.annotation.RequestParam;
|
22 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 22 |
|
23 |
|
| 23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
26 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 25 |
import com.spice.profitmandi.web.config.AppConfig;
|
27 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| - |
|
28 |
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
|
| - |
|
29 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| - |
|
30 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| - |
|
31 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| - |
|
32 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| - |
|
33 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| - |
|
34 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| - |
|
35 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 26 |
import com.spice.profitmandi.web.model.FofoDetails;
|
36 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 27 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
37 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 28 |
import com.spice.profitmandi.web.util.GoogleLoginUtil;
|
38 |
import com.spice.profitmandi.web.util.GoogleTokenUtil;
|
| 29 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
39 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 30 |
|
40 |
|
| 31 |
@Controller
|
41 |
@Controller
|
| 32 |
@Transactional(rollbackFor=Throwable.class)
|
42 |
@Transactional(rollbackFor=Throwable.class)
|
| 33 |
public class LoginController {
|
43 |
public class LoginController {
|
| 34 |
|
44 |
|
| 35 |
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
|
45 |
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
|
| 36 |
|
46 |
|
| 37 |
@Autowired
|
47 |
@Autowired
|
| 38 |
GoogleLoginUtil googleLoginUtil;
|
48 |
GoogleTokenUtil googleTokenUtil;
|
| - |
|
49 |
|
| - |
|
50 |
@Autowired
|
| - |
|
51 |
RetailerRepository retailerRepository;
|
| - |
|
52 |
|
| - |
|
53 |
@Autowired
|
| - |
|
54 |
UserRepository userRepository;
|
| - |
|
55 |
|
| - |
|
56 |
@Autowired
|
| - |
|
57 |
UserAccountRepository userAccountRepository;
|
| - |
|
58 |
|
| - |
|
59 |
@Autowired
|
| - |
|
60 |
UserRoleRepository userRoleRepository;
|
| 39 |
|
61 |
|
| 40 |
@Autowired
|
62 |
@Autowired
|
| 41 |
MVCResponseSender mvcResponseSender;
|
63 |
MVCResponseSender mvcResponseSender;
|
| 42 |
|
64 |
|
| 43 |
@Autowired
|
65 |
@Autowired
|
| Line 61... |
Line 83... |
| 61 |
}
|
83 |
}
|
| 62 |
|
84 |
|
| 63 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
85 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 64 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token, Model model) throws Exception{
|
86 |
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.TOKEN) String token, Model model) throws Exception{
|
| 65 |
try{
|
87 |
try{
|
| - |
|
88 |
String emailId = googleTokenUtil.getEmailId(token);
|
| - |
|
89 |
User user = null;
|
| - |
|
90 |
try{
|
| - |
|
91 |
user = userRepository.selectByEmailId(emailId);
|
| - |
|
92 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
93 |
LOGGER.error("User not found with given emailId", profitMandiBusinessException);
|
| - |
|
94 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, request.getContextPath() + "/register"));
|
| - |
|
95 |
return "response";
|
| - |
|
96 |
}
|
| - |
|
97 |
UserAccounts userAccounts = userAccountRepository.getUserAccountByType(user.getId(), AccountType.saholic);
|
| - |
|
98 |
Retailer retailer = retailerRepository.selectById(Integer.parseInt(userAccounts.getAccount_key()));
|
| - |
|
99 |
if(!retailer.isFofo()){
|
| - |
|
100 |
LOGGER.error("Retailer is not fofo, should be registered");
|
| - |
|
101 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, request.getContextPath() + "/register"));
|
| - |
|
102 |
return "response";
|
| - |
|
103 |
}
|
| - |
|
104 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| - |
|
105 |
Set<RoleType> roleTypes = new HashSet<>();
|
| - |
|
106 |
StringBuilder roleNames = new StringBuilder();
|
| - |
|
107 |
for(int index = 0; index < userRoles.size(); index++){
|
| - |
|
108 |
roleTypes.add(userRoles.get(index).getRoleType());
|
| - |
|
109 |
roleNames.append(userRoles.get(index).getRoleType().toString());
|
| - |
|
110 |
if(index + 1 != userRoles.size()){
|
| - |
|
111 |
roleNames.append(",");
|
| - |
|
112 |
}
|
| - |
|
113 |
}
|
| - |
|
114 |
FofoDetails fofoDetails = new FofoDetails();
|
| - |
|
115 |
fofoDetails.setFofoId(retailer.getId());
|
| - |
|
116 |
fofoDetails.setEmailId(emailId);
|
| - |
|
117 |
fofoDetails.setRoleTypes(roleTypes);
|
| 66 |
FofoDetails fofoDetails = googleLoginUtil.getFofoDetail(token);
|
118 |
//FofoDetails fofoDetails = googleTokenUtil.getFofoDetail(token);
|
| 67 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
119 |
Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, String.valueOf(fofoDetails.getFofoId()));
|
| 68 |
cookieFofoId.setDomain(request.getServerName());
|
120 |
cookieFofoId.setDomain(request.getServerName());
|
| 69 |
cookieFofoId.setPath(request.getContextPath());
|
121 |
cookieFofoId.setPath(request.getContextPath());
|
| 70 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId());
|
122 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId());
|
| 71 |
cookieEmailId.setDomain(request.getServerName());
|
123 |
cookieEmailId.setDomain(request.getServerName());
|
| 72 |
cookieEmailId.setPath(request.getContextPath());
|
124 |
cookieEmailId.setPath(request.getContextPath());
|
| - |
|
125 |
Cookie cookieRoleNames = new Cookie(ProfitMandiConstants.ROLE_NAMES, roleNames.toString());
|
| 73 |
response.addCookie(cookieFofoId);
|
126 |
response.addCookie(cookieFofoId);
|
| 74 |
response.addCookie(cookieEmailId);
|
127 |
response.addCookie(cookieEmailId);
|
| - |
|
128 |
response.addCookie(cookieRoleNames);
|
| 75 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
129 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to /dashboard");
|
| 76 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, request.getContextPath() + "/dashboard"));
|
130 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_OK_1002", true, request.getContextPath() + "/dashboard"));
|
| 77 |
return "response";
|
131 |
return "response";
|
| 78 |
// return mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/profitmandi-fofo/dashboard");
|
132 |
// return mvcResponseSender.createResponseString("RTLR_OK_1002", true, "/profitmandi-fofo/dashboard");
|
| 79 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
133 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|