The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

want little architect help

Alexander's Avatar

Alexander

17 Apr, 2012 03:42 PM

Hello,
I'm sorry, I do not know English very well, and I have very little experience with php, I'm a js developer and a mild panic
I need set and check authorization on ajax requests in my little application, but i don't know beautiful way for it:)

simple i need(pseudo code):

if (!checkAuthoziation() && $_GET['page'] !== 'auth') {

echo json_encode(array( 'status' => 'error', 'message' => 'not authorized' ));
exit;

} if ($_GET['page'] === 'auth') {

$_SESSION['sid'] = 'something';

} if ($_GET['page'] === 'any_module') {

// do something

}

but i don't know how to do it beautiful with Slim without copy-past authorization check in to any module, or another beautiful way :(

$app->post('/auth', function () {
    $_SESSION['sid'] = 'something';
});
$app->create('/any', function() {
    // do something;
});

//--

if (!checkAuthorization() && !$app->route('/auth')) {

echo json_encode(array( 'status' => 'error', 'message' => 'not authorized' ));
exit;

}

$app->run();

i can just use two different files for authorization and for another, but it stange

  1. 1 Posted by Alexander on 17 Apr, 2012 04:32 PM

    Alexander's Avatar

    sirusly i can do it
    <?php
    $resource = $app->request()->getResourceUri(); $user = false;

    if (!$user && $resource !== '/auth')
    {

    $app->halt(401, json_encode(array(
        'status' => 'error',
        'message' => 'not authorized'
    )));
    

    }

    $app->run(); ?> but don`t know its ok or not

  2. 2 Posted by avalak on 24 Apr, 2012 02:50 PM

    avalak's Avatar

    @Alexander use Route Middleware/Middleware

  3. Andrew Smith closed this discussion on 04 Oct, 2012 04:18 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac