In the User singleton object, add:

  override def homePage = whereAfterLogin.is openOr super.homePage

  object whereAfterLogin extends SessionVar[Box[String]](Empty)

And in Boot.scala:

    LiftRules.setSiteMap(new SiteMap(List({
            case Full(Req(path, _, _)) if !User.loggedIn_? &&
!path.startsWith(List("user_mgt")) && path != List("index") =>
              Loc.EarlyResponse(() => {S.error("You must be logged in")
                                       val uri = S.uri
                                       S.redirectTo("/user_mgt/login", () =>
{User.whereAfterLogin.set(Full(uri))})})
          }), entries:_*))

So, what this does is it always redirects you to the login screen if you're
not logged in (unless you're accessing the home page or something in
/user_mgt.  It remembers the URL that you came from and sends you back there
after you log in.

Hope this helps.

Thanks,

David

On Fri, Jul 3, 2009 at 3:39 AM, Ewan <[email protected]> wrote:

>
> I wonder if anyone would care to advise of the most appropriate
> solution for not rendering sitemap menu items with additional redirect
> to a login page.  I have read a couple of solutions in this list but
> here is what I have done cobbled together from the liftbook.
>
> I have an If LocParam for testing if a user is logged in which is
> added to a menu:
>
>  val loggedInLocParam = If(() => User.loggedIn_?,
>                            () => RedirectWithState("/user_mgt/login",
> RedirectState(Empty, ("You must login", NoticeType.Notice))))
>
> this seems to achieve the effect I am looking for in that the menuitem
> is not rendered and if the url was bookmarked and the user tries a GET
> then they are redirected to login and a notice is added and rendered
> at the top of the page accordingly.
>
> Is this a good solution or can this cat be skinned better?  I have
> read something about Loc.EarlyResponse and was hoping for an
> explanation.
>
> --Ewan
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to