70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
use DarksLight2\Training\Steps\ChatFirstStep;
|
|
use DarksLight2\Training\Steps\MyUserFirstQuest;
|
|
use DarksLight2\Training\TrainingException;
|
|
use DarksLight2\Training\TrainingManager;
|
|
|
|
header('Content-type: application/json');
|
|
|
|
if (!defined('GAME_VERSION')) {
|
|
require_once '../_incl_data/autoload.php';
|
|
}
|
|
|
|
$user = User::start();
|
|
|
|
if($input = file_get_contents("php://input")) {
|
|
$data = json_decode($input);
|
|
}
|
|
|
|
if(!empty($user->info)) {
|
|
|
|
$training = TrainingManager::getInstance($user->info['id'], false);
|
|
|
|
try {
|
|
$training->createDatabaseRecord();
|
|
$training->register([
|
|
new MyUserFirstQuest(),
|
|
new ChatFirstStep()
|
|
]);
|
|
} catch (TrainingException $e) {
|
|
}
|
|
|
|
if (!isset($data->token) || !password_verify(
|
|
$training->getDatabaseData()['api_token'] . $data->time . $user->info['id'],
|
|
$data->token
|
|
)) {
|
|
http_response_code(401);
|
|
die;
|
|
}
|
|
|
|
if (isset($_GET['get'])) {
|
|
switch ($_GET['get']) {
|
|
default:
|
|
http_response_code(400);
|
|
die;
|
|
case 'complete':
|
|
if ($training->getDatabaseData()['data'][$training->getCurrentStepName()]['completed']) {
|
|
http_response_code(400);
|
|
die;
|
|
}
|
|
|
|
if($training->getRegistered()[$data->short_name]->isInfo()) {
|
|
|
|
$training->addPoint($training->getCurrentStepName());
|
|
}
|
|
|
|
$training->nextStep();
|
|
|
|
$training->store();
|
|
|
|
die(json_encode(['status' => 'ok']));
|
|
|
|
case 'go_back':
|
|
$training->previousStep();
|
|
$training->store();
|
|
die(json_encode(['status' => 'ok', 'message' => 'Вы указали не верный ответ!']));
|
|
|
|
}
|
|
}
|
|
} |