1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00
This commit is contained in:
Robin Appelman 2016-12-03 15:39:05 +01:00
commit 3061dda018
15 changed files with 1091 additions and 0 deletions

View file

@ -0,0 +1,37 @@
<?php namespace Providers;
use RandomLib\Generator;
class AuthProvider extends BaseProvider {
/**
* @var Generator
*/
private $generator;
public function __construct(\PDO $db, Generator $generator) {
parent::__construct($db);
$this->generator = $generator;
}
public function generateToken() {
return $this->generator->generateString(32, Generator::CHAR_ALNUM);
}
public function setUser($token, \SteamId $steamid, $key) {
apc_store($token, [
'name' => $steamid->getNickname(),
'steamid' => $steamid->getSteamId64(),
'key' => $key
]);
}
public function getUser($token) {
$found = true;
$result = apc_fetch($token, $found);
return ($found) ? $result : ['name' => null, 'steamid' => null, 'key' => null];
}
public function logout($token) {
apc_delete($token);
}
}