我有一个表单,在验证失败时,应该查询一个自定义/非Drupal表,如果该查询成功,则将用户重定向到一个只能通过登录状态访问的自定义页面(因此,我需要“伪造”成功的身份验证,即使该用户不存在于正式的Drupal user表中)。
对自定义表的查询本质上是在无法验证官方方式时以非Drupal格式检查辅助用户列表,如果成功,将将用户重定向到另一个页面,在那里他们可以选择Drupal用户名和密码组合,以便在系统中注册它们/创建一个正式帐户。
这是我的表单验证方法中的相关代码:
if ($this->userAuth->authenticate($form_state->getValue('name'), $password) == FALSE) {
// other stuff
$uid = $this->userAuth->authenticate($form_state->getValue('name'), $password);
$form_state->set('uid', $uid);
$response = new TrustedRedirectResponse('/path/destination');
$form_state->setResponse($response);
}我也尝试过这样做,而不是使用新的TrustedRedirectResponse:
$redirect_path = "/path/destination";
$url = url::fromUserInput($redirect_path);
$form_state->setRedirectUrl($url);发布于 2018-04-07 04:05:03
如果您希望重定向立即发生,您可以这样做:
use Symfony\Component\HttpFoundation\RedirectResponse;
$response = new RedirectResponse('/path/destination');
$response->send();https://drupal.stackexchange.com/questions/259334
复制相似问题