请看下面的代码
应用程序.scala
def Online = Action { implicit request =>
loginForm.bindFromRequest.fold(
formWithErrors => BadRequest(html.login(formWithErrors)),
user => Contact.AddOnline("email" -> user._1)
)
其次是
trait Secured {
/**
* Retrieve the connected user email.
*/
private def username(request: RequestHeader) =
request.session.get("email")
/**
* Redirect to login if the user in not authorized.
*/
private def onUnauthorized(request: RequestHeader) =
Home.flashing("failure"->"You are not logged in");
// --
/**
* Action for authenticated users.
*/
def IsAuthenticated(f: => String => Request[AnyContent] => Result)=
Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
- 我的问题是我试图调用一段名为setOnline(user.email)
. 此代码仅在通过身份验证后将某个用户的状态设置为在线。在上面给出的代码中,我想调用我的setOnline(user.email)
函数,但我不确定我应该在哪里或如何调用。在过去的 4 个小时里,我一直在尝试,但没有任何运气。主要问题是我不明白上面的代码是如何工作的(因为它不是我的代码)。