/** * Copyright 2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.bricket.plugin.user.web; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.StringResourceModel; import org.apache.wicket.request.target.basic.RedirectRequestTarget; import org.bricket.plugin.authentication.web.LoginPage; import org.bricket.plugin.user.domain.User; import org.bricket.web.BricketApplication; import org.bricket.web.BricketConfigAwarePanel; import brix.jcr.wrapper.BrixNode; import brix.web.nodepage.PageParametersCarryingLink; /** * @author Ingo Renner * @author Henning Teek */ public class UserPanel extends BricketConfigAwarePanel<UserConfig> { public UserPanel(String id, IModel<BrixNode> tileNode) { super(id, tileNode, new UserConfig()); } @Override protected void initGui() { add(new Label("greeting", isSignedIn() ? new StringResourceModel("greeting", new Model<User>(getUser())) : new Model<String>(""))); add(new LogoutLink("logoutLink").setVisible(isSignedIn())); add(new BookmarkablePageLink<LoginPage>("loginLink", LoginPage.class).setVisible(!isSignedIn())); add(new PageParametersCarryingLink("signupLink", ((BricketApplication) getApplication()).getI18nBrixLink( getSession(), "/signup.html")).setVisible(getConfig().isRegistrationVisible())); } static class LogoutLink extends Link<Void> { public LogoutLink(String id) { super(id); } @Override public void onClick() { getSession().invalidate(); getRequestCycle().setRequestTarget(new RedirectRequestTarget("/")); } } }