001package votorola.a.web.wic.authen; // Copyright 2008-2009, 2012, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import org.apache.wicket.Page;
004import org.apache.wicket.request.mapper.parameter.PageParameters;
005import votorola.a.web.wic.*;
006import votorola.g.locale.*;
007import votorola.g.lang.*;
008import votorola.g.web.wic.*;
009
010
011/** A link that logs the user in.
012  */
013public @ThreadRestricted("wicket") final class WC_LoginLink extends BookmarkablePageLinkX
014{
015
016    // OPT.  After moving to Wicket 1.5, login and logout links reconstruct some pages
017    // twice: once for the state change and once again for the link click.  This is
018    // because the pages are now stateless (to rid us of 1.5's new versioning parameters
019    // in the URL) and so the links are no longer bookmarkable.
020
021
022    /** Constructs a standard WC_LoginLink.
023      *
024      *     @param page the return page, which must be bookmarkable.
025      */
026    private WC_LoginLink( String _id, Page _page, final VRequestCycle cycle )
027    {
028        this( _id, _page, cycle.bunW().l( "a.web.wic.authen.WC_LoginLink.linkBody" ));
029    }
030
031
032
033    /** Constructs a WC_LoginLink with the specified body string.
034      *
035      *     @param page the return page, which must be bookmarkable.
036      */
037    public WC_LoginLink( String _id, final Page page, final String bodyString )
038    {
039        super( _id, VOWicket.get().authenticator().loginPageClass(), PageParametersX.withSet(
040          new PageParameters(page.getPageParameters()), "returnClass", page.getClass().getName() ));
041        assert page.isBookmarkable(): "return page must be bookmarkable";
042        setBody( bodyString );
043    }
044
045
046
047    /** Constructs a standard WC_LoginLink or WC_LogoutLink depending on the user's
048      * current login state.
049      */
050    public static BookmarkablePageLinkX newInOut( final String id, final Page page,
051      final VRequestCycle cycle )
052    {
053        return VSession.get().user() == null? new WC_LoginLink(id,page,cycle):
054          new WC_LogoutLink(id,page,cycle);
055    }
056
057
058
059}