<?php

include __DIR__.'/account.php';

class Login extends Vn\Web\JsonRequest
{
	function run ($db)
	{
		try {
			Account::trySync ($db
				,strtolower ($_POST['user'])
				,$_POST['password']
			);
		}
		catch (Exception $e) {}

		$token = $this->service->createToken (
			$_SESSION['user'],
			!empty ($_POST['remember'])
		);

		return [
			'login' => TRUE,
			'token' => $token
		];
	}
}

