Pergunta

I need to show different home pages depending on whether the user is logged in or not, just like Twitter or Instagram does:

  • If the user has not authenticated, the default cover home page must be shown (logo, description, download our app, log in button, etc.)
  • When the user logs in, a feed must be shown with the user's data (e.g. his timeline, photos, etc.)

In both cases the corresponding URL must be the same, e.g https://myapp.com and not https://myapp.com/feed for the latter.

I need to know if my implementation is the correct way of doing it and more importantly if it has any security issues. If it is incorrect, an example would be very much appreciated.

My routes file:

# Home page
GET     /          controllers.Application.index()

My Application.java:

package controllers;

import play.mvc.Controller;
import play.mvc.Result;
import securesocial.core.Identity;
import securesocial.core.java.SecureSocial;
import views.html.feed;
import views.html.index;

public class Application extends Controller {

    @SecureSocial.UserAwareAction
    public static Result index() {
        Identity user = (Identity) ctx().args.get(SecureSocial.USER_KEY);
        if (user == null) {
            return ok(index.render());
        } else {
            return ok(feed.render(user));
        }
    }

}

Thanks!

Foi útil?

Solução

Using UserAwareAction is the way to go, then it's up to your action code and template to show/hide things as needed.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top