Skip to content

Instantly share code, notes, and snippets.

@alaz
Created June 16, 2009 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaz/130708 to your computer and use it in GitHub Desktop.
Save alaz/130708 to your computer and use it in GitHub Desktop.
Liftweb's IfLoggedIn implementation
/*
* IfLoggedIn implementation which redirects to the page a user was going to,
* after his/her successful login
*
* based on http://groups.google.com/group/liftweb/browse_thread/thread/bdd5accd4bb623c9/d56e054c4037470f ,
* works with ProtoUser out of the box
*/
// In SiteMap:
lazy val IfLoggedIn = If(User.loggedIn_? _, loginAndComeBack _)
private def loginAndComeBack = {
val uri = S.uri
RedirectWithState(loginUri, RedirectState( () => User.goAfterLogin(uri), ?("notlogged") -> NoticeType.Notice ) )
}
private lazy val loginUri = SiteMap.findLoc("Login").map{ _.link.uriList }.
openOr(LiftRules.siteMapFailRedirectLocation).mkString("/", "/", "")
// In User model object:
object goAfterLogin extends SessionVar("/")
override def homePage = {
val uri = goAfterLogin.is
goAfterLogin.remove
uri
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment