Esempio n. 1
0
 public function getSlimInstance()
 {
     $app = new \Slim\Slim(array('version' => '0.0.0', 'debug' => false, 'mode' => 'testing', 'view' => new \Slim\Views\Twig(), 'templates.path' => ROOT_PATH . '/resources/views'));
     // Set options
     $view = $app->view();
     $view->parserOptions = array('debug' => false, 'cache' => ROOT_PATH . '/storage/views');
     // force to overwrite the App singleton, so that \Slim\Slim::getInstance()
     // returns the correct instance.
     $app->setName('default');
     return $app;
 }
    } else {
        echo "You gonna login first";
    }
});
$app->get('/app', function () use($app, $twig, $assets) {
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets);
    if (isset($_SESSION['app_id'])) {
        echo $twig->render('views/index.php', $data);
    } else {
        echo "You gonna login first bro";
    }
});
$app->get('/app/login', function () use($app, $twig, $assets) {
    $request = $app->request();
    $action = $request->params('action');
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets, 'action' => $action, 'csrf_key' => $app->view()->getData('csrf_key'), 'csrf_token' => $app->view()->getData('csrf_token'));
    echo $twig->render('views/login.php', $data);
});
$app->post('/app/login', function () use($app, $twig, $assets) {
    $check_user = $MongoUser->findOne(array('$and' => array(array('email' => $slim->request()->post('email')), array('password' => $slim->request()->post('password')))));
    if ($check_user) {
        // set the session here
        if (!isset($_SESSION)) {
            session_start();
        }
        # nice technique : http://stackoverflow.com/questions/19068363/storing-and-retrieving-an-array-in-a-php-cookie
        $dataArray = array('user' => $new_user, 'message' => "User created sucessfully");
        $response = json_encode($dataArray);
        echo $response;
    } else {
        $app->halt(401, "Credentials incorrect or user dont exist.");