View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.web.actions.admin.user;
20  
21  import org.apache.log4j.Logger;
22  import org.apache.struts.action.*;
23  import org.itracker.model.User;
24  import org.itracker.model.util.UserUtilities;
25  import org.itracker.services.UserService;
26  import org.itracker.web.actions.base.ItrackerBaseAction;
27  import org.itracker.web.util.LoginUtilities;
28  import org.itracker.web.util.ServletContextUtils;
29  
30  import javax.servlet.ServletException;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  import java.io.IOException;
34  
35  
36  public class UnlockUserAction extends ItrackerBaseAction {
37      private static final Logger log = Logger.getLogger(UnlockUserAction.class);
38  
39      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40  
41          ActionMessages errors = new ActionMessages();
42  
43          if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
44              log.info("execute: forwarding to unauthorized for " + LoginUtilities.getCurrentUser(request));
45              return mapping.findForward("unauthorized");
46          }
47  
48          try {
49              UserService userService = ServletContextUtils.getItrackerServices().getUserService();
50  
51              Integer userId = Integer.valueOf((request.getParameter("id") == null ? "-1" : (request.getParameter("id"))));
52              User user = userService.getUser(userId);
53              if (log.isInfoEnabled()) {
54                  log.info("Unlocking user " + user + " (id: " + userId + ")");
55              }
56              user.setStatus(UserUtilities.STATUS_ACTIVE);
57              userService.updateUser(user);
58          } catch (Exception e) {
59              log.error("execute: failed with unexpected exception", e);
60              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
61          }
62  
63          if (!errors.isEmpty()) {
64              saveErrors(request, errors);
65          }
66          return mapping.findForward("listusers");
67      }
68  
69  }
70