【问题标题】:allow users to change their own password, email and Profile允许用户更改自己的密码、电子邮件和个人资料
【发布时间】:2011-01-25 10:59:25
【问题描述】:

我正在创建自己的博客引擎来学习 Symfony,我有一个问题:

感谢 sfGuardUser 模块,我可以添加和编辑用户,但我怎样才能允许用户只编辑他们的记录?

用户应该有权访问允许他们编辑电子邮件、姓名、密码和个人资料的页面。

有什么想法吗?

【问题讨论】:

    标签: symfony1 sfguard sfdoctrineguard


    【解决方案1】:

    在更新配置文件的操作中,您通过getId() 方法检索用户对象并将更改应用于返回的对象。

    $user = sfGuardUserPeer::retrieveByPK(
      $this->getUser()->getGuardUser()->getId()
    );
    

    【讨论】:

      【解决方案2】:

      我找到了下面的代码,今晚试试。

      class sfGuardUserActions extends autoSfGuardUserActions {
      
      
          public function executeEdit(sfWebRequest $request) {
              $this->checkPerm($request);
              parent::executeEdit($request);
          }
      
          public function checkPerm(sfWebRequest $request) {
              $id = $request->getParameter('id');
      
              $user = sfContext::getInstance()->getUser();
              $user_id = $user->getGuardUser()->getId();
      
              if ($id != $user_id && !($user->hasCredential('admin'))) {
                  $this->redirect('sfGuardAuth/secure');
              }
          } }
      

      来自http://oldforum.symfony-project.org/index.php/m/96776/

      【讨论】:

      • 这通过禁止用户编辑另一个用户的个人资料来起作用,但它不能正确保存用户信息
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 2021-07-10
      • 2019-02-18
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      相关资源
      最近更新 更多