使用 Kohana 制作用户档案
我正在运行 Kohana 3,并且很难理解 Auth 模块,或者即使它是我所需要的。基本上我想创建一个具有基本用户名/密码保护的基本用户配置文件网站。
我如何使用现有的控制器...
class Controller_Profile extends Controller
{
function action_index( $user_id )
{
// User should already be authenticated by here I think
}
}
...并将它们与某种身份验证系统一起使用
I'm running Kohana 3, and having a hard time understanding the Auth module, or even if it's what I need. Basically I want to create a basic user profile site with basic username/password protection.
How do I take my existing controllers...
class Controller_Profile extends Controller
{
function action_index( $user_id )
{
// User should already be authenticated by here I think
}
}
...and use them with some sort of authentication system
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 Kohana 3,您需要在
之前
进行签入,而不是像 JIStone 建议的那样__construct
。简单易懂。您可以将其放入控制器中,并让所有需要身份验证的控制器来扩展它。
For Kohana 3 you'll want to do your check in
before
and not__construct
like JIStone suggests.Simple enough to understand. You can put this into a controller and have all the controllers that need authentication to extend that.
如果您要求用户注册控制器上的所有页面,您可以在
__construct()
语句中进行检查:这是我们使用的代码,但它是 Kohana 2,而不是 3 ,因此您需要根据您的目的进行一些调整。
If you will be requiring a user to be registered for all pages on the controller you can put a check in your
__construct()
statement:This is the code we use, but it is Kohana 2, not 3, so you will need to adjust a bit for your purposes.
我提供了一个简短演练的链接,用于安装和基本使用 Kohana 3 中的身份验证模块
一旦您的身份验证流程正常运行,您可以通过在 before() 方法中检查登录用户和正确的身份验证角色来保护某些控制器,或者为以下内容创建一个基本控制器:你所有的控制器将需要这项检查。如果用户未登录,请将他们重定向到登录页面,如果他们没有适当的访问级别(或角色),那么您可以向他们显示“拒绝访问”页面。
I have provided a link to a short walkthrough for the installation and basic usage of the Auth Module in Kohana 3
Once you have your Auth process working, you can protect certain controllers by checking for a logged in user and proper authentication role in your before() method, or create a base controller for all your controllers that will need this check. If the user is not logged in, redirect them to the login page, if they do not have the proper access level (or role), then you can show them an "Access Denied" page.