| Line 17... |
Line 17... |
| 17 |
import org.springframework.stereotype.Controller;
|
17 |
import org.springframework.stereotype.Controller;
|
| 18 |
import org.springframework.transaction.annotation.Transactional;
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
| 19 |
import org.springframework.ui.Model;
|
19 |
import org.springframework.ui.Model;
|
| 20 |
import org.springframework.ui.ModelMap;
|
20 |
import org.springframework.ui.ModelMap;
|
| 21 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
21 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| - |
|
22 |
import org.springframework.web.bind.annotation.PostMapping;
|
| 22 |
import org.springframework.web.bind.annotation.RequestBody;
|
23 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
24 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 24 |
import org.springframework.web.bind.annotation.RequestMethod;
|
25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 25 |
import org.springframework.web.bind.annotation.RequestParam;
|
26 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 26 |
|
27 |
|
| 27 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 28 |
import com.spice.profitmandi.common.model.Location;
|
29 |
import com.spice.profitmandi.common.model.Location;
|
| 29 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
30 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
31 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
32 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 31 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
33 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 32 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
34 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 33 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
35 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 34 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
36 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 35 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
37 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 36 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
38 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 37 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
39 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| - |
|
40 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
41 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
42 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
43 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 41 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
44 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
45 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
46 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| - |
|
47 |
import com.spice.profitmandi.service.AuthService;
|
| 44 |
import com.spice.profitmandi.web.model.LoginDetails;
|
48 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 45 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
49 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 46 |
import com.spice.profitmandi.web.util.GoogleTokenUtil;
|
50 |
import com.spice.profitmandi.web.util.GoogleTokenUtil;
|
| 47 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
51 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 48 |
|
52 |
|
| Line 80... |
Line 84... |
| 80 |
private CookiesProcessor cookiesProcessor;
|
84 |
private CookiesProcessor cookiesProcessor;
|
| 81 |
|
85 |
|
| 82 |
@Value("${google.api.key}")
|
86 |
@Value("${google.api.key}")
|
| 83 |
private String googleApiKey;
|
87 |
private String googleApiKey;
|
| 84 |
|
88 |
|
| - |
|
89 |
@Autowired
|
| - |
|
90 |
private AuthService authService;
|
| - |
|
91 |
|
| - |
|
92 |
@Autowired
|
| - |
|
93 |
private AuthRepository authRepository;
|
| - |
|
94 |
|
| 85 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
95 |
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
| 86 |
public String loginPage(HttpServletRequest request, Model model) throws Exception {
|
96 |
public String loginPage(HttpServletRequest request, Model model) throws Exception {
|
| 87 |
LOGGER.info("Context Path is {}", request.getContextPath());
|
97 |
LOGGER.info("Context Path is {}", request.getContextPath());
|
| 88 |
try {
|
98 |
try {
|
| 89 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
99 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| Line 91... |
Line 101... |
| 91 |
String redirectUrl = null;
|
101 |
String redirectUrl = null;
|
| 92 |
|
102 |
|
| 93 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
103 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 94 |
Role roleFofo = roleRepository.selectByName(RoleType.RETAILER.toString());
|
104 |
Role roleFofo = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 95 |
Role roleFofoAdmin = roleRepository.selectByName(RoleType.RETAILER.toString());
|
105 |
Role roleFofoAdmin = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 96 |
|
- |
|
| 97 |
if ((fofoDetails.getRoleIds().contains(roleRetailer.getId())
|
106 |
if ((fofoDetails.getRoleIds().contains(roleRetailer.getId())
|
| 98 |
&& fofoDetails.getRoleIds().contains(roleFofo.getId())
|
107 |
&& fofoDetails.getRoleIds().contains(roleFofo.getId())
|
| 99 |
|| (fofoDetails.getRoleIds().contains(roleFofoAdmin.getId())))) {
|
108 |
|| (fofoDetails.getRoleIds().contains(roleFofoAdmin.getId())))) {
|
| 100 |
redirectUrl = "/dashboard";
|
109 |
redirectUrl = "/dashboard";
|
| 101 |
} else {
|
110 |
} else {
|
| Line 114... |
Line 123... |
| 114 |
return "redirect:/login";
|
123 |
return "redirect:/login";
|
| 115 |
}
|
124 |
}
|
| 116 |
|
125 |
|
| 117 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
126 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 118 |
public String login(HttpServletRequest request, HttpServletResponse response,
|
127 |
public String login(HttpServletRequest request, HttpServletResponse response,
|
| - |
|
128 |
@RequestParam(name = ProfitMandiConstants.TOKEN) String token,
|
| - |
|
129 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER, defaultValue = "") String emailIdOrMobileNumber,
|
| 119 |
@RequestParam(name = ProfitMandiConstants.TOKEN) String token, Model model) throws Exception {
|
130 |
@RequestParam(name = "password", defaultValue = "") String password, Model model) throws Exception {
|
| - |
|
131 |
|
| 120 |
LoginDetails fofoDetails = new LoginDetails();
|
132 |
LoginDetails fofoDetails = new LoginDetails();
|
| 121 |
Set<Integer> roleIds = new HashSet<>();
|
133 |
Set<Integer> roleIds = new HashSet<>();
|
| 122 |
fofoDetails.setRoleIds(roleIds);
|
134 |
fofoDetails.setRoleIds(roleIds);
|
| - |
|
135 |
String emailId = null;
|
| - |
|
136 |
String name=null;
|
| 123 |
// fofoDetails.setFofo(false);
|
137 |
// fofoDetails.setFofo(false);
|
| 124 |
|
138 |
|
| 125 |
try {
|
139 |
try {
|
| 126 |
// if role is retailer then FOFO_ID is retailerId else it is userid as normal
|
140 |
// if role is retailer then FOFO_ID is retailerId else it is userid as normal
|
| 127 |
// user's wont have retailer id.
|
141 |
// user's wont have retailer id.
|
| - |
|
142 |
if (token == "") {
|
| - |
|
143 |
if (authService.authenticate(emailIdOrMobileNumber, password)) {
|
| - |
|
144 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailIdOrMobileNumber);
|
| - |
|
145 |
if(authUser==null) {
|
| - |
|
146 |
throw new ProfitMandiBusinessException("Authentication", "Email or Mobile", "Invalid Email Or Mobile");
|
| - |
|
147 |
}
|
| - |
|
148 |
emailId = authUser.getEmailId();
|
| - |
|
149 |
name=authUser.getFirstName()+" "+authUser.getLastName();
|
| - |
|
150 |
authUser.setLastLoginTimestamp(LocalDateTime.now());
|
| - |
|
151 |
authRepository.persist(authUser);
|
| - |
|
152 |
}
|
| - |
|
153 |
|
| - |
|
154 |
} else {
|
| 128 |
String emailId = googleTokenUtil.getEmailId(token);
|
155 |
emailId = googleTokenUtil.getEmailId(token);
|
| - |
|
156 |
}
|
| 129 |
fofoDetails.setEmailId(emailId);
|
157 |
fofoDetails.setEmailId(emailId);
|
| 130 |
fofoDetails.setFofoId(-1);
|
158 |
fofoDetails.setFofoId(-1);
|
| 131 |
// fofoDetails.setFofo(false);
|
159 |
// fofoDetails.setFofo(false);
|
| 132 |
User user = null;
|
160 |
User user = null;
|
| 133 |
try {
|
161 |
try {
|
| Line 182... |
Line 210... |
| 182 |
userRepository.persist(user);
|
210 |
userRepository.persist(user);
|
| 183 |
this.addCookiesToResponse(fofoDetails, request, response);
|
211 |
this.addCookiesToResponse(fofoDetails, request, response);
|
| 184 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
212 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
| 185 |
redirectUrl);
|
213 |
redirectUrl);
|
| 186 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
214 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
| 187 |
request.getContextPath() + redirectUrl));
|
215 |
request.getContextPath() + redirectUrl,name));
|
| 188 |
} else {
|
216 |
} else {
|
| 189 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
217 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
| 190 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
218 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
| 191 |
"RTLR_1000");
|
219 |
"RTLR_1000");
|
| 192 |
}
|
220 |
}
|
| Line 196... |
Line 224... |
| 196 |
model.addAttribute("response",
|
224 |
model.addAttribute("response",
|
| 197 |
mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
225 |
mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
| 198 |
return "response";
|
226 |
return "response";
|
| 199 |
}
|
227 |
}
|
| 200 |
}
|
228 |
}
|
| - |
|
229 |
|
| - |
|
230 |
@PostMapping(value = "/forgetPassword")
|
| - |
|
231 |
public String forgetPasswordPage(@RequestParam(name=ProfitMandiConstants.EMAIL_ID,defaultValue="")String emailId,Model model) throws Exception {
|
| - |
|
232 |
LOGGER.info(emailId);
|
| - |
|
233 |
authService.resetPassword(emailId);
|
| - |
|
234 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
235 |
LOGGER.info("completed");
|
| - |
|
236 |
return "response";
|
| - |
|
237 |
}
|
| 201 |
|
238 |
|
| 202 |
private void addCookiesToResponse(LoginDetails fofoDetails, HttpServletRequest request,
|
239 |
private void addCookiesToResponse(LoginDetails fofoDetails, HttpServletRequest request,
|
| 203 |
HttpServletResponse response) {
|
240 |
HttpServletResponse response) {
|
| 204 |
List<String> roleIds = new ArrayList<>();
|
241 |
List<String> roleIds = new ArrayList<>();
|
| 205 |
|
242 |
|
| Line 251... |
Line 288... |
| 251 |
@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
|
288 |
@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
|
| 252 |
public String setLocation(HttpServletRequest request, Model model, @RequestBody Location location)
|
289 |
public String setLocation(HttpServletRequest request, Model model, @RequestBody Location location)
|
| 253 |
throws Exception {
|
290 |
throws Exception {
|
| 254 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
291 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 255 |
boolean response = true;
|
292 |
boolean response = true;
|
| - |
|
293 |
try
|
| - |
|
294 |
{
|
| 256 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
295 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 257 |
if (fs.getLatitude() == null) {
|
296 |
if (fs.getLatitude() == null) {
|
| 258 |
fs.setLatitude(location.getLatitude());
|
297 |
fs.setLatitude(location.getLatitude());
|
| 259 |
fs.setLongitude(location.getLongitude());
|
298 |
fs.setLongitude(location.getLongitude());
|
| 260 |
fofoStoreRepository.persist(fs);
|
299 |
fofoStoreRepository.persist(fs);
|
| 261 |
}
|
300 |
}
|
| 262 |
model.addAttribute("response", response);
|
301 |
model.addAttribute("response", response);
|
| - |
|
302 |
}
|
| - |
|
303 |
catch(Exception e)
|
| - |
|
304 |
{
|
| - |
|
305 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| - |
|
306 |
}
|
| 263 |
return "response";
|
307 |
return "response";
|
| 264 |
}
|
308 |
}
|
| 265 |
}
|
309 |
}
|