Git Product home page Git Product logo

slim-contextsensitiveloginlogout's Introduction

Login/Logout with Redirect

In response to http://help.slimframework.com/discussions/questions/341-loginlogout-with-redirect I created this sample web app.

git clone git://github.com/briannesbitt/Slim-ContextSensitiveLoginLogout.git
cd Slim-ContextSensitiveLoginLogout
curl -s http://getcomposer.org/installer | php
php composer.phar install
php -S 127.0.0.1:80   # <== assumes PHP 5.4 (built in dev server)

Launch browser to http://127.0.0.1

This application uses route middleware for authentication and a slim.before.dispatch hook to set a $user variable for all views if in fact the user is logged in.

Public pages

From any public page you can click Login and it will redirect to the login page and upon successful login redirect back to the previously browsed page. This is done partly via javascript to capture the current url on the Login click and via sessions (cookie) to store the url to redirect to.

Private pages

This also works if you try to visit a private page as well. If you are not logged in and try to visit http://127.0.0.1/private/goodstuff it will see that you are not authenticated, store that url and forward you onto the login page. Then again upon successful login redirect you back to the requested private page. This is all done via sessions (cookies).

Page navigation

The page navigation only shows the Login or Logout as needed and shows private pages only after the user is logged in.

Huh?

If you have no idea what I am talking about, first visit Slim Framework.

slim-contextsensitiveloginlogout's People

Contributors

briannesbitt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slim-contextsensitiveloginlogout's Issues

[feature] authenticate on grouped routes

Hi,

I love your project! Simple, clean, and works perfectly! While testing I found that this will not work with grouped routes, as Slim by default ALWAYS triggers everything inside the group definition. I think this could be a useful feature in your script, so if somebody has an idea:

Example:

// works perfectly
$app->get('/admin', $authenticate($app), function () use ($app) {
    // ...
});

// this will not work as expected! Slim runs $authenticate automatically every time 
// you hit your application, regardless of route. 
// Hitting /admin will trigger the line below, even if it clearly says /xxx ! This is 
// probably intended behaviour, but still tricky...
$app->group('/xxx', $authenticate($app), function () use ($app, $model) {
    $app->get('/yyy', function () use ($app, $model) {
        // ...
    });
});

Idea:

I would like to make your wonderful script work with grouped routes, but have failed to implement this for now. Has anybody reading this already found a solution ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.