Exemple #1
0
<?php

namespace AttOn;

use Logger;
use Slim\Slim;
/* @var $app Slim */
/* @var $debug bool */
global $app, $debug;
$app->post('/login/', function () use($app, $debug) {
    // logout user if logged in
    Controller\User\UserActions::logout();
    try {
        $username = isset($_POST['username']) ? $_POST['username'] : '';
        $password = isset($_POST['password']) ? $_POST['password'] : '';
        $remember = isset($_POST['remember']) ? true : false;
        Controller\User\UserActions::login($username, $password, $remember);
        // successfully logged in, redirect to main route
        $app->redirect(ABS_REF_PREFIX);
    } catch (Exceptions\LoginException $ex) {
        $user = Model\User\ModelUser::getCurrentUser();
        $data = array();
        $data['user'] = $user->getViewData();
        $data['errors'] = array('login' => $ex->getMessage());
        if (isset($_POST['username']) && !empty($_POST['username'])) {
            $data['user']['username'] = $_POST['username'];
        }
        $data['template'] = 'login';
        $app->render('main.twig', $data);
    }
});
Exemple #2
0
/* @var $debug bool */
/* @var $logger Logger */
global $app, $debug, $logger;
$app->get('/', function () use($app, $debug) {
    $data = array();
    HeaderViewHelper::parseCurrentUser($data);
    $data['template'] = 'home';
    $app->render('main.twig', $data);
});
$app->get('/login/', function () use($app, $debug) {
    UserActions::logout();
    $data['template'] = 'login';
    $app->render('main.twig', $data);
});
$app->get('/logout/', function () use($app, $debug) {
    UserActions::logout();
    $app->redirect(ABS_REF_PREFIX);
});
$app->get('/map/', function () use($app, $debug) {
    $data = array();
    HeaderViewHelper::parseCurrentUser($data);
    if (ModelGame::getCurrentGame() === null) {
        $data['errors'] = array('message' => 'select a game first');
        $app->render('error.twig', $data);
        return;
    }
    try {
        $map = new Map();
        $map->run($data);
    } catch (MapException $ex) {
        $data['errors'] = array('message' => $ex->getMessage());