Change redirect in Drupal 7 for Password Recovery

五迷三道 提交于 2019-12-14 01:08:40

问题


In Drupal 7 there is a way to reset your password by going to '/user/password'. If you fill in your email address you should get an email in your inbox with an url to reset your password.

On that page you need to click 'login' and you get redirected to your profile page ('/user'). Is there maybe a way to edit this last redirect?

Thanks!


回答1:


You can change the content of the email sent to the user in admin/config/people/accounts.

The default content is the following one:

[user:name],

A request to reset the password for your account has been made at [site:name].

You may now log in by clicking this link or copying and pasting it to your browser:

[user:one-time-login-url]

This link can only be used once to log in and will lead you to a page where you can set your password. It expires after one day and nothing will happen if it's not used.

-- [site:name] team

If you are going to change the URL to which the user is directed, you need to write all the code to handle the password recovery request.

To have an idea of what Drupal does to handle a request of password reset, see user_pass_reset().




回答2:


I suppose it's better to look at user_pass_submit(). It makes

$form_state['redirect'] = 'user';

and redirects to /user page.

To make redirect to 'user/login' (for example) you have to add form alter hook and add one more submit callback:

/**
 * Implements hook_form_alter().
 *
 *
 */
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if ('user_pass' == $form_id) {
    $form['#submit'][] = '_password_recover_submit';
  }
}

function _password_recover_submit($form, &$form_state){
  $form_state['redirect'] = 'user/login';
}

This solution works for me.



来源:https://stackoverflow.com/questions/13952975/change-redirect-in-drupal-7-for-password-recovery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!