
Allows defining and checking user authentication via ACLs, authorization levels or a simple logged in/not logged in scheme
1.0.0b6 | Fixed checkIP() to not trigger a notice when $_SERVER['REMOTE_ADDR'] is not set 5/10/11 |
---|---|
1.0.0b5 | Added getLoginPage() 3/9/10 |
1.0.0b4 | Updated class to use new fSession API 10/23/09 |
1.0.0b3 | Updated class to use new fSession API 5/8/09 |
1.0.0b2 | Fixed a bug with using named IP ranges in checkIP() 1/10/09 |
1.0.0b | The initial implementation 6/14/07 |
Adds a named IP address or range, or array of addresses and/or ranges
This method allows checkIP() to be called with a name instead of the actual IPs.
void addNamedIPRange( string $name, mixed $ip_ranges )
string | $name | The name to give the IP addresses/ranges |
mixed | $ip_ranges | This can be string (or array of strings) of the IPs or IP ranges to restrict to - please see checkIP() for format details |
Checks to see if the logged in user meets the requirements of the ACL specified
boolean checkACL( string $resource, string $permission )
string | $resource | The resource we are checking permissions for |
string | $permission | The permission to require from the user |
If the user has the required permissions
Checks to see if the logged in user has the specified auth level
boolean checkAuthLevel( string $level )
string | $level | The level to check against the logged in user's level |
If the user has the required auth level
Checks to see if the user is from the IPs or IP ranges specified
The $ip_ranges parameter can be either a single string, or an array of strings, each of which should be in one of the following formats:
boolean checkIP( mixed $ip_ranges )
mixed | $ip_ranges | A string (or array of strings) of the IPs or IP ranges to restrict to - see method description for details |
If the user is coming from (one of) the IPs or ranges specified
Checks to see if the user has an auth level or ACLs defined
boolean checkLoggedIn( )
If the user is logged in
Destroys the user's auth level and/or ACLs
void destroyUserInfo( )
Returns the login page set via setLoginPage()
string getLoginPage( )
The login page users are redirected to if they don't have the required authorization
Returns the URL requested before the user was redirected to the login page
string getRequestedURL( boolean $clear, string $default_url=NULL )
boolean | $clear | If the requested url should be cleared from the session after it is retrieved |
string | $default_url | The default URL to return if the user was not redirected |
The URL that was requested before they were redirected to the login page
Gets the ACLs for the logged in user
array getUserACLs( )
The logged in user's ACLs
Gets the authorization level for the logged in user
string getUserAuthLevel( )
The logged in user's auth level
Gets the value that was set as the user token, NULL if no token has been set
mixed getUserToken( )
The user token that had been set, NULL if none
Redirect the user to the login page if they do not have the permissions required
void requireACL( string $resource, string $permission )
string | $resource | The resource we are checking permissions for |
string | $permission | The permission to require from the user |
Redirect the user to the login page if they do not have the auth level required
void requireAuthLevel( string $level )
string | $level | The level to check against the logged in user's level |
Redirect the user to the login page if they do not have an auth level or ACLs
void requireLoggedIn( )
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Sets the authorization levels to use for level checking
void setAuthLevels( array $levels )
array | $levels | An associative array of (string) {level} => (integer) {value}, for each level |
Sets the login page to redirect users to
void setLoginPage( string $url )
string | $url | The URL of the login page |
Sets the restricted URL requested by the user
void setRequestedURL( string $url )
string | $url | The URL to save as the requested URL |
Sets the ACLs for the logged in user.
Array should be formatted like:
array (
(string) {resource name} => array(
(mixed) {permission}, ...
), ...
)
The resource name or the permission may be the single character '*' which acts as a wildcard.
void setUserACLs( array $acls )
array | $acls | The logged in user's ACLs - see method description for format |
Sets the authorization level for the logged in user
void setUserAuthLevel( string $level )
string | $level | The logged in user's auth level |
Sets some piece of information to use to identify the current user
void setUserToken( mixed $token )
mixed | $token | The user's token. This could be a user id, an email address, a user object, etc. |