Personal tools

ACList

From Utopia MVC

Jump to: navigation, search

Access Control List class, secures a page, showing login forms for non-logged Users, giving out forbidden messages for logged users who don't have enough rights to access the resource and lets authorized users see the page.

Basic use is calling <?php ACList::onlyAllowGroups('group1','group2'?> .

This library relies heavily on the default actions in the ErrorController controller to handle the login/deny access functionalities, this allows for a great degree of customization in the user flow.

Contents

Methods

onlyAllowGroups

Only allows user having a group found in $groups

[toc]Description
public static bool onlyAllowGroups ([string $group [,string ...]])

Straightforward method that basically takes care of everything on its own, just pass one or more group names that are supposed to have access to the page (being inside even just one is enough).

Unauthorized users will be sent to ErrorController::httpError(401) for attempting login, or ErrorController::httpError(403) if they are already logged in and should be denied access.

Parameters
group
unlimited amount of User::groups that can access this resource, any match will grant access.
Return Values

Returns true in case access was granted.

hasAccesss

Returns true if $user has one of the listed $groups in his access level.

[toc]Description
public static bool hasAccesss (User $user, array $groups)

Basic method that does little but running a quick check.

Parameters
user
the User object to be checked for access
groups
an array of allowed access levels (strings), any match will grant access.
Return Values

Returns true in case access should be granted.