且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Symfony sfDoctrineGuardPlugin 自定义登录查询

更新时间:2023-12-04 23:17:04

我想我找到了更好的解决方案.sfDoctrineGuard 插件有自己的后验证器,用于检查用户检索的可选可调用对象.

I think I found a better solution. sfDoctrineGuard plugin has its own post validator that checks for an optional callable for user retrival.

//app.yml
all:
  sf_guard_plugin:
    retrieve_by_username_callable: sfGuardUser::getForBackend

//sfGuardUser.class.php

  public static function getForBackend($username)
  {
    $query = Doctrine::getTable('sfGuardUser')->createQuery('u')
      ->leftJoin('u.Groups g')
      ->leftJoin('g.Permissions p')
      ->where('u.username = ? OR u.email_address = ?', array($username, $username))
      ->addWhere('u.is_active = ?', true)
      ->addWhere('p.name = ?', 'backend');

    return $query->fetchOne();
  }