1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.admin.user;
20
21 import java.io.IOException;
22
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionMessages;
32 import org.itracker.model.User;
33 import org.itracker.services.UserService;
34 import org.itracker.services.util.UserUtilities;
35 import org.itracker.web.actions.base.ItrackerBaseAction;
36 import org.itracker.web.util.SessionManager;
37
38
39 public class LockUserAction extends ItrackerBaseAction {
40
41
42 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
43 ActionMessages errors = new ActionMessages();
44
45 if(! hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
46 return mapping.findForward("unauthorized");
47 }
48
49 try {
50 UserService userService = getITrackerServices().getUserService();
51
52 Integer userId = Integer.valueOf((request.getParameter("id") == null ? "-1" : (request.getParameter("id"))));
53 User user = userService.getUser(userId);
54 user.setStatus(UserUtilities.STATUS_LOCKED);
55
56 if(user.getStatus() == UserUtilities.STATUS_LOCKED) {
57 userService.clearOwnedProjects(user);
58 if(SessionManager.getSessionStart(user.getLogin()) != null) {
59 SessionManager.setSessionNeedsReset(user.getLogin());
60 }
61 }
62 } catch(Exception e) {
63 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
64 }
65
66 if(! errors.isEmpty()) {
67 saveErrors(request, errors);
68 }
69 return mapping.findForward("listusers");
70 }
71
72 }
73