1 package org.roller.presentation.website.actions; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.apache.struts.action.ActionErrors; 6 import org.apache.struts.action.ActionForm; 7 import org.apache.struts.action.ActionForward; 8 import org.apache.struts.action.ActionMapping; 9 import org.apache.struts.action.ActionMessage; 10 import org.apache.struts.action.ActionMessages; 11 import org.roller.RollerException; 12 import org.roller.model.UserManager; 13 import org.roller.pojos.UserData; 14 import org.roller.pojos.WebsiteData; 15 import org.roller.presentation.RollerRequest; 16 import org.roller.presentation.pagecache.PageCacheFilter; 17 import org.roller.presentation.website.formbeans.UserFormEx; 18 import org.roller.util.StringUtils; 19 20 import java.io.IOException ; 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 26 35 public class UserEditAction extends UserBaseAction 36 { 37 private static Log mLogger = 38 LogFactory.getFactory().getInstance(UserEditAction.class); 39 40 42 public ActionForward edit( 43 ActionMapping mapping, 44 ActionForm actionForm, 45 HttpServletRequest request, 46 HttpServletResponse response) 47 throws IOException , ServletException 48 { 49 ActionForward forward = mapping.findForward("editUser.page"); 50 try 51 { 52 RollerRequest rreq = RollerRequest.getRollerRequest(request); 53 if ( rreq.isUserAuthorizedToEdit() ) 54 { 55 UserData ud = rreq.getUser(); 56 request.setAttribute("user",ud); 57 58 UserFormEx form = (UserFormEx)actionForm; 59 form.copyFrom(ud, request.getLocale()); 60 61 form.setPasswordText(null); 63 form.setPasswordConfirm(null); 64 65 loadRequestObjects(request, rreq, ud, form); 66 } 67 else 68 { 69 forward = mapping.findForward("access-denied"); 70 } 71 } 72 catch (Exception e) 73 { 74 mLogger.error("ERROR in action",e); 75 throw new ServletException (e); 76 } 77 78 if (mLogger.isDebugEnabled()) 81 { 82 log.debug("checking for cookieLogin..."); 83 } 84 85 if (request.getSession().getAttribute("cookieLogin") != null) { 86 ActionMessages messages = new ActionMessages(); 87 88 messages.add(ActionMessages.GLOBAL_MESSAGE, 90 new ActionMessage("userSettings.cookieLogin")); 91 saveMessages(request, messages); 92 } 93 94 return forward; 95 } 96 97 99 public ActionForward update( 100 ActionMapping mapping, 101 ActionForm actionForm, 102 HttpServletRequest request, 103 HttpServletResponse response) 104 throws IOException , ServletException 105 { 106 UserFormEx form = (UserFormEx)actionForm; 107 ActionForward forward = mapping.findForward("editUser.page"); 108 ActionMessages msgs = new ActionMessages(); 109 try 110 { 111 RollerRequest rreq = RollerRequest.getRollerRequest(request); 112 if (rreq.isUserAuthorizedToEdit()) 113 { 114 ActionMessages errors = validate(form, new ActionErrors()); 115 if (errors.size() == 0) 116 { 117 UserManager mgr = rreq.getRoller().getUserManager(); 118 UserData data = mgr.getUser( form.getUserName() ); 119 120 rreq.getRoller().setUser(UserData.SYSTEM_USER); 122 123 form.copyTo(data, request.getLocale()); 125 126 if ( !StringUtils.isEmpty(form.getPasswordText()) 128 && !StringUtils.isEmpty(form.getPasswordConfirm())) 129 { 130 try 131 { 132 data.resetPassword(rreq.getRoller(), 133 form.getPasswordText(), 134 form.getPasswordConfirm()); 135 } 136 catch (RollerException e) 137 { 138 msgs.add(ActionMessages.GLOBAL_MESSAGE, 139 new ActionMessage("userSettings.passwordResetError")); 140 } 141 } 142 143 WebsiteData website = mgr.getWebsite(data.getUserName()); 145 website.setEditorTheme(form.getTheme()); 146 website.setLocale(form.getLocale()); 147 website.setTimezone(form.getTimezone()); 148 149 mgr.storeUser( data ); 151 mgr.storeWebsite( website ); 152 rreq.getRoller().commit(); 153 PageCacheFilter.removeFromCache( request,data ); 154 155 msgs.add(null, new ActionMessage("userSettings.saved")); 156 saveMessages(request, msgs); 157 } 158 else 159 { 160 saveErrors(request, errors); 161 } 162 return edit(mapping, actionForm, request, response); 163 } 164 return mapping.findForward("access-denied"); 165 } 166 catch (Exception e) 167 { 168 mLogger.error("ERROR in action",e); 169 throw new ServletException (e); 170 } 171 } 172 173 } 174 175 176 177 178 179 180 | Popular Tags |