Download the PHP package webiik/account without Composer
On this page you can find all versions of the php package webiik/account. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webiik/account
More information about webiik/account
Files in webiik/account
Package account
Short Description The Account provides common interface for user authentication.
License MIT
Homepage https://www.webiik.com
Informations about the package account
Account
The Account provides common interface for user authentication.
Installation
Example
The following example expects you have already written your account implementation and you use email and password for user authentication.
Settings
addAccount
addAccount() adds an implementation of account.
useAccount
useAccount() sets account to be used when calling custom account related methods.
setNamespace
setNamespace() sets authentication namespace. It allows you to use separate authentication for different parts of your application. If you don't set any namespace, it means user belongs to default namespace.
Writing Your Custom Account
To write your account implementation you have to extend from abstract class namespace to each method. Read below intended function of each mentioned method and adapt your implementation to it.
auth
auth() authenticates a user with credentials. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, INVALID_CREDENTIAL, INVALID_PASSWORD, ACCOUNT_DOES_NOT_EXIST, ACCOUNT_IS_NOT_ACTIVATED, ACCOUNT_IS_BANNED, ACCOUNT_IS_DISABLED, FAILURE
To compare passwords, always use secure method
verifyPassword(string $password, string $hash): bool
provided by AccountBase.
reAuth
reAuth() re-authenticates a user by unique user identifier uid. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, ACCOUNT_DOES_NOT_EXIST, ACCOUNT_IS_NOT_ACTIVATED, ACCOUNT_IS_BANNED, ACCOUNT_IS_DISABLED, FAILURE
signup
signup() signs up a user with credentials. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, INVALID_CREDENTIAL, ACCOUNT_ALREADY_EXISTS, FAILURE
Never store passwords in plain text. AccountBase provides you secure method to hash passwords
hashPassword(string $password): string
.
update
update() updates data on account with id uid. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, ACCOUNT_DOES_NOT_EXIST, INVALID_KEY, FAILURE
disable
disable() sets account status to ACCOUNT_IS_DISABLED or ACCOUNT_IS_BANNED on account with id uid. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, ACCOUNT_DOES_NOT_EXIST, FAILURE
delete
delete() deletes an account with id uid. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, ACCOUNT_DOES_NOT_EXIST, FAILURE
createToken
createToken() creates and returns time limited security token. On error throws AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, FAILURE
activate
activate() activates an account by valid token. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, INVALID_TOKEN, FAILURE
resetPassword
resetPassword() updates account password by valid token. On success returns AccountException. Possible exception status codes: METHOD_IS_NOT_IMPLEMENTED, INVALID_TOKEN, FAILURE
Never store passwords in plain text. AccountBase provides you secure method to hash passwords
hashPassword(string $password): string
.
User
User is an object returned by several Account methods. User provides handy methods to work with authenticated user.
__construct
__construct() creates User object.
Parameters
- status user account status. Usual status codes are: ACCOUNT_IS_OK and ACCOUNT_IS_NOT_ACTIVATED
- id unique user account id.
- role (optional) user role.
- info (optional) additional user account info.
getId
getId() returns unique user account id.
getRole
getRole() returns user role.
hasRole
hasRole() checks if user has given role.
getInfo
getInfo() returns additional user account info.
needsActivation
needsActivation() checks if user account requires activation.
Account Exception
AccountException has to be thrown by all implemented account methods. Unlike standard Exception, AccountException has one extra parameter validationResult. This parameter is intended to store invalid credentials in the following format e.g. ['email' => ['Invalid email'], 'password' => ['Password is too short.']]
__construct
__construct() creates AccountException object.
getValidationResult
getValidationResult() returns invalid credentials.