php - Zend_Auth 和动态更改 UI 上的用户详细信息

标签 php zend-framework

当我的用户登录时,我会在 UI 上显示他们的详细信息(姓名、电子邮件)。当他们更新个人资料时,我想显示更新的详细信息,而不需要用户注销并重新登录。

UI 详细信息通过 View 助手从 Zend_Auth 检索。 Zend_Auth 将“身份”详细信息存储在 session 中。

我应该如何更新 session 中的详细信息?:

  • 我正在考虑从数据库中检索用户的登录凭据并使用它们再次调用 Zend_Auth->authenticate()。问题是我不知道密码,只知道它是 md5 哈希。我可以考虑一种新方法 reauthenticate(),它将适配器配置为绕过 md5 和 salt,但这听起来很费力。

  • 我正在考虑直接写入 Zend_Auth session 命名空间,但这听起来像是一个麻烦的秘诀?

你遇到过类似的问题吗?你是怎么处理的?

非常感谢您的想法!

最佳答案

您可以为当前登录的用户更新 Zend_auth 身份。仅更新用户名的非常简化的操作如下:

 public function editAction() {


    // check if user is logged, etc, and then
    // show the edit user form and process the data after submission.

    $userForm = new My_Form_EditUser();       


    if ($this->getRequest()->isPost()) {
        if ($userForm->isValid($_POST)) {

            // process the submitted data,
            // and when you are sure  that everything went ok,
            // update the zend_auth identity


            $authData = Zend_Auth::getInstance()->getIdentity();

            // this line would depend on the format of your 
            // identity data and a  structure of your 
            // actual form. 
            $authData->property->nickname = $formData['user']['nickname'];

            $this->_helper->FlashMessenger('Your data was changed');
            return $this->_redirect('/');
        }
    }       

    $this->view->form = $userForm;
}

希望这对您有所帮助。

关于php - Zend_Auth 和动态更改 UI 上的用户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6938884/

相关文章:

zend-framework - 使用 Doctrine ODM 将 Zend Framework 1.11 与 MongoDB 集成

zend-framework - Zend_Mail - 通过 POP 阅读 Gmail 邮件

mysql - 如何从 zend 框架 View (phtml) 查询数据库?

php - 在 zend 框架中的另一个模块中查看模块的输出

php - Zend Framework - 并未显示所有错误

PHP如何创建从方法调用返回为字符串的类的实例

php - 这是什么编码?

php - 如何获取数组的切片,其中日期是数组的键?

php - 确定美国本地/国际电话号码

php - phantomJS : Absolute path working, 但相对路径给出问题