次のコードを見てください
アプリケーション.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時間、何の運もありませんでした。主な問題は、上記のコードがどのように機能するかを完全に理解していないことです (私のコードではないため)。