briannesbitt/Slim-ContextSensitiveLoginLogout

语言: PHP

git: https://github.com/briannesbitt/Slim-ContextSensitiveLoginLogout

回应
In response to
README.md (中文)

使用重定向登录/注销

为了回应http://help.slimframework.com/discussions/questions/341-loginlogout-with-redirect,我创建了这个示例Web应用程序。

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)

启动浏览器到http://127.0.0.1

此应用程序使用路由中间件进行身份验证,并使用slim.before.dispatch挂钩为所有视图设置$ user变量,实际上用户已登录。

公共页面

在任何公共页面中,您都可以单击“登录”,它将重定向到登录页面,并在成功登录后重定向回到之前浏览的页面。这部分是通过javascript来捕获登录点击的当前URL和通过会话(cookie)来存储要重定向到的URL。

私人网页

如果您尝试访问私人页面,这也有效。如果您尚未登录并尝试访问http://127.0.0.1/private/goodstuff,则会看到您未经过身份验证,存储该URL并将您转发到登录页面。然后,一旦成功登录,请将您重定向回所请求的私人页面。这都是通过会话(cookies)完成的。

页面导航

页面导航仅根据需要显示“登录”或“注销”,并仅在用户登录后显示私有页面。

咦?

如果您不知道我在说什么,请先访问Slim Framework。

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

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.