From 091bb8f623d2513b5584315fce6e63c028514673 Mon Sep 17 00:00:00 2001 From: Leonardo Menezes <mail@lmenezes.com> Date: Wed, 25 Oct 2017 23:07:53 +0200 Subject: [PATCH] handle custom base path correctly on logout closes #142 --- app/controllers/AuthController.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/AuthController.scala b/app/controllers/AuthController.scala index 9b9c435..468881e 100644 --- a/app/controllers/AuthController.scala +++ b/app/controllers/AuthController.scala @@ -5,15 +5,21 @@ import javax.inject.{Inject, Singleton} import akka.actor.ActorSystem import controllers.auth.{AuthAction, AuthenticationModule} import forms.LoginForm +import play.api.Configuration import play.api.mvc.{Action, Controller} + @Singleton -class AuthController @Inject()(system: ActorSystem, authentication: AuthenticationModule) extends Controller { +class AuthController @Inject()(system: ActorSystem, + authentication: AuthenticationModule, + configuration: Configuration) + extends Controller { import AuthController._ private val badFormMsg = "invalid login form data" + def index = Action { implicit request => if (authentication.isEnabled) { request.session.get(AuthAction.SESSION_USER).map { user => @@ -47,15 +53,15 @@ class AuthController @Inject()(system: ActorSystem, authentication: Authenticati } resp.withSession(AuthAction.SESSION_USER -> username) case None => - Redirect(routes.AuthController.index).flashing(LOGIN_MSG -> "wrong user and/or password") + Redirect(routes.AuthController.index).flashing(LOGIN_MSG -> "Incorrect username or password") } } ) } - def logout = Action { - request => - Redirect("/login").withNewSession + def logout = Action { _ => + val prefix = configuration.getString("play.http.context").getOrElse("/") + Redirect(s"${prefix}login").withNewSession } } -- GitLab