使用sfguarduser进行身份验证,无需http登录

mar*_*ial 1 php symfony1 sfguard

我正在尝试在基于symfony的应用程序中开发web服务,我们正在使用sfguarduser插件,并且我希望在单次请求中获取用户凭据以检查用户权限然后执行webservice操作,有没有办法执行没有html表单登录的登录操作?

cva*_*mar 5

在您的操作中执行以下操作:

$this->getUser()->signin($sfGuardUserObject);
Run Code Online (Sandbox Code Playgroud)

您必须使用sfGuardUser的对象调用.您可以将此代码放在模块的preExecute()方法中,以检查每个请求.

当我做"激活帐户"操作时,我做了类似的事情.帐户创建后会发送带有令牌的电子邮件,其中包含返回该站点的链接.令牌在URL中发送,并在路由中与操作匹配.然后,操作检查用户是否具有该令牌,然后将用户登录.这就是我所做的:

public function executeActivate(sfWebRequest $request)
{
  // if token is not present, forward to 404
  $this->forward404Unless($request->getParameter('token'), 'page', 'index');

  $this->profile = sfGuardUserProfilePeer::activateProfileByToken($request->getParameter('token'));

  // if someone was activated, return the mobile activation form and success page
  if (!$this->profile)
  {
    $this->redirect404();
  }

  // sign the user in
  $this->getUser()->signin($this->profile->getsfGuardUser());

  // set the $user variable for the template
  $this->user = $this->profile->getsfGuardUser();

}
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你.