PHP code example of xphere / one-time-access-bundle
1. Go to this page and download the library: Download xphere/one-time-access-bundle 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/ */
xphere / one-time-access-bundle example snippets
class OTARepository extends EntityRepository implements ProviderInterface
{
public function generateOTA($user)
{
$token = md5($user->getUsername() . time());
$ota = new YourOneTimeAccessEntity($user, $token);
$this->getEntityManager()->persist($ota);
$this->getEntityManager()->flush($ota);
return $ota;
}
public function loadUserByOTA($token)
{
$ota = $this->findOneByToken($token);
if ($ota) {
// Remember, user must be defined as EAGER in OTAEntity
return $ota->getUser();
}
}
public function invalidateByOTA($token)
{
$ota = $this->findOneByToken($token);
$this->getEntityManager()->remove($ota);
$this->getEntityManager()->flush();
}
}