コード例 #1
0
ファイル: index.php プロジェクト: antonisgr/hangman
        try {
            $game->guessLetter($letter);
            $_SESSION['game'] = serialize($game);
            //sync game obj with session
        } catch (Exception $e) {
            $message = $e->getMessage();
            buildView('user/index', compact('game', 'message'));
            exit;
        }
        header('Location: .');
        exit;
    } else {
        $message = 'Insert letter only!';
        buildView('user/index', compact('game', 'message'));
    }
}
// if 'Start New' is clicked, unset session to start new game without saving
if (isset($_POST['abort-and-new'])) {
    unset($_SESSION['game']);
    header('Location: .');
    exit;
}
// if 'New' is clicked when game is over, save it to db and unset game in session to start new
if (isset($_POST['start-new'])) {
    $db->insert('games', ['user_id' => $game->player->id, 'word_id' => $game->word->id, 'start_datetime' => date('Y-m-d h:i:s a', time()), 'score' => $game->score]);
    unset($_SESSION['game']);
    header('Location: .');
    exit;
}
buildView('user/index', compact('game'));
コード例 #2
0
        switch ($form['action']) {
            case 'login':
                doLogin($form);
                break;
            case "register":
                registerNewUser();
                break;
            case "getsecurityquestion":
                $question = getSecurityQuestion($form['username']);
                if ($question === false) {
                    sendJSONError($lang['forgot_password_no_question']);
                } else {
                    sendJSONResponse(array("question" => $question));
                }
                break;
            case "fetchpassword":
                $form['answer'] = $utils->getRequestVar('answer');
                $form['answer'] = $db->escape($form['answer']);
                $answer = getPassword($form['username'], $form['answer']);
                if ($answer === false) {
                    sendJSONError($lang['forgot_password_invalid_answer']);
                } else {
                    sendJSONResponse(array("password" => $answer));
                }
                break;
            default:
                buildView();
        }
        break;
}
exit(0);
コード例 #3
0
ファイル: auth.php プロジェクト: antonisgr/hangman
    // validate input
    if (V::notEmpty($name) && V::isAlpha($name) && V::maxLength($name, 20) && V::notEmpty($username) && V::isUsername($username) && V::maxLength($username, 20) && V::notEmpty($password) && V::maxLength($password, 20)) {
        // if input ok register user and force login
        $user = new User($name, $username, $password);
        $auth = new Auth($db, $user);
        $password = $auth->register();
        /*echo '<pre>';
          var_dump($auth);
          echo '</pre>';exit;*/
        $auth->forceLogin($password);
        header('Location: /');
        exit;
    } else {
        $message = 'Correct your input and try again.';
        buildView('auth/register', compact('message'));
        exit;
    }
}
// if 'Or register' is clicked
if (isset($_GET['register'])) {
    buildView('auth/register');
    exit;
}
// nothing to see here if u r logged in
if (Auth::isLoggedin()) {
    header('Location: /');
    exit;
}
$message = 'Wrong username or password';
buildView('auth/login', compact('message'));
exit;
コード例 #4
0
ファイル: index.php プロジェクト: paroxp/rafalp
 *
 * @param $container
 * @return \Slim\Views\Twig
 */
$container['view'] = function ($container) {
    return buildView($container);
};
/**
 * Overwrite the 404 page, inside the container.
 *
 * @param $container
 * @return Closure
 */
$container['notFoundHandler'] = function ($container) {
    return function (ServerRequestInterface $request, ResponseInterface $response) use($container) {
        return buildView($container)->render($response->withStatus(404), '/page/404.html');
    };
};
/**
 * Define the main application.
 */
$app = new Slim\App($container);
/**
 * Define route, for the homepage.
 */
$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response, $arguments) {
    return $this->view->render($response, '/page/home.html');
});
/**
 * Define the route for the about page.
 */
コード例 #5
0
ファイル: admin.php プロジェクト: antonisgr/hangman
}
// if 'Add' is clicked add new word
if (isset($_POST['addWord'])) {
    $word = $_POST['word'];
    if (Validator::isAlpha($word) && Validator::maxLength($word, 20)) {
        $db->insert('words', ['word' => mb_strtoupper($word)]);
        header('Location: /admin.php?words');
        exit;
    } else {
        $words = $db->selectAll('words');
        $message = 'Only letters and length < 20 please.';
        buildView('admin/words', compact('words', 'message'));
        exit;
    }
}
// if admin edits word, update it with AJAX
if (isset($_POST['name'])) {
    $newValue = $_POST['value'];
    if (Validator::isAlpha($newValue) && Validator::maxLength($newValue, 20)) {
        $db->update('words', ['word' => mb_strtoupper($newValue)], $_POST['pk']);
        http_response_code(200);
        exit;
    } else {
        http_response_code(400);
        header('Content-type: application/json');
        echo json_encode('Only letters and length < 20 please.');
        exit;
    }
}
buildView('admin/index');