Created
June 16, 2009 14:35
-
-
Save alaz/130708 to your computer and use it in GitHub Desktop.
Liftweb's IfLoggedIn implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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