1. Go to this page and download the library: Download golem/auth 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/ */
golem / auth example snippets
php
class UserRepository implements \Golem\Auth\UserRepository
{
public function findUserById($id)
{
// or whatever you need to do to pull a user record
$data = $this->database->fetchRow('SELECT * from users WHERE id = ?', [$id]);
if (!$data) {
throw new \RuntimeException('User not found.');
}
return new User($data);
}
}
php
// Use the native php session
session_start();
$storage = new \Golem\Auth\NativeSession();
// get an instance of your user repository however you need to
$userRepository = new UserRepository($database_connection);
$auth = new \Golem\Auth($storage, $userRepository);
php
// Should return a User instance that implements Golem\Auth\Authenticatable
$user = $userRepository->getByCredentials($email, $password);
// Store the user login
$auth->login($user);
php
if ($auth->loggedIn()) {
// The user is logged in
}
if (!$auth->loggedIn()) {
// The user is not logged in
}
php
$auth->logout();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.