1 2 package org.roller.presentation.website.actions; 3 4 import java.io.IOException ; 5 import java.util.List ; 6 7 import javax.servlet.ServletException ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.apache.struts.action.ActionForm; 14 import org.apache.struts.action.ActionForward; 15 import org.apache.struts.action.ActionMapping; 16 import org.apache.struts.action.ActionMessage; 17 import org.apache.struts.action.ActionMessages; 18 import org.roller.RollerException; 19 import org.roller.business.search.operations.RebuildUserIndexOperation; 20 import org.roller.business.search.operations.RemoveUserIndexOperation; 21 import org.roller.model.IndexManager; 22 import org.roller.model.UserManager; 23 import org.roller.pojos.UserData; 24 import org.roller.pojos.WebsiteData; 25 import org.roller.presentation.RollerRequest; 26 import org.roller.presentation.RollerSession; 27 import org.roller.presentation.pagecache.PageCacheFilter; 28 import org.roller.presentation.website.formbeans.UserAdminForm; 29 import org.roller.util.StringUtils; 30 31 32 41 public final class UserAdminAction extends UserBaseAction 42 { 43 private static Log mLogger = 44 LogFactory.getFactory().getInstance(UserAdminAction.class); 45 46 51 public ActionForward edit( 52 ActionMapping mapping, 53 ActionForm actionForm, 54 HttpServletRequest request, 55 HttpServletResponse response) 56 throws IOException , ServletException 57 { 58 ActionForward forward = mapping.findForward("adminUser.page"); 59 ActionMessages msgs = new ActionMessages(); 60 try 61 { 62 RollerRequest rreq = RollerRequest.getRollerRequest(request); 63 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) 64 { 65 UserAdminForm userForm = (UserAdminForm)actionForm; 66 UserManager mgr = rreq.getRoller().getUserManager(); 67 68 if (userForm != null && userForm.getUserName() != null) 69 { 70 UserData user = mgr.getUser( userForm.getUserName(), false ); 71 if (user != null) 72 { 73 userForm.copyFrom(user, request.getLocale()); 74 75 userForm.setPasswordText(null); 77 userForm.setPasswordConfirm(null); 78 79 WebsiteData website = 81 mgr.getWebsite(userForm.getUserName(), false); 82 userForm.setUserEnabled(website.getIsEnabled()); 83 } 84 else 85 { 86 msgs.add(ActionMessages.GLOBAL_MESSAGE, 87 new ActionMessage("userAdmin.invalidNewUserName")); 88 userForm.setUserName(""); 89 } 90 } 91 } 92 else 93 { 94 forward = mapping.findForward("access-denied"); 95 } 96 } 97 catch (Exception e) 98 { 99 mLogger.error("ERROR in action",e); 100 throw new ServletException (e); 101 } 102 103 if (request.getSession().getAttribute("cookieLogin") != null) 104 { 105 msgs.add(ActionMessages.GLOBAL_MESSAGE, 107 new ActionMessage("userAdmin.cookieLogin")); 108 } 109 110 saveMessages(request, msgs); 111 return forward; 112 } 113 114 118 public ActionForward update( 119 ActionMapping mapping, 120 ActionForm actionForm, 121 HttpServletRequest request, 122 HttpServletResponse response) 123 throws IOException , ServletException 124 { 125 ActionForward forward = mapping.findForward("adminUser.page"); 126 ActionMessages msgs = new ActionMessages(); 127 try 128 { 129 RollerRequest rreq = RollerRequest.getRollerRequest(request); 130 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) 131 { 132 UserAdminForm userForm = (UserAdminForm)actionForm; 133 UserManager mgr = rreq.getRoller().getUserManager(); 134 135 rreq.getRoller().setUser(UserData.SYSTEM_USER); 137 138 UserData user = mgr.retrieveUser(userForm.getId()); 139 userForm.copyTo(user, request.getLocale()); 141 if (userForm.getDelete()) 142 { 143 PageCacheFilter.removeFromCache( request, user ); 145 user = deleteUser(mapping, request, rreq, userForm, mgr, user); 146 147 msgs.add(ActionMessages.GLOBAL_MESSAGE, 148 new ActionMessage("userSettings.deleted")); 149 saveMessages(request, msgs); 150 } 151 else 152 { 153 if ( !StringUtils.isEmpty(userForm.getPasswordText()) 155 && !StringUtils.isEmpty(userForm.getPasswordConfirm())) 156 { 157 try 158 { 159 user.resetPassword(rreq.getRoller(), 160 userForm.getPasswordText(), 161 userForm.getPasswordConfirm()); 162 } 163 catch (RollerException e) 164 { 165 msgs.add(ActionMessages.GLOBAL_MESSAGE, 166 new ActionMessage("userSettings.passwordResetError")); 167 } 168 } 169 170 mgr.storeUser( user ); 172 rreq.getRoller().commit(); 173 174 refreshIndexCache(request, rreq, userForm); 176 PageCacheFilter.removeFromCache( request, user ); 177 178 msgs.add(ActionMessages.GLOBAL_MESSAGE, 179 new ActionMessage("userSettings.saved")); 180 saveMessages(request, msgs); 181 } 182 183 userForm.setUserName(null); 185 return edit(mapping, actionForm, request, response); 186 } 187 else 188 { 189 forward = mapping.findForward("access-denied"); 190 } 191 } 192 catch (Exception e) 193 { 194 mLogger.error("ERROR in action",e); 195 throw new ServletException (e); 196 } 197 return forward; 198 } 199 200 202 private UserData deleteUser( 203 ActionMapping mapping, 204 HttpServletRequest request, 205 RollerRequest rreq, 206 UserAdminForm uaf, 207 UserManager mgr, 208 UserData ud) throws RollerException 209 { 210 IndexManager indexManager = rreq.getRoller().getIndexManager(); 212 indexManager.removeUserIndex(ud); 213 214 ud.remove(); 216 rreq.getRoller().commit(); 217 PageCacheFilter.removeFromCache( request, ud ); 218 ud = null; 219 220 request.getSession().setAttribute( 221 RollerSession.STATUS_MESSAGE, 222 uaf.getUserName() + " has been deleted"); 223 224 uaf.reset(mapping, request); 225 226 List users = mgr.getUsers(false); 227 request.setAttribute("users", users); 228 return ud; 229 } 230 231 235 public ActionForward index( 236 ActionMapping mapping, 237 ActionForm actionForm, 238 HttpServletRequest request, 239 HttpServletResponse response) 240 throws IOException , ServletException 241 { 242 try 243 { 244 RollerRequest rreq = RollerRequest.getRollerRequest(request); 245 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) 246 { 247 UserAdminForm uaf = (UserAdminForm)actionForm; 248 249 IndexManager manager = rreq.getRoller().getIndexManager(); 251 manager.rebuildUserIndex(); 252 request.getSession().setAttribute( 253 RollerSession.STATUS_MESSAGE, 254 "Successfully scheduled rebuild of index for '" 255 + uaf.getUserName() + "'"); 256 } 257 } 258 catch (Exception e) 259 { 260 mLogger.error("ERROR in action",e); 261 throw new ServletException (e); 262 } 263 return edit(mapping, actionForm, request, response); 264 } 265 266 } 267 268 | Popular Tags |