| 24383 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 37127 |
amit |
5 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 24383 |
amit.gupta |
6 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 37127 |
amit |
7 |
import com.spice.profitmandi.dao.model.PasswordOverrideRow;
|
| 27806 |
tejbeer |
8 |
import com.spice.profitmandi.dao.entity.cs.PartnerPosition;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 24383 |
amit.gupta |
10 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 32493 |
amit.gupta |
14 |
import com.spice.profitmandi.dao.repository.cs.PartnerPositionRepository;
|
| 27806 |
tejbeer |
15 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 24383 |
amit.gupta |
16 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 37127 |
amit |
19 |
import com.spice.profitmandi.dao.repository.devtools.PasswordOverrideRepository;
|
| 24383 |
amit.gupta |
20 |
import com.spice.profitmandi.service.AuthService;
|
| 37105 |
amit |
21 |
import com.spice.profitmandi.service.user.UserService;
|
| 24383 |
amit.gupta |
22 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
23 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 29209 |
manish |
24 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 31238 |
amit.gupta |
25 |
import org.apache.logging.log4j.LogManager;
|
|
|
26 |
import org.apache.logging.log4j.Logger;
|
|
|
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
28 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 37105 |
amit |
29 |
import org.springframework.beans.factory.annotation.Value;
|
| 37127 |
amit |
30 |
import org.springframework.core.io.InputStreamResource;
|
|
|
31 |
import org.springframework.http.HttpHeaders;
|
|
|
32 |
import org.springframework.http.HttpStatus;
|
|
|
33 |
import org.springframework.http.ResponseEntity;
|
| 31238 |
amit.gupta |
34 |
import org.springframework.stereotype.Controller;
|
|
|
35 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
36 |
import org.springframework.ui.Model;
|
|
|
37 |
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
38 |
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
39 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 37127 |
amit |
40 |
import org.springframework.web.bind.annotation.RequestPart;
|
|
|
41 |
import org.springframework.web.multipart.MultipartFile;
|
| 24383 |
amit.gupta |
42 |
|
| 31238 |
amit.gupta |
43 |
import javax.servlet.http.HttpServletRequest;
|
|
|
44 |
import java.time.LocalDateTime;
|
| 37127 |
amit |
45 |
import java.util.ArrayList;
|
| 31238 |
amit.gupta |
46 |
import java.util.HashMap;
|
|
|
47 |
import java.util.List;
|
|
|
48 |
import java.util.Map;
|
| 33065 |
raveendra. |
49 |
import java.util.stream.Collectors;
|
| 31238 |
amit.gupta |
50 |
|
| 24383 |
amit.gupta |
51 |
@Controller
|
| 25192 |
tejbeer |
52 |
@Transactional(rollbackFor = Throwable.class)
|
| 24383 |
amit.gupta |
53 |
public class AuthUserController {
|
|
|
54 |
|
|
|
55 |
private static final Logger LOGGER = LogManager.getLogger(AuthUserController.class);
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
private AuthService authService;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
| 37105 |
amit |
61 |
private UserService userService;
|
|
|
62 |
|
| 37127 |
amit |
63 |
@Autowired
|
|
|
64 |
private PasswordOverrideRepository passwordOverrideRepository;
|
|
|
65 |
|
| 37105 |
amit |
66 |
@Value("${prod}")
|
|
|
67 |
private boolean isProd;
|
|
|
68 |
|
|
|
69 |
@Autowired
|
| 24383 |
amit.gupta |
70 |
private AuthRepository authRepository;
|
|
|
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private UserRepository userRepository;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private RoleRepository roleRepository;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
| 29209 |
manish |
79 |
private MVCResponseSender mvcResponseSender;
|
|
|
80 |
|
|
|
81 |
@Autowired
|
| 24383 |
amit.gupta |
82 |
private UserRoleRepository userRoleRepository;
|
|
|
83 |
|
|
|
84 |
@Autowired
|
|
|
85 |
private CookiesProcessor cookiesProcessor;
|
|
|
86 |
|
|
|
87 |
@Autowired
|
| 27806 |
tejbeer |
88 |
private PositionRepository positionRepository;
|
|
|
89 |
|
|
|
90 |
@Autowired
|
| 32493 |
amit.gupta |
91 |
private PartnerPositionRepository partnerPositionRepository;
|
| 27806 |
tejbeer |
92 |
|
|
|
93 |
@Autowired
|
| 24383 |
amit.gupta |
94 |
@Qualifier("userUserRepository")
|
|
|
95 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
|
|
96 |
|
| 33065 |
raveendra. |
97 |
|
| 24383 |
amit.gupta |
98 |
@GetMapping(value = "/createAuthUser")
|
|
|
99 |
public String getcreateAuthUser(HttpServletRequest request,
|
|
|
100 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 33066 |
raveendra. |
101 |
@RequestParam(name = "limit", defaultValue = "0") int limit, Model model)
|
| 24383 |
amit.gupta |
102 |
throws ProfitMandiBusinessException {
|
| 25570 |
tejbeer |
103 |
// List<AuthUser> authUsers = authRepository.selectAll(offset, limit);
|
| 29209 |
manish |
104 |
List<AuthUser> activeAuthUsers = authRepository.selectAllActiveUser();
|
| 33066 |
raveendra. |
105 |
//List<AuthUser> authUsers = activeAuthUsers.stream().skip(offset).limit(limit).collect(Collectors.toList());
|
|
|
106 |
List<AuthUser> authUsers = activeAuthUsers.stream().skip(offset).collect(Collectors.toList());
|
| 29209 |
manish |
107 |
|
| 33065 |
raveendra. |
108 |
Map<Integer, AuthUser> userManagerMap = activeAuthUsers.stream()
|
|
|
109 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 33103 |
amit.gupta |
110 |
|
| 33065 |
raveendra. |
111 |
long size = activeAuthUsers.size();
|
| 29209 |
manish |
112 |
model.addAttribute("userManagerMap", userManagerMap);
|
|
|
113 |
model.addAttribute("activeAuthUsers", activeAuthUsers);
|
| 24383 |
amit.gupta |
114 |
model.addAttribute("authUsers", authUsers);
|
|
|
115 |
model.addAttribute("start", offset + 1);
|
|
|
116 |
model.addAttribute("size", size);
|
| 29209 |
manish |
117 |
model.addAttribute("url", "/getPaginatedAuthUser");
|
| 32559 |
amit.gupta |
118 |
|
| 24383 |
amit.gupta |
119 |
if (authUsers.size() < limit) {
|
|
|
120 |
model.addAttribute("end", offset + authUsers.size());
|
|
|
121 |
} else {
|
|
|
122 |
model.addAttribute("end", offset + limit);
|
|
|
123 |
}
|
| 29209 |
manish |
124 |
|
| 24383 |
amit.gupta |
125 |
return "create-auth-user";
|
|
|
126 |
|
|
|
127 |
}
|
| 29209 |
manish |
128 |
@PostMapping(value = "/addManagerId")
|
|
|
129 |
public String addManagerId(HttpServletRequest request, @RequestParam(name = "authId") int authId,
|
|
|
130 |
@RequestParam(name = "managerId") int managerId, Model model) throws Exception {
|
|
|
131 |
// List<AuthUser> authUsers = authRepository.selectAll(offset, limit);
|
|
|
132 |
AuthUser authUser = authRepository.selectById(authId);
|
|
|
133 |
|
|
|
134 |
if (authUser.getId() != 0) {
|
|
|
135 |
|
|
|
136 |
authUser.setManagerId(managerId);
|
|
|
137 |
}
|
|
|
138 |
List<AuthUser> activeAuthUsers = authRepository.selectAllActiveUser();
|
|
|
139 |
|
|
|
140 |
AuthUser manager = authRepository.selectById(authUser.getManagerId());
|
|
|
141 |
|
|
|
142 |
model.addAttribute("activeAuthUsers", activeAuthUsers);
|
|
|
143 |
model.addAttribute("authUser", authUser);
|
|
|
144 |
model.addAttribute("manager", manager);
|
|
|
145 |
|
|
|
146 |
return "create-auth-user";
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
|
| 24383 |
amit.gupta |
150 |
@PostMapping(value = "/createAuthUser")
|
|
|
151 |
public String createAuthUser(HttpServletRequest request,
|
|
|
152 |
@RequestParam(name = ProfitMandiConstants.FIRST_NAME, defaultValue = "") String firstName,
|
|
|
153 |
@RequestParam(name = ProfitMandiConstants.LAST_NAME, defaultValue = "") String lastName,
|
|
|
154 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID, defaultValue = "") String emailId,
|
|
|
155 |
@RequestParam(name = ProfitMandiConstants.MOBILE_NUMBER, defaultValue = "") String mobileNumber,
|
| 25366 |
tejbeer |
156 |
@RequestParam(name = ProfitMandiConstants.GMAIL_ID, defaultValue = "") String gmailId,
|
| 27595 |
tejbeer |
157 |
@RequestParam(name = "employeeCode", defaultValue = "") String employeeCode,
|
| 32463 |
jai.hind |
158 |
@RequestParam(name = "imageUrl", defaultValue = "") String imageUrl,
|
|
|
159 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 33066 |
raveendra. |
160 |
@RequestParam(name = "limit", defaultValue = "0") int limit, Model model)
|
| 24383 |
amit.gupta |
161 |
throws ProfitMandiBusinessException {
|
|
|
162 |
AuthUser authUser = null;
|
|
|
163 |
User user = null;
|
|
|
164 |
List<Role> roles = roleRepository.selectAll();
|
|
|
165 |
try {
|
|
|
166 |
user = userRepository.selectByEmailId(emailId);
|
|
|
167 |
userRoleRepository.deleteByUserId(user.getId());
|
|
|
168 |
for (Role role : roles) {
|
|
|
169 |
UserRole userRole = new UserRole();
|
|
|
170 |
userRole.setRoleId(role.getId());
|
|
|
171 |
userRole.setUserId(user.getId());
|
|
|
172 |
userRoleRepository.persist(userRole);
|
|
|
173 |
}
|
|
|
174 |
} catch (Exception ex) {
|
|
|
175 |
user = new User();
|
|
|
176 |
user.setFirstName(firstName);
|
|
|
177 |
user.setLastName(lastName);
|
|
|
178 |
user.setUsername(emailId);
|
|
|
179 |
user.setEmailId(emailId);
|
|
|
180 |
user.setPassword("");
|
|
|
181 |
user.setMobileNumber(mobileNumber);
|
|
|
182 |
user.setCity("Noida");
|
|
|
183 |
user.setPinCode(201301);
|
|
|
184 |
user.setActivated(true);
|
|
|
185 |
user.setMobile_verified(true);
|
|
|
186 |
user.setReferral_url("");
|
|
|
187 |
user.setUpdateTimestamp(LocalDateTime.now());
|
|
|
188 |
user.setStatus(0);
|
|
|
189 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
190 |
userRepository.persist(user);
|
|
|
191 |
LOGGER.info("User created successfully");
|
|
|
192 |
for (Role role : roles) {
|
|
|
193 |
UserRole userRole = new UserRole();
|
|
|
194 |
userRole.setRoleId(role.getId());
|
|
|
195 |
userRole.setUserId(user.getId());
|
|
|
196 |
userRoleRepository.persist(userRole);
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
authUser = new AuthUser();
|
|
|
200 |
authUser.setEmailId(emailId);
|
|
|
201 |
authUser.setFirstName(firstName);
|
|
|
202 |
authUser.setLastName(lastName);
|
|
|
203 |
authUser.setMobileNumber(mobileNumber);
|
| 25366 |
tejbeer |
204 |
authUser.setGmailId(gmailId);
|
| 32463 |
jai.hind |
205 |
authUser.setImageUrl(imageUrl);
|
| 27595 |
tejbeer |
206 |
authUser.setEmployeeCode(employeeCode);
|
| 25587 |
tejbeer |
207 |
authUser.setActive(true);
|
| 25570 |
tejbeer |
208 |
|
| 24383 |
amit.gupta |
209 |
authUser.setCreatedTimestamp(LocalDateTime.now());
|
|
|
210 |
authService.addAuthUser(authUser);
|
|
|
211 |
|
|
|
212 |
List<AuthUser> authUsers = authRepository.selectAll(offset, limit);
|
|
|
213 |
long size = authRepository.selectCountAuthUser();
|
|
|
214 |
model.addAttribute("authUsers", authUsers);
|
|
|
215 |
model.addAttribute("start", offset + 1);
|
|
|
216 |
model.addAttribute("size", size);
|
|
|
217 |
if (authUsers.size() < limit) {
|
|
|
218 |
model.addAttribute("end", offset + authUsers.size());
|
|
|
219 |
} else {
|
|
|
220 |
model.addAttribute("end", offset + limit);
|
|
|
221 |
}
|
|
|
222 |
return "create-auth-user";
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
@GetMapping(value = "/changePassword")
|
|
|
226 |
public String getChangePassword(HttpServletRequest request, Model model) {
|
|
|
227 |
return "change-auth-user-password";
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
@PostMapping(value = "/changePassword")
|
|
|
231 |
public String changePassword(HttpServletRequest request,
|
|
|
232 |
@RequestParam(name = "oldPassword", defaultValue = "") String oldPassword,
|
|
|
233 |
@RequestParam(name = "newPassword", defaultValue = "") String newPassword, Model model)
|
|
|
234 |
throws ProfitMandiBusinessException {
|
|
|
235 |
|
|
|
236 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
237 |
authService.changePassword(loginDetails.getEmailId(), oldPassword, newPassword);
|
|
|
238 |
return "change-auth-user-password";
|
|
|
239 |
}
|
|
|
240 |
|
| 37105 |
amit |
241 |
@GetMapping(value = "/resetPasswordPage")
|
|
|
242 |
public String getResetPasswordPage(HttpServletRequest request, Model model) {
|
|
|
243 |
return "reset-password";
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
@PostMapping(value = "/resetPasswordOverride")
|
|
|
247 |
public String resetPasswordOverride(HttpServletRequest request,
|
|
|
248 |
@RequestParam(name = "type", defaultValue = "") String type,
|
|
|
249 |
@RequestParam(name = "identifier", defaultValue = "") String identifier,
|
|
|
250 |
@RequestParam(name = "retailerId", defaultValue = "0") int retailerId,
|
|
|
251 |
@RequestParam(name = "newPassword", defaultValue = "") String newPassword, Model model)
|
|
|
252 |
throws Exception {
|
|
|
253 |
if (isProd) {
|
|
|
254 |
throw new ProfitMandiBusinessException("Access Denied", "Environment",
|
|
|
255 |
"Password override is disabled in production");
|
|
|
256 |
}
|
| 37127 |
amit |
257 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
258 |
applyOverride(type, retailerId, identifier, newPassword, loginDetails.getEmailId());
|
|
|
259 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
260 |
return "response";
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
// Reset one target's live password and record it in devtools.password_override.
|
|
|
264 |
private void applyOverride(String type, int retailerId, String identifier, String newPassword, String setBy)
|
|
|
265 |
throws ProfitMandiBusinessException {
|
|
|
266 |
if (newPassword == null || newPassword.trim().isEmpty()) {
|
| 37105 |
amit |
267 |
throw new ProfitMandiBusinessException("Password", "newPassword", "New password cannot be blank");
|
|
|
268 |
}
|
|
|
269 |
if ("PARTNER".equalsIgnoreCase(type)) {
|
|
|
270 |
if (retailerId <= 0) {
|
|
|
271 |
throw new ProfitMandiBusinessException("Partner", "retailerId", "Please select a partner");
|
|
|
272 |
}
|
| 37127 |
amit |
273 |
String stored = userService.resetPasswordById(retailerId, newPassword);
|
|
|
274 |
passwordOverrideRepository.upsert("PARTNER", 0, retailerId,
|
|
|
275 |
identifier == null ? "" : identifier.trim(), stored, newPassword, setBy);
|
|
|
276 |
LOGGER.info("Password override for partner retailerId={} by {}", retailerId, setBy);
|
| 37105 |
amit |
277 |
} else {
|
| 37127 |
amit |
278 |
if (identifier == null || identifier.trim().isEmpty()) {
|
| 37105 |
amit |
279 |
throw new ProfitMandiBusinessException("Auth User", "identifier", "Please enter an email or mobile");
|
|
|
280 |
}
|
|
|
281 |
authService.resetPassword(identifier.trim(), newPassword);
|
| 37127 |
amit |
282 |
AuthUser authUser = authRepository.selectByEmailOrMobile(identifier.trim());
|
|
|
283 |
passwordOverrideRepository.upsert("AUTH_USER", authUser.getId(), 0, identifier.trim(),
|
|
|
284 |
authUser.getPassword(), newPassword, setBy);
|
|
|
285 |
LOGGER.info("Password override for authUser={} by {}", identifier.trim(), setBy);
|
| 37105 |
amit |
286 |
}
|
| 37127 |
amit |
287 |
}
|
|
|
288 |
|
|
|
289 |
@GetMapping(value = "/passwordOverride/download")
|
|
|
290 |
public ResponseEntity<?> downloadPasswordOverrides(HttpServletRequest request) throws Exception {
|
|
|
291 |
if (isProd) {
|
|
|
292 |
throw new ProfitMandiBusinessException("Access Denied", "Environment",
|
|
|
293 |
"Password override is disabled in production");
|
|
|
294 |
}
|
|
|
295 |
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
|
|
296 |
ExcelUtils.writePasswordOverrides(passwordOverrideRepository.selectAll(), out);
|
|
|
297 |
byte[] bytes = out.toByteArray();
|
|
|
298 |
HttpHeaders headers = new HttpHeaders();
|
|
|
299 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
300 |
headers.set("Content-disposition", "attachment; filename=password-overrides.xlsx");
|
|
|
301 |
headers.setContentLength(bytes.length);
|
|
|
302 |
return new ResponseEntity<>(new InputStreamResource(new java.io.ByteArrayInputStream(bytes)), headers,
|
|
|
303 |
HttpStatus.OK);
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
@PostMapping(value = "/passwordOverride/upload")
|
|
|
307 |
public String uploadPasswordOverrides(HttpServletRequest request,
|
|
|
308 |
@RequestPart("file") MultipartFile file, Model model) throws Exception {
|
|
|
309 |
if (isProd) {
|
|
|
310 |
throw new ProfitMandiBusinessException("Access Denied", "Environment",
|
|
|
311 |
"Password override is disabled in production");
|
|
|
312 |
}
|
|
|
313 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
314 |
List<PasswordOverrideRow> rows = ExcelUtils.parsePasswordOverrides(file.getInputStream());
|
|
|
315 |
int applied = 0;
|
|
|
316 |
List<String> failures = new ArrayList<>();
|
|
|
317 |
for (int i = 0; i < rows.size(); i++) {
|
|
|
318 |
PasswordOverrideRow r = rows.get(i);
|
|
|
319 |
if (r.getCleartextPassword() == null || r.getCleartextPassword().trim().isEmpty()) {
|
|
|
320 |
continue; // blank password = leave this target unchanged
|
|
|
321 |
}
|
|
|
322 |
try {
|
|
|
323 |
int retailerId = "PARTNER".equalsIgnoreCase(r.getType()) ? r.getRetailerId() : 0;
|
|
|
324 |
applyOverride(r.getType(), retailerId, r.getIdentifier(), r.getCleartextPassword(),
|
|
|
325 |
loginDetails.getEmailId());
|
|
|
326 |
applied++;
|
|
|
327 |
} catch (Exception e) {
|
|
|
328 |
failures.add("Row " + (i + 2) + " (" + r.getType() + " "
|
|
|
329 |
+ (r.getIdentifier() == null ? r.getRetailerId() : r.getIdentifier()) + "): " + e.getMessage());
|
|
|
330 |
}
|
|
|
331 |
}
|
|
|
332 |
LOGGER.info("Bulk password override by {}: {} applied, {} failed", loginDetails.getEmailId(), applied,
|
|
|
333 |
failures.size());
|
|
|
334 |
model.addAttribute("response1", mvcResponseSender.createResponseString(
|
|
|
335 |
"Applied " + applied + " of " + rows.size() + " row(s)."
|
|
|
336 |
+ (failures.isEmpty() ? "" : " Failures: " + String.join("; ", failures))));
|
| 37105 |
amit |
337 |
return "response";
|
|
|
338 |
}
|
|
|
339 |
|
| 24383 |
amit.gupta |
340 |
@GetMapping(value = "/getPaginatedAuthUser")
|
|
|
341 |
public String getPaginatedAuthUser(HttpServletRequest request,
|
|
|
342 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
343 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 27806 |
tejbeer |
344 |
// List<AuthUser> authUsers = authRepository.selectAll(offset, limit);
|
| 29209 |
manish |
345 |
|
|
|
346 |
List<AuthUser> activeAuthUsers = authRepository.selectAllActiveUser();
|
|
|
347 |
|
| 25570 |
tejbeer |
348 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser(offset, limit);
|
| 29209 |
manish |
349 |
|
|
|
350 |
Map<Integer, AuthUser> userManagerMap = new HashMap<>();
|
|
|
351 |
|
|
|
352 |
for (AuthUser authUser : authUsers) {
|
|
|
353 |
if (authUser.getManagerId() != 0) {
|
|
|
354 |
userManagerMap.put(authUser.getId(), authRepository.selectById(authUser.getManagerId()));
|
|
|
355 |
}
|
|
|
356 |
}
|
|
|
357 |
model.addAttribute("userManagerMap", userManagerMap);
|
| 24383 |
amit.gupta |
358 |
model.addAttribute("authUsers", authUsers);
|
| 29209 |
manish |
359 |
model.addAttribute("activeAuthUsers", activeAuthUsers);
|
|
|
360 |
model.addAttribute("url", "/getPaginatedAuthUser");
|
| 24383 |
amit.gupta |
361 |
return "auth-users-paginated";
|
|
|
362 |
}
|
| 25570 |
tejbeer |
363 |
|
|
|
364 |
@GetMapping(value = "/authuser/edit")
|
|
|
365 |
public String updateAuthUser(Model model, @RequestParam String gmailId, @RequestParam String emailId)
|
|
|
366 |
throws Exception {
|
| 24478 |
amit.gupta |
367 |
AuthUser user = authRepository.selectByEmailOrMobile(emailId);
|
|
|
368 |
user.setGmailId(gmailId);
|
| 32559 |
amit.gupta |
369 |
//authRepository.persist(user);
|
| 31238 |
amit.gupta |
370 |
model.addAttribute("response1", "true");
|
| 24478 |
amit.gupta |
371 |
return "response";
|
|
|
372 |
}
|
| 32463 |
jai.hind |
373 |
@GetMapping(value = "/authuser/editImageUrl")
|
|
|
374 |
public String updateAuthUserImage(Model model, @RequestParam String imageUrl ,@RequestParam String emailId)
|
|
|
375 |
throws Exception{
|
|
|
376 |
AuthUser user = authRepository.selectByEmailOrMobile(emailId);
|
|
|
377 |
user.setImageUrl(imageUrl);
|
|
|
378 |
model.addAttribute("response1", "true");
|
|
|
379 |
return "response";
|
|
|
380 |
}
|
| 27595 |
tejbeer |
381 |
|
| 25570 |
tejbeer |
382 |
@PostMapping(value = "/authuser/remove")
|
| 27595 |
tejbeer |
383 |
public String removeAuthUser(Model model, @RequestParam int id) throws Exception {
|
| 25570 |
tejbeer |
384 |
AuthUser user = authRepository.selectById(id);
|
| 27806 |
tejbeer |
385 |
|
| 25570 |
tejbeer |
386 |
user.setActive(false);
|
| 35395 |
amit |
387 |
List<Position> positions = positionRepository.selectAllByAuthUserId(user.getId());
|
| 27806 |
tejbeer |
388 |
for (Position position : positions) {
|
|
|
389 |
List<PartnerPosition> partnerPositions = partnerPositionRepository.selectByPositionId(position.getId());
|
|
|
390 |
positionRepository.delete(position.getId());
|
|
|
391 |
for (PartnerPosition partnerPosition : partnerPositions) {
|
|
|
392 |
partnerPositionRepository.delete(partnerPosition.getPositionId());
|
|
|
393 |
}
|
|
|
394 |
}
|
| 31238 |
amit.gupta |
395 |
model.addAttribute("response1", "true");
|
| 25570 |
tejbeer |
396 |
return "response";
|
|
|
397 |
}
|
| 25366 |
tejbeer |
398 |
|
| 24383 |
amit.gupta |
399 |
}
|