velsym/auth
Ready to use package for authentication in Velsym framework.
Velsym\Auth
Roles
A Singleton class that is used to define user roles that work inside the velsym application.
Methods
set(roles)
- defines roles working in the application.Returns:
void
Params:
roles
- key-value array of roles. Key is name of the role and value is an integer (can be used to defined hierarchy).
get()
- returns the list of roles.Returns:
array
Examples
BaseUser
An abstract class extended by BaseModel[Link Required]. Used to create custom user.
Properties
role
- takes one of the roles defined in the Roles.
Methods
getRole()
- returns the role that is assigned to the user.Returns:
string
setRole(role)
- used to promote/demote/change user's role.Returns:
void
Params:
role
- string of user's role.
Examples
AuthStatus
Manages status of the (un)authenticated user.
Methods
logIn(user)
- binds client with the user.Returns:
void
Params:
user
- Instance of class extended by BaseUser.
logOut()
- unbinds the user from client.Returns:
void
getUser()
- if user is logged in then the user object is returned. Otherwise null is returned.Returns:
NULL or instance of class extended by
BaseUser
isLoggedIn()
- checks if any user is bound to the client.Returns:
bool
- true if user is authenticated and false if not.
Examples
Example below uses BasicUser
from the example titled "How to create custom user" and role setup from the example title "Example role setup".
Velsym\Auth\Middleware
AuthCanAccess
Check if the user's role is sufficient to access route. If role has higher interger/value than required, then it will also be allowed.
Params
role
- role required to access the route.redirectPath
- url to which client should be redirected.
Examples
Last updated