Question

I have this in my routes.conf file:

# SecureSocial routes
# Login page
GET     /login                      securesocial.controllers.LoginPage.login

And then I have this in a Scala Controller file

val index = SecuredAction { implicit request => 
    Redirect(routes.UserOps.watchlist)
    // how do I go straight to /login? >|
}

Doing this takes me to a login page that has a red error bar saying "you must be signed in to view this page". If I access `localhost:9000/login' I get the login page without the error bar.

Normally I do a Redirect(routes.SomeControllerObject.ActionMethodName) but in this case the controller I need to access is in a plugin...

I feel like I'm missing something rather large here...

Was it helpful?

Solution

Update:

To reverse-route to an action in a plugin controller you need to provide the correct, full path to the plugin's routes class.

Redirect(securesocial.controllers.routes.LoginPage.login)

Original Answer

For reverse-routing I don't think it matters where the Controller is since Play is building that when the project compiles. From the documentation:

For each controller used in the routes file, the router will generate a ‘reverse controller’ in the routes package, having the same action methods, with the same signature, but returning a play.api.mvc.Call instead of a play.api.mvc.Action.

So this should work just as if LoginPage was a controller directly in your app.

Redirect(routes.LoginPage.login);

OTHER TIPS

In order to show the message, you must have an item in the Flash. When you hit /login directly, there is no flash, so you won't see that message.

If you want to see that message:

Redirect(securesocial.controllers.LoginPage.login).flashing( ... )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top