if (isset($_SESSION['app_id'])) {
        echo $twig->render('views/index.php', $data);
    } 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;
Пример #2
0
 * This is not much than a ping on the API server
 */
$app->get('/status', function () {
    $response['status'] = 'ok';
    echoRespnse(200, $response);
    exit;
});
/**
 * Try to perform a user log in
 * If the user is authenticated, then start the session cookie
 */
$app->post('/login', function () use($app) {
    // check for required params
    verify_required_params(array('email', 'password'));
    // reading post params
    $email = $app->request()->post('email');
    $password = $app->request()->post('password');
    $response = array('request' => 'login');
    // Sanitize data
    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
    $password = filter_var($password, FILTER_SANITIZE_STRING);
    // Validate data
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $response['error'] = true;
        $response['msg'] = 'Input data not valid.';
        echoRespnse(401, $response);
        $app->stop();
    }
    $db = new DbHandler();
    // check for correct email and password
    if ($db_uid = $db->checkUserExisits($email)) {
Пример #3
0
$dbpass = '******';
// $dbname = 'naiemoji';
$dbname = 'testorm';
$dbmethod = 'mysql:dbname=';
$dsn = $dbmethod . $dbname;
$pdo = new PDO($dsn, $dbuser, $dbpass);
$db = new NotORM($pdo);
// Home Route
$app->get('/', function () use($app) {
    $app->response->setStatus(200);
    $app->render('../templates/homepage.html');
});
// Register a user
$app->post('/register', function () use($app, $db) {
    $app->response()->header('Content-Type', 'application/json');
    $name = $app->request()->post('name');
    $email = $app->request()->post('email');
    $password = $app->request()->post('password');
    $passwordEncryption = md5($password);
    if ($email === $db->users()->where('email', $email)->fetch('email')) {
        echo json_encode(['message' => 'That email address is already in use. Please use another email address']);
    } else {
        $user = ['name' => "{$name}", 'email' => "{$email}", 'password' => "{$passwordEncryption}"];
        $result = $db->users->insert($user);
        $users = array();
        foreach ($db->users() as $user) {
            $users[] = array('id' => $user['id'], 'name' => $user['name'], 'email' => $user['email']);
        }
        echo json_encode($users, JSON_FORCE_OBJECT);
    }
});
Пример #4
0
    echoRespnse(200, $response);
    exit;
});
/**
 * Try to perform a user log in
 * If the user is authenticated, then start the session cookie
 */
$app->post('/login', function () use($app) {
    // Dev only
    // Sleep 3 seconds before processing the request
    // to display the loader
    sleep(1);
    // check for required params
    verify_required_params(array('email', 'password'));
    // reading post params
    $email = $app->request()->post('email');
    $password = $app->request()->post('password');
    $response = array('request' => 'login');
    // Sanitize data
    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
    $password = filter_var($password, FILTER_SANITIZE_STRING);
    // Validate data
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $response['error'] = true;
        $response['msg'] = 'Input data not valid.';
        echoRespnse(401, $response);
        $app->stop();
    }
    $db = new DbHandler();
    // check for correct email and password
    if ($db_uid = $db->checkUserExisits($email)) {