<?php
include '../env.php';
require_once(LIB.'common.inc.php');
require_once(LIB.'User.class.php');
$userObj = new User();
$user = $userObj->login(@$_POST['id'], @$_POST['password']);
if (empty($user)) {
	if (ENABLE_ACTION_LOG) {
		require_once(LIB.'Action.class.php');
		$action = new Action();
		$ret = $action->login(FALSE, @$_POST['id']);
	}
	if (! empty($_POST['noajax'])) {
		header('Locatin: '.BASE_URL.'login');
		die;
	}
	echo json_encode(FALSE);
	die;
}
$userObj->save($user);
if (ENABLE_ACTION_LOG) {
	require_once(LIB.'Action.class.php');
	$action = new Action($user['id']);
	session_regenerate_id(TRUE);
	if (! $action->login(TRUE, session_id())) {
		$userObj->clear();
		if (! empty($_POST['noajax'])) {
			header('Locatin: '.BASE_URL.'login');
			die;
		}
		echo json_encode(FALSE);
		die;
	}
}

if (! empty($_POST['noajax'])) {
	header('Locatin: '.BASE_URL);
	die;
}
echo json_encode(TRUE);
?>