Package controllers

Source Code of controllers.Application

package controllers;

import annotations.Secure;
import models.User;
import play.mvc.Before;
import play.mvc.Controller;

public class Application extends Controller {
   
    @Before
    static void addUserToSession() {
        User user = connectedUser();
        if(user != null) {
            renderArgs.put("user", user);
        }
    }
    @Before
    static void checkSecure() {
        Secure secure = getActionAnnotation(Secure.class);
        if (secure != null) {
            if (connectedUser() == null) {
                forbidden();
            }
        }
    }
    protected static User connectedUser() {
        if(renderArgs.get("user") != null) {
            return renderArgs.get("user", User.class);
        }
        String username = session.get("user");
        if(username != null) {
            return User.find("byUsername", username).first();
        }
        return null;
    }
   
}
TOP

Related Classes of controllers.Application

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.