PHP code example of mrjulio / rapture-auth
1. Go to this page and download the library: Download mrjulio/rapture-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/ */
mrjulio / rapture-auth example snippets
class User implements UserInterface, SourceInterface
{
/*
* SourceInterface
*/
/**
* @param array $data Authentication data
*
* @return $this
*/
public function fetchUser($data)
{
$data += ['email' => null, 'password' => null];
$user = UserQuery::create()->filterByEmail($data['email'])->findOne();
if ($user && password_verify($data['password'], $user->getPassword())) {
return $user;
}
return new self;
}
/*
* UserInterface
*/
public function getId()
{
return $this->id;
}
/**
* getName
*
* @return string
*/
public function getName()
{
return $this->getFirstname();
}
/**
* Check if user is anonymous
*
* @return bool
*/
public function isAnonymous()
{
return (int)$this->getId() == 0;
}
/**
* Check if user is authenticated
*
* @return bool
*/
public function isAuthenticated()
{
return !$this->isAnonymous();
}
}