On 5/2/07, benjamin servant <[EMAIL PROTECTED]> wrote:
Sorry to insist guys but I really need to know how I can get the username or
the fullame of the current logged in user. So, has anyone any ideas on which
data object I should use??? (something that replaced $user.userName, but still
work with roller 3.0).
_________________________________________________________________
Exprimez-vous : créez la page d'accueil qui vous ressemble avec Live.com.
http://www.live.com/getstarted
I don't believe there is a replacement for $user in the Roller 3.0
models. It's not necessarily a bad idea, so perhaps we can add
$utils.authenticatedUser in the future.
For now, if you need that functionality now one way to get it is to
add your own "model" plugin to Roller. For example, this is a model
class that returns the currently authenticated user via
$authenticated.user:
package org.apache.roller.examples.plugins.pagemodel;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
import org.apache.roller.pojos.wrapper.UserDataWrapper;
import org.apache.roller.ui.core.RollerSession;
import org.apache.roller.ui.rendering.model.Model;
public class AuthenticatedUserModel implements Model {
private static Log log = LogFactory.getLog(AuthenticatedUserModel.class);
private HttpServletRequest request = null;
public String getModelName() {
return "authenticated";
}
public void init(Map params) throws RollerException {
this.request = (HttpServletRequest)params.get("request");
}
public UserDataWrapper getUser() {
try {
RollerSession rses = RollerSession.getRollerSession(request);
if (rses != null && rses.getAuthenticatedUser() != null) {
return UserDataWrapper.wrap(rses.getAuthenticatedUser());
}
} catch (Exception e) {
log.warn("ERROR: checking user authorization", e);
}
return null;
}
}
If you want to try that, I've created a build script and a README of
instructions on how to use the model here: http://tinyurl.com/37m9vk
- Dave