1. Go to this page and download the library: Download webiik/account library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webiik / account example snippets
$account = new \Webiik\Account\Account();
// Add your account implementation
$account->addAccount('YourAccount', function () {
return new \Webiik\Service\YourAccount());
});
// Use one of your account implementations
$account->useAccount('YourAccount');
// Try authenticate a user
try {
$user = $this->account->auth([
'email' => '[email protected]',
'password' => 'meow!'
]);
echo 'User ID: ' . $user->getId() . '<br/>';
echo 'User status: ' . $user->getStatus() . '<br/>';
echo 'User role: ' . $user->getRole() . '<br/>';
if ($user->hasRole('admin')) {
// Do something...
}
} catch (AccountException $e) {
echo $e->getMessage() . '<br/>';
print_r($e->getValidationResult());
}
$account->addAccount('YourAccount', function () {
return new \Webiik\Service\YourAccount());
});
useAccount(string $name): void
$account->useAccount('YourAccount');
setNamespace(string $namespace): void
// Set namespace to 'en'
$account->setNamespace('en');
// Let's say, user '[email protected]' is authenticated in
// namespace 'es', so the following authentication fails.
try {
$user = $this->account->auth([
'email' => '[email protected]',
'password' => 'meow!'
]);
} catch (AccountException $e) {
echo $e->getMessage(); // e.g. Account does not exist.
}
try {
$token = $this->account->createToken();
// Send token to user, so he can perform an action...
} catch (AccountException $e) {
echo $e->getMessage();
}
throw new AccountException(self::MSG_INVALID_CREDENTIAL, self::INVALID_CREDENTIAL, null, ['email' => ['Invalid email'], 'password' => ['Password is too short.']]);