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

I don't anderstand somthing about Middleware...

stephan's Avatar

stephan

29 Jun, 2012 09:52 AM

Hi guys,

I really don't anderstand how Middleware works...
can you explain me how to do something like this :

function auth_middleware($app){
$user = $app->request(); // = array('login' => 'foo', 'pass' => 'bar')

$good = some_login_process($user); if($good) return $app->PATH_INFO;

$app->redirect('/login'); }

$app->get('/', 'auth_middleware', function() use ($app){ $app->render('index.php'); });

$app->get('/login', 'auth_middleware', function() use ($app){ $app->render('login.php'); });

Thank's a lot !

  1. Support Staff 1 Posted by Andrew Smith on 29 Jun, 2012 10:45 AM

    Andrew Smith's Avatar

    Take a look at the current Authentication middlewares in the Slim Extras
    repo.

  2. Support Staff 2 Posted by Brian Nesbitt on 29 Jun, 2012 01:01 PM

    Brian Nesbitt's Avatar

    It needs to be a class that extends Slim_Middleware

    Here are the examples that Andrew mentioned:
    https://github.com/codeguy/Slim-Extras/tree/master/Middleware

    Let us know if it doesn't clear things up for you.

  3. 3 Posted by stephan on 29 Jun, 2012 01:09 PM

    stephan's Avatar

    Hello Andrew, Brian,

    I did read those repo but it's still blury in my mind... but I will double check tomorrow morning.

    I come back if I need to ! :-)

    Thank you !

  4. 4 Posted by stephan on 29 Jun, 2012 01:18 PM

    stephan's Avatar

    I thinking something... can I ask you to make an example with Slim-Extras ?
    In my case I need to set Authentification in specific route (or just know how to control where)... and I see it's for all routes.

    Thank's again !! :-)

  5. Support Staff 5 Posted by Andrew Smith on 29 Jun, 2012 02:15 PM

    Andrew Smith's Avatar

    Take a look at the release-1.0.3 branch and you will see the Strong Auth
    middleware, it authenticate based on routes. You will need to install
    Strong Auth in order to use the middleware. It should be documented enough

  6. 6 Posted by wardprogrammer on 29 Jun, 2012 02:58 PM

    wardprogrammer's Avatar

    Hi Andrew!

    New "Form based authentication" method in Its looks great. I was wondering
    how to check for username and password from MySql table? How should i do
    that?

    Do we have any Demo Code for that? Please let me know.

    Thanks,
    Amit

  7. Support Staff 7 Posted by Andrew Smith on 29 Jun, 2012 03:23 PM

    Andrew Smith's Avatar

    Take a look at the Strong repo, this code is still a work in progress but you can take what you need from it or you can use and enhance it. Currently the hash method is really weak, so I will be changing how this works but there is a PDO provider which allows you to use a mysql database.

    Sorry for the limited help I am giving at the moment, but I am out at a meeting.

  8. 8 Posted by wardprogrammer on 29 Jun, 2012 03:36 PM

    wardprogrammer's Avatar

    Hi Andrew!

    Thanks for quick reply. I appreciate your help. I was trying to make MySql
    driven web application , was just wondering if i can create Custom
    Middleware for MySql Database, Security (XSS and CSRF and SQK Injection)
    things with Slim, So i was looking for similar demo project. Please let me
    know when you are free.

    I would love to learn about the Slim.

    Thanks for your time again.

    regards,

    Amit

  9. 9 Posted by stephan on 30 Jun, 2012 09:29 AM

    stephan's Avatar

    Hello Andrew,

    that is exactly what I wanted to see !
    Now I anderstand how it works.

    Thank you so much ! ;-)

  10. Brian Nesbitt closed this discussion on 30 Jun, 2012 12:57 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