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 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.log4j.Logger;
28  import org.apache.struts.action.ActionForm;
29  import org.apache.struts.action.ActionForward;
30  import org.apache.struts.action.ActionMapping;
31  import org.apache.struts.action.ActionMessage;
32  import org.apache.struts.action.ActionMessages;
33  import org.itracker.model.User;
34  import org.itracker.services.UserService;
35  import org.itracker.services.util.UserUtilities;
36  import org.itracker.web.actions.base.ItrackerBaseAction;
37  import org.itracker.web.util.LoginUtilities;
38  
39  
40  public class UnlockUserAction extends ItrackerBaseAction {
41  	private static final Logger log = Logger.getLogger(UnlockUserAction.class);
42  
43      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
44  
45      	ActionMessages errors = new ActionMessages();
46  
47          if(! hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
48          	log.info("execute: forwarding to unauthorized for " + LoginUtilities.getCurrentUser(request));
49              return mapping.findForward("unauthorized");
50          }
51  
52          try {
53              UserService userService = getITrackerServices().getUserService();
54  
55              Integer userId = Integer.valueOf((request.getParameter("id") == null ? "-1" : (request.getParameter("id"))));
56              User user = userService.getUser(userId);
57              if (log.isInfoEnabled()) {
58              	log.info("Unlocking user " + user + " (id: " + userId + ")");
59              }
60              user.setStatus(UserUtilities.STATUS_ACTIVE);
61              userService.updateUser(user);
62          } catch (Exception e) {
63          	log.error("execute: failed with unexpected exception", e);
64              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
65          }
66  
67          if(! errors.isEmpty()) {
68          	saveErrors(request, errors);
69          }
70          return mapping.findForward("listusers");
71      }
72  
73  }
74