<?php
namespace Imperium\InterfaceToken;
use Imperium\Config\iConfig;
use Imperium\InterfaceBase\AuthTokenBase;
use Imperium\InterfaceBase\WebHookBase;
use Imperium\StaticUtils\Crypt;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class userToken extends AuthTokenBase
{
protected $api_verify_endpoint = '/authentication/tokens/users/verify';
protected $api_signin_endpoint = '/authentication/tokens/users/signin';
protected $api_uri_key = 'api_idbl';
private $session;
function __construct( $token=null,SessionInterface $session=null)
{
if($token && !empty($token)){
$this->user_token = $token;
$resp = $this->verify($this->user_token);
if($resp->status==200)
$this->payload = $resp->payload;
}
if($session != null){
$this->session = $session;
$token = $this->session->get('user_token');
if ($token){
$this->user_token = $token;
$resp = $this->verify($this->user_token);
if($resp->status==200 && isset($resp->payload))
$this->payload = $resp->payload;
}
}
}
function authenticate($username, $password)
{
$resp = $this->auth($username,$password);
if($resp->status == 200 && $this->session != null){
$this->session->set('user_token',$resp->token);
}
return $resp;
}
}