new AbstractActionCall() {
public String doInAction(ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServiceException {
ActionsHelper.rememberPage(request, "/user/account/show");
ActionsHelper.rememberContext(request, "admin");
User userLogged = (User)request.getSession().getAttribute(Params.LOGIN.SESSION.USER);
if (userLogged==null) {
LOGGER.debug("user try to access account page without being logged in.");
return ActionsHelper.loginForwardName();
}
String userLogin = (String)request.getParameter(Params.USER_ACCOUNT.SHOW.PARAMS.LOGIN);
User u = null;
if (userLogin!=null) {
if (!userLogged.getLogin().equals(userLogin) && !ActionsHelper.isAdmin(request)) {
// a non admin user try to edit another user page
LOGGER.debug("user " + userLogged.getLogin() + " try to edit " + userLogin + " page without admin rights");
return ActionsHelper.homepageForwardName();
}
LOGGER.debug("showing account form for user with login : " + userLogin);
u = DaoFactory.getUserDao().findUser(userLogin);
} else {
LOGGER.debug("showing account form for connected user");
u = (User)request.getSession().getAttribute(Params.LOGIN.SESSION.USER);
if (u!=null) {
// We refresh the user
u = Portal.getInstance().getUserService().getUser(u.getLogin());
if (u!=null) {
request.getSession().setAttribute(Params.LOGIN.SESSION.USER, u);
}
}
}
if (u == null) {
LOGGER.debug("failed to retrieve user to modify in account form");
request.setAttribute(Params.REDIRECT.REQUEST.REDIRECTION_URL, ActionsHelper.homepageForward().getPath());
request.setAttribute(Params.REDIRECT.REQUEST.MESSAGE_KEY, "illegal.state");
return "redirect";
}
DynaActionForm f = (DynaActionForm)form;
UserImpl usr = (UserImpl)u;
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.PASSWORD, null);
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.CONFIRM_PASSWORD, null);
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.LOGIN, usr.getLogin());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.EMAIL, usr.getEmail());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.FIRST_NAME, usr.getFirstName());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.LAST_NAME, usr.getLastName());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.ADRESS, usr.getAdress());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.CITY, usr.getCity());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.POSTAL_CODE, usr.getPostalCode());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.COUNTRY, usr.getCountry());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.COMPANY, usr.getCompany());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.COMPANY_HOMEPAGE, usr.getCompanyHomepage());
f.set(Params.USER_ACCOUNT.VALIDATE.PARAMS.GODFATHER, usr.getGodfather());
request.setAttribute("countries", Portal.getInstance().getGeographyService().getCountries());
request.setAttribute(Params.USER_ACCOUNT.SHOW.REQUEST.USER, u);
request.setAttribute(Params.USER_ACCOUNT.VALIDATE.PARAMS.LOGIN, u.getLogin());
request.setAttribute(Params.USER_ACCOUNT.SHOW.REQUEST.EMAIL_VALID, Boolean.valueOf(usr.isMailVerified()).toString());
int uPoints = ServiceFactory.getFidelityService().getUserPoint(usr).getPoints();
request.setAttribute(Params.USER_ACCOUNT.SHOW.REQUEST.POINTS, new Integer(uPoints));
request.setAttribute(Params.USER_ACCOUNT.SHOW.REQUEST.HAS_POINTS, Boolean.valueOf(uPoints>0));