Zend_Auth 最佳实践 [英] Zend_Auth best practices

查看:23
本文介绍了Zend_Auth 最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是要求某些页面登录.我正在使用 Zend Framework MVC,并且正在尝试查找有关最佳实践的示例.

My goal is to require login for certain pages. I am using Zend Framework MVC, and I'm trying to find examples regarding best practices.

关于我正在寻找的内容的一些说明:

Some notes on what I'm looking for:

  • 我希望未登录的用户获得一个登录框,然后在通过身份验证后返回到登录版本的页面
  • 我想使用依赖注入,避免单例
  • 代码占用空间小 - 与 Zend mvc 结构相结合
  • 登录框应该是一个单独的控制器并进行标头重定向吗?认证成功后如何返回登陆页面?简单地调用登录控制器操作以在登录页面中显示登录框的想法,或者这是否是搜索引擎索引的缺点?
  • 能够使用外部库来处理 cookie

或者完全不同的东西.我对 Zend 框架还很陌生,我想以正确的方式"来做.

Or something completely different. I'm fairly new to the Zend framework, and I want to do it 'the right way'.

推荐答案

  • 我想让非登录用户得到一个登录框,然后返回到登录状态在页面的版本中,一次已认证

使用 FrontController 插件 并重定向或转发它们到您的登录操作.

Use a FrontController plugin and redirect or forward them to your loginAction.

  • 我想使用依赖注入,避免单例

Zend 框架,目前不提供任何 DI 系统,但是 Zend_Application_Resource_* 实际上取代了它.这里需要什么样的依赖?

Zend Framework, doesn't currently ship any DI system, however, the Zend_Application_Resource_* actually replace it. What kind of dependency would you need here?

  • 代码占用空间小 - 与 Zend mvc 结构相结合

这取决于你.

  • 登录框应该是一个单独的控制器并进行标头重定向吗?如何认证后返回登陆页面成功?一个简单地调用的想法登录控制器操作以显示登陆页面中的登录框,或者这是搜索的缺点引擎索引?

我主要使用一个特殊的 AuthControllerLoginAction &注销操作.为了将用户重定向到试图查看的页面,我总是在我的表单中添加一个 returnUrl 元素,并注入请求的 URL 的值以便能够重定向用户,如果没有,我将他重定向到索引/仪表板,这取决于.

I mostly use a special AuthController with LoginAction & LogoutAction. To redirect the user to the page is was trying to view, I always add a returnUrl element in my forms, and I inject the value of the requested URL to be able to redirect the user, and if none, I redirect him to the index/dashboard, depends.

  • 能够使用外部库来处理 cookie

Zend_Auth 允许您设置您的 自己的存储机制,所以只需要实现接口即可.

Zend_Auth allows you to set your own storage mechanism, so just implement the interface.

$auth = Zend_Auth::getInstance();
$auth->setStorage(new My_Auth_Storage());

但是从不将身份验证结果存储在 cookie 中,修改它并访问您的网站非常容易.

But never store authentication result in a cookie, it's so easy to modify it and access your website.

您还可以查看我的一个之前的答案.

You may also take a look to one of my previous answer.

这篇关于Zend_Auth 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆