<?
//
//
#Автор: Jquery
#telegram: @justin_olivier
//
//
class core{
	private $db;
	public function __construct() {
		return $this->getUserData();
	}
	protected function getUserData() {
		if (isset($_COOKIE['token'])):
			return $this->authentification($_COOKIE['token']);
		endif;
		return [];
	}
	private function authentification(string $token): array {
		$req = DB::$dbs->query('SELECT * FROM `users` WHERE `token` = ? LIMIT 1',[$token]);
		if ($req->rowCount()):
			$this->userData = $req->fetch();
			DB::$dbs->query('UPDATE `users` SET `time` = ? WHERE `id` = ?',[time(),$this->userData['id']]);
		else:
			$this->userUnset();
		endif;
		return [];
	}
	public function getData() {
		return $this->userData ?? null;
	}
	protected function userUnset(): void {
		setcookie('token', '');
	}
	private function setIP($value): string {
		return ! empty($value) && filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? $value : 0;
	}
}
//
//
?>