Example #1
0
$app->config(['templates.path' => 'templates']);
// Set singleton value
$app->container->singleton('db', function () {
    require __DIR__ . '/../../bin/private/variables.php';
    try {
        $db = new PDO("mysql:host={$host};dbname={$dbName};charset=utf8", $userName, $pwd, [\PDO::ATTR_PERSISTENT => false]);
    } catch (PDOException $e) {
        die('Error!: ' . $e->getMessage());
    }
    return $db;
});
$app->container->singleton('hybridInstance', function () {
    $instance = new Hybrid_Auth('config.php');
    return $instance;
});
$model = new \Model\App_Model($app->db);
$authenticate = function ($app) {
    return function () use($app) {
        $app->hybridInstance;
        $session_identifier = Hybrid_Auth::storage()->get('user');
        if (is_null($session_identifier) && $app->request()->getPathInfo() != '/login/') {
            $app->redirect('/login/');
        }
    };
};
$app->get('/', function () use($app, $model) {
    $app->hybridInstance;
    $session_identifier = Hybrid_Auth::storage()->get('user');
    $avatarUrl = $model->getAvatarUrl($session_identifier);
    if (isset($session_identifier) && !empty($session_identifier)) {
        $scriptID = 'i';
Example #2
0
$app = new \Slim\Slim();
$app->config(['templates.path' => 'templates']);
// Set singleton value
$app->container->singleton('db', function () {
    try {
        $db = new PDO('mysql:host=localhost;dbname=hybridauth', 'hybridauth', 'hybridauth', [\PDO::ATTR_PERSISTENT => false]);
    } catch (PDOException $e) {
        die('Error!: ' . $e->getMessage());
    }
    return $db;
});
$app->container->singleton('hybridInstance', function () {
    $instance = new Hybrid_Auth('config.php');
    return $instance;
});
$model = new \Model\App_Model($app->db);
$authenticate = function ($app) {
    return function () use($app) {
        $app->hybridInstance;
        $session_identifier = Hybrid_Auth::storage()->get('user');
        if (is_null($session_identifier) && $app->request()->getPathInfo() != '/login/') {
            $app->redirect('/login/');
        }
    };
};
$app->get('/', $authenticate($app));
$app->get('/login/', $authenticate($app), function () use($app) {
    $app->render('login.php');
});
$app->get('/login/:idp', function ($idp) use($app, $model) {
    try {