Exemplo n.º 1
0
<?php

require '../vendor/autoload.php';
require 'core/Middleware.php';
use Noodlehaus\Config;
use Helge\Framework\Session;
use Helge\Framework\Authentication;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
// Start session
Session::start();
Session::cacheLimiter("nocache");
// Instantiate and setup Slim application instance
$app = new \Slim\Slim(array('view' => new \Slim\Views\Twig(), 'templates.path' => '../app/views', 'cookies.encrypt' => true, 'cookies.secret_key' => "pCAyyIHcGmZ9kT1yzsA8YuhNt64oNPvSOBHHUhQYuamRjYKFrQujaLMjTlhS", 'cookies.cipher' => MCRYPT_RIJNDAEL_256, 'cookies.cipher_mode' => MCRYPT_MODE_CBC, 'log.enabled' => true, 'log.level' => \Slim\Log::WARN, 'log.writer' => new \Slim\Logger\DateTimeFileWriter(array('path' => "../log/"))));
// Load the ini config file
$app->container->set("config", Config::load('../app/config.ini'));
// Set the default timezone from config
date_default_timezone_set($app->config->get("localization.timezone"));
// If debugging is enabled we show all errors
if ($app->config->get("development.debugging")) {
    error_reporting(E_ALL);
    ini_set("display_errors", "on");
} else {
    ini_set("display_errors", "off");
}
// Create a translator instance
$app->container->set("translator", new Translator($app->config->get("localization.language"), new MessageSelector()));
$app->translator->setFallbackLocales(['nb_NO']);
$app->translator->addLoader('php', new \Symfony\Component\Translation\Loader\PhpFileLoader());
// Include require all route files in the routes directory
Exemplo n.º 2
0
<?php

use Helge\Framework\Session;
$app->map('/login', function () use($app) {
    $username = null;
    if ($app->request()->isPost()) {
        $username = $app->request->post('username');
        $password = $app->request->post('password');
        $password = hash("sha512", $password);
        $stmt = $app->db->prepare("SELECT * FROM users WHERE username = :username AND password = :password");
        $stmt->execute(array("username" => $username, "password" => $password));
        $userInfo = $stmt->fetch(PDO::FETCH_ASSOC);
        if ($stmt->rowCount()) {
            Session::set("user", $userInfo);
            $app->flash("info", $app->translator->trans("logged_in"));
            $app->redirect("/");
        } else {
            $app->flashNow("error", $app->translator->trans("wrong_username_or_password"));
        }
    }
    $app->render('login.twig', array('username' => $username));
})->via('GET', 'POST')->name('login');
$app->get('/logout', function () use($app) {
    // Clear session values
    Session::clear();
    $app->flash("info", $app->translator->trans("logged_out"));
    $app->redirectTo('login');
})->name("logout");