| Line 3... |
Line 3... |
| 3 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.ArrayList;
|
4 |
import java.util.ArrayList;
|
| 5 |
import java.util.HashSet;
|
5 |
import java.util.HashSet;
|
| 6 |
import java.util.List;
|
6 |
import java.util.List;
|
| 7 |
import java.util.Set;
|
7 |
import java.util.Set;
|
| - |
|
8 |
import java.util.stream.Collectors;
|
| 8 |
|
9 |
|
| 9 |
import javax.servlet.http.Cookie;
|
10 |
import javax.servlet.http.Cookie;
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| 11 |
import javax.servlet.http.HttpServletResponse;
|
12 |
import javax.servlet.http.HttpServletResponse;
|
| 12 |
|
13 |
|
| Line 24... |
Line 25... |
| 24 |
import org.springframework.web.bind.annotation.RequestMapping;
|
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 26 |
import org.springframework.web.bind.annotation.RequestParam;
|
27 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 27 |
|
28 |
|
| 28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
30 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 29 |
import com.spice.profitmandi.common.model.Location;
|
31 |
import com.spice.profitmandi.common.model.Location;
|
| 30 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 31 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
33 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 32 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
34 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 33 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
35 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| Line 43... |
Line 45... |
| 43 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
45 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
46 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
47 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 46 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
48 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 47 |
import com.spice.profitmandi.service.AuthService;
|
49 |
import com.spice.profitmandi.service.AuthService;
|
| - |
|
50 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| - |
|
51 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 48 |
import com.spice.profitmandi.web.model.LoginDetails;
|
52 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 49 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
53 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 50 |
import com.spice.profitmandi.web.util.GoogleTokenUtil;
|
54 |
import com.spice.profitmandi.web.util.GoogleTokenUtil;
|
| 51 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
55 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 52 |
|
56 |
|
| Line 58... |
Line 62... |
| 58 |
|
62 |
|
| 59 |
@Autowired
|
63 |
@Autowired
|
| 60 |
private GoogleTokenUtil googleTokenUtil;
|
64 |
private GoogleTokenUtil googleTokenUtil;
|
| 61 |
|
65 |
|
| 62 |
@Autowired
|
66 |
@Autowired
|
| - |
|
67 |
private RoleManager roleManager;
|
| - |
|
68 |
|
| - |
|
69 |
@Autowired
|
| 63 |
private RetailerRepository retailerRepository;
|
70 |
private RetailerRepository retailerRepository;
|
| 64 |
|
71 |
|
| 65 |
@Autowired
|
72 |
@Autowired
|
| - |
|
73 |
private RetailerService retailerService;
|
| - |
|
74 |
|
| - |
|
75 |
@Autowired
|
| 66 |
private UserRepository userRepository;
|
76 |
private UserRepository userRepository;
|
| 67 |
|
77 |
|
| 68 |
@Autowired
|
78 |
@Autowired
|
| 69 |
private UserAccountRepository userAccountRepository;
|
79 |
private UserAccountRepository userAccountRepository;
|
| 70 |
|
80 |
|
| Line 121... |
Line 131... |
| 121 |
@RequestMapping(value = "/", method = RequestMethod.GET)
|
131 |
@RequestMapping(value = "/", method = RequestMethod.GET)
|
| 122 |
public String home() {
|
132 |
public String home() {
|
| 123 |
return "redirect:/login";
|
133 |
return "redirect:/login";
|
| 124 |
}
|
134 |
}
|
| 125 |
|
135 |
|
| - |
|
136 |
@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
|
| - |
|
137 |
public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
|
| - |
|
138 |
@RequestParam int fofoId) throws Exception {
|
| - |
|
139 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
140 |
if(roleManager.isAdmin(fofoDetails.getRoleIds())){
|
| - |
|
141 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| - |
|
142 |
Set<Integer> roleIds = userRoleRepository.selectByUserId(fofoId).stream().map(x->x.getRoleId()).collect(Collectors.toSet());
|
| - |
|
143 |
LoginDetails newFofoDetails = new LoginDetails();
|
| - |
|
144 |
newFofoDetails.setFofoId(fofoId);
|
| - |
|
145 |
newFofoDetails.setRoleIds(roleIds);
|
| - |
|
146 |
newFofoDetails.setEmailId(customRetailer.getEmail());
|
| - |
|
147 |
this.addCookiesToResponse(fofoDetails, request, response);
|
| - |
|
148 |
} else {
|
| - |
|
149 |
throw new ProfitMandiBusinessException("", "", "");
|
| - |
|
150 |
}
|
| - |
|
151 |
return "/dahboard";
|
| - |
|
152 |
}
|
| - |
|
153 |
|
| 126 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
154 |
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
| 127 |
public String login(HttpServletRequest request, HttpServletResponse response,
|
155 |
public String login(HttpServletRequest request, HttpServletResponse response,
|
| 128 |
@RequestParam(name = ProfitMandiConstants.TOKEN) String token,
|
156 |
@RequestParam(name = ProfitMandiConstants.TOKEN) String token,
|
| 129 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER, defaultValue = "") String emailIdOrMobileNumber,
|
157 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER, defaultValue = "") String emailIdOrMobileNumber,
|
| 130 |
@RequestParam(name = "password", defaultValue = "") String password, Model model) throws Exception {
|
158 |
@RequestParam(name = "password", defaultValue = "") String password, Model model) throws Exception {
|
| 131 |
|
159 |
|
| 132 |
LoginDetails fofoDetails = new LoginDetails();
|
160 |
LoginDetails fofoDetails = new LoginDetails();
|
| 133 |
Set<Integer> roleIds = new HashSet<>();
|
161 |
Set<Integer> roleIds = new HashSet<>();
|
| 134 |
fofoDetails.setRoleIds(roleIds);
|
162 |
fofoDetails.setRoleIds(roleIds);
|
| 135 |
String emailId = null;
|
163 |
String emailId = null;
|
| 136 |
String name=null;
|
164 |
String name = null;
|
| 137 |
try {
|
165 |
try {
|
| 138 |
// if role is retailer then FOFO_ID is retailerId else it is userid as normal
|
166 |
// if role is retailer then FOFO_ID is retailerId else it is userid as normal
|
| 139 |
// user's wont have retailer id.
|
167 |
// user's wont have retailer id.
|
| 140 |
if (token == "") {
|
168 |
if (token == "") {
|
| 141 |
if (authService.authenticate(emailIdOrMobileNumber, password)) {
|
169 |
if (authService.authenticate(emailIdOrMobileNumber, password)) {
|
| 142 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailIdOrMobileNumber);
|
170 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailIdOrMobileNumber);
|
| 143 |
if(authUser==null) {
|
171 |
if (authUser == null) {
|
| 144 |
throw new ProfitMandiBusinessException("Authentication", "Email or Mobile", "Invalid Email Or Mobile");
|
172 |
throw new ProfitMandiBusinessException("Authentication", "Email or Mobile",
|
| - |
|
173 |
"Invalid Email Or Mobile");
|
| 145 |
}
|
174 |
}
|
| 146 |
emailId = authUser.getEmailId();
|
175 |
emailId = authUser.getEmailId();
|
| 147 |
name=authUser.getFirstName()+" "+authUser.getLastName();
|
176 |
name = authUser.getFirstName() + " " + authUser.getLastName();
|
| 148 |
authUser.setLastLoginTimestamp(LocalDateTime.now());
|
177 |
authUser.setLastLoginTimestamp(LocalDateTime.now());
|
| 149 |
authRepository.persist(authUser);
|
178 |
authRepository.persist(authUser);
|
| 150 |
}
|
179 |
}
|
| 151 |
|
180 |
|
| 152 |
} else {
|
181 |
} else {
|
| 153 |
emailId = googleTokenUtil.getEmailId(token);
|
182 |
emailId = googleTokenUtil.getEmailId(token);
|
| 154 |
if(ProfitMandiConstants.BLOCKED_EMAILS.contains(emailId)) {
|
183 |
if (ProfitMandiConstants.BLOCKED_EMAILS.contains(emailId)) {
|
| 155 |
}
|
184 |
}
|
| 156 |
}
|
185 |
}
|
| 157 |
fofoDetails.setEmailId(emailId);
|
186 |
fofoDetails.setEmailId(emailId);
|
| 158 |
fofoDetails.setFofoId(-1);
|
187 |
fofoDetails.setFofoId(-1);
|
| 159 |
// fofoDetails.setFofo(false);
|
188 |
// fofoDetails.setFofo(false);
|
| Line 167... |
Line 196... |
| 167 |
try {
|
196 |
try {
|
| 168 |
user = userRepository.selectBySecondryEmailId(emailId);
|
197 |
user = userRepository.selectBySecondryEmailId(emailId);
|
| 169 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
198 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 170 |
LOGGER.error("User not found with given emailId", profitMandiBusinessException);
|
199 |
LOGGER.error("User not found with given emailId", profitMandiBusinessException);
|
| 171 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
200 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
| 172 |
request.getContextPath() + "/login","Email"));
|
201 |
request.getContextPath() + "/login", "Email"));
|
| 173 |
return "response";
|
202 |
return "response";
|
| 174 |
}
|
203 |
}
|
| 175 |
}
|
204 |
}
|
| 176 |
if (user != null) {
|
205 |
if (user != null) {
|
| 177 |
fofoDetails.setFofoId(user.getId());
|
206 |
fofoDetails.setFofoId(user.getId());
|
| Line 213... |
Line 242... |
| 213 |
userRepository.persist(user);
|
242 |
userRepository.persist(user);
|
| 214 |
this.addCookiesToResponse(fofoDetails, request, response);
|
243 |
this.addCookiesToResponse(fofoDetails, request, response);
|
| 215 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
244 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
| 216 |
redirectUrl);
|
245 |
redirectUrl);
|
| 217 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
246 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
| 218 |
request.getContextPath() + redirectUrl,name));
|
247 |
request.getContextPath() + redirectUrl, name));
|
| 219 |
} else {
|
248 |
} else {
|
| 220 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
249 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
| 221 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
250 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
| 222 |
"RTLR_1000");
|
251 |
"RTLR_1000");
|
| 223 |
}
|
252 |
}
|
| Line 227... |
Line 256... |
| 227 |
model.addAttribute("response",
|
256 |
model.addAttribute("response",
|
| 228 |
mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
257 |
mvcResponseSender.createResponseString(profitMandiBusinessException.getCode(), false, "/error"));
|
| 229 |
return "response";
|
258 |
return "response";
|
| 230 |
}
|
259 |
}
|
| 231 |
}
|
260 |
}
|
| 232 |
|
261 |
|
| 233 |
@PostMapping(value = "/forgetPassword")
|
262 |
@PostMapping(value = "/forgetPassword")
|
| - |
|
263 |
public String forgetPasswordPage(
|
| 234 |
public String forgetPasswordPage(@RequestParam(name=ProfitMandiConstants.EMAIL_ID,defaultValue="")String emailId,Model model) throws Exception {
|
264 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID, defaultValue = "") String emailId, Model model)
|
| - |
|
265 |
throws Exception {
|
| 235 |
LOGGER.info(emailId);
|
266 |
LOGGER.info(emailId);
|
| 236 |
authService.resetPassword(emailId);
|
267 |
authService.resetPassword(emailId);
|
| 237 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
268 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 238 |
LOGGER.info("completed");
|
269 |
LOGGER.info("completed");
|
| 239 |
return "response";
|
270 |
return "response";
|
| Line 291... |
Line 322... |
| 291 |
@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
|
322 |
@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
|
| 292 |
public String setLocation(HttpServletRequest request, Model model, @RequestBody Location location)
|
323 |
public String setLocation(HttpServletRequest request, Model model, @RequestBody Location location)
|
| 293 |
throws Exception {
|
324 |
throws Exception {
|
| 294 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
325 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 295 |
boolean response = true;
|
326 |
boolean response = true;
|
| 296 |
try
|
327 |
try {
|
| 297 |
{
|
- |
|
| 298 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
328 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 299 |
if (fs.getLatitude() == null) {
|
329 |
if (fs.getLatitude() == null) {
|
| 300 |
fs.setLatitude(location.getLatitude());
|
330 |
fs.setLatitude(location.getLatitude());
|
| 301 |
fs.setLongitude(location.getLongitude());
|
331 |
fs.setLongitude(location.getLongitude());
|
| 302 |
fofoStoreRepository.persist(fs);
|
332 |
fofoStoreRepository.persist(fs);
|
| 303 |
}
|
333 |
}
|
| 304 |
model.addAttribute("response", response);
|
334 |
model.addAttribute("response", response);
|
| 305 |
}
|
- |
|
| 306 |
catch(Exception e)
|
335 |
} catch (Exception e) {
|
| 307 |
{
|
- |
|
| 308 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
336 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| 309 |
}
|
337 |
}
|
| 310 |
return "response";
|
338 |
return "response";
|
| 311 |
}
|
339 |
}
|
| 312 |
}
|
340 |
}
|