Skip to content
Browse files

Merge pull request #4 from lunserv/add_Remembered_feature

Add Remembered feature
  • Loading branch information...
2 parents df8cb2c + d32ab96 commit 13e5dc81a734f8a7b69b12c02a8631ed8e38cc2a @timperrett committed Sep 20, 2011
Showing with 18 additions and 11 deletions.
  1. +10 −2 library/src/main/scala/shiro/sitemap/locs.scala
  2. +8 −9 library/src/main/scala/shiro/utils.scala
View
12 library/src/main/scala/shiro/sitemap/locs.scala
@@ -37,12 +37,20 @@ object Locs {
() => !isAuthenticated,
() => RedirectToIndexURL)
+ val RequireRemembered = If(
+ () => isRemembered || isAuthenticated,
+ () => RedirectBackToReferrer)
+
+ val RequireNotRemembered = If(
+ () => !(isRemembered || isAuthenticated),
+ () => RedirectToIndexURL)
+
def logoutMenu = Menu(Loc("Logout", logoutURL,
S.??("logout"), logoutLocParams))
- private val logoutLocParams = RequireAuthentication ::
+ private val logoutLocParams = RequireRemembered ::
EarlyResponse(() => {
- if(isAuthenticated){ subject.logout() }
+ if(isAuthenticated || isRemembered){ subject.logout() }
Full(RedirectResponse(Shiro.indexURL.vend))
}) :: Nil
View
17 library/src/main/scala/shiro/utils.scala
@@ -17,6 +17,9 @@ private[shiro] trait Utils {
def isAuthenticated =
test { _.isAuthenticated }
+ def isRemembered =
+ test { _.isRemembered }
+
def hasRole(role: String) =
test { _.hasRole(role) }
@@ -35,10 +38,9 @@ private[shiro] trait Utils {
}
}
-
-import net.liftweb._,
- common.{Box,Failure,Full,Empty},
- util.Helpers.tryo, http.S
+import net.liftweb.common.{Box,Failure,Full}
+import net.liftweb.util.Helpers
+import net.liftweb.http.S
import org.apache.shiro.authc.{
AuthenticationToken, IncorrectCredentialsException, UnknownAccountException,
LockedAccountException, ExcessiveAttemptsException}
@@ -52,10 +54,7 @@ trait SubjectLifeCycle {
def redirect = S.redirectTo(LoginRedirect.is.openOr("/"))
if(!isAuthenticated){
- // println("~~~~~~")
- // println(isAuthenticated)
-
- tryo(subject.login(token)) match {
+ Helpers.tryo(subject.login(token)) match {
case Failure(_,Full(err),_) => err match {
case x: UnknownAccountException =>
S.error("Unkown user account")
@@ -72,4 +71,4 @@ trait SubjectLifeCycle {
}
} else redirect
}
-}
+}

0 comments on commit 13e5dc8

Please sign in to comment.
Something went wrong with that request. Please try again.