Keller123
Keller123

Reputation: 187

set conditions to access play framework 2 actions

I want to set a rule for accessing a route to some users that I created. My user model is :

public class User extends Model{

    public String firstName;

    @Required
    public String lastName;

    @Required
    public String password;

    @Required
    public boolean labAccess;

    public boolean labAccess() {
       return labAccess;
    }
}

After users log in to the main page, I have a route link to the "Laboratory page". I want to set a rule for users: if the labAccess of User is true he/she can click the route to see the laboratory page.

My controller action is like this :

public class Application extends Controller {

    public static Result login() {
        return ok(login.render(form(Login.class)));
    }

    public static Result laboratory() {
        return ok(laboratoryPage.render("hello. welcome to lab));
    }
}

How to set this rule? Do I need to save something in session or set some constraint on actions in my Application class?

Upvotes: 0

Views: 51

Answers (1)

i.am.michiel
i.am.michiel

Reputation: 10404

You will have to use Action Composition. Checkout the official documentation!

Upvotes: 2

Related Questions