PHP Trait TinyAuth\Auth\AuthUserTrait

Simply add it at the class file: trait AuthUserTrait; But needs protected function _getUser() } to be implemented in the using class. Expects the Role session infos to be either - Auth.User.role_id (single) or - Auth.User.Role (multi - flat array of roles, or array role data) and can be adjusted via constants and defined(). Same goes for Right data. If roles are defined in configuration file (non-db roles setup) the constant USER_ROLE_KEY has to be defined in bootstrap.php. if role key in User model is role_id define('USER_ROLE_KEY', 'role_id'); Note: This uses AuthComponent internally to work with both stateful and stateless auth.
Author: Mark Scherer
显示文件 Open project: dereuromark/cakephp-tinyauth

Public Methods

Method Description
hasRole ( mixed $expectedRole, mixed | null $providedRoles = null ) : boolean Check if the current session has this role.
hasRoles ( mixed $expectedRoles, boolean $oneRoleIsEnough = true, mixed | null $providedRoles = null ) : boolean Check if the current session has one of these roles.
id ( ) : mixed Get the user id of the current session.
isMe ( string | integer $userId ) : boolean This check can be used to tell if a record that belongs to some user is the current logged in user
roles ( ) : array Get the role(s) of the current session.
user ( string | null $key = null ) : mixed Get the user data of the current session.

Method Details

hasRole() public method

Check if the current session has this role.
public hasRole ( mixed $expectedRole, mixed | null $providedRoles = null ) : boolean
$expectedRole mixed
$providedRoles mixed | null
return boolean Success

hasRoles() public method

You can either require one of the roles (default), or you can require all roles to match.
public hasRoles ( mixed $expectedRoles, boolean $oneRoleIsEnough = true, mixed | null $providedRoles = null ) : boolean
$expectedRoles mixed
$oneRoleIsEnough boolean (if all $roles have to match instead of just one)
$providedRoles mixed | null
return boolean Success

id() public method

This can be used anywhere to check if a user is logged in.
public id ( ) : mixed
return mixed User id if existent, null otherwise.

isMe() public method

This check can be used to tell if a record that belongs to some user is the current logged in user
public isMe ( string | integer $userId ) : boolean
$userId string | integer
return boolean

roles() public method

It will return the single role for single role setup, and a flat list of roles for multi role setup.
public roles ( ) : array
return array Array of roles

user() public method

Get the user data of the current session.
public user ( string | null $key = null ) : mixed
$key string | null Key in dot syntax.
return mixed Data