-
Notifications
You must be signed in to change notification settings - Fork 142
/
LoginLogout.scala
36 lines (28 loc) · 1.17 KB
/
LoginLogout.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package jp.t2v.lab.play2.auth
import play.api.mvc._
import play.api.mvc.Cookie
import play.api.libs.Crypto
import scala.concurrent.{Future, ExecutionContext}
trait Login {
self: Controller with AuthConfig =>
def gotoLoginSucceeded(userId: Id)(implicit request: RequestHeader, ctx: ExecutionContext): Future[Result] = {
gotoLoginSucceeded(userId, loginSucceeded(request))
}
def gotoLoginSucceeded(userId: Id, result: => Future[Result])(implicit request: RequestHeader, ctx: ExecutionContext): Future[Result] = for {
token <- idContainer.startNewSession(userId, sessionTimeoutInSeconds)
r <- result
} yield tokenAccessor.put(token)(r)
}
trait Logout {
self: Controller with AuthConfig =>
def gotoLogoutSucceeded(implicit request: RequestHeader, ctx: ExecutionContext): Future[Result] = {
gotoLogoutSucceeded(logoutSucceeded(request))
}
def gotoLogoutSucceeded(result: => Future[Result])(implicit request: RequestHeader, ctx: ExecutionContext): Future[Result] = {
tokenAccessor.extract(request) foreach idContainer.remove
result.map(tokenAccessor.delete)
}
}
trait LoginLogout extends Login with Logout {
self: Controller with AuthConfig =>
}