Score:1

Redirect user to a custom page after one time login

kn flag

If my user click to "forgot password", and email with a one-time login is sended.

When the user clicks the given link, he's redirected to this page /user/reset/$id with the user_pass_reset form (basically containing a single button for the one-time login)

I'd like to redirect to a custom page after the user clicked on the one-time login button, but can't find out why this code doesn't works

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function module_form_user_pass_reset_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
  $form['actions']['submit']['#submit'][] = '_module_user_reset_pass_form_submit';
}

function _module_user_reset_pass_form_submit(&$form, FormStateInterface $form_state) {
  $form_state->setRedirect('module.custom_reset_password_page');
}

I'm using drupal 9

Score:2
ne flag

Look at the code of the Login Destination module. But maybe the Password Reset Landing Page module is actually what you are looking for.

Because you normally also need to take care of having the users reset their passwords after accessing a one-time login link.

Users often forget to change their password after they use the one time login link in their password reset email. Forgetting to set their password will require them to request password reset link emails repeatedly, without fixing the underlying problem - namely that they haven't set their password to something they can remember.

The Password Reset Landing Page "PRLP" module enhances the original password reset landing page by letting a user set their new password at the same time they "log in" using the one-time-login link. It can also show a username and email address field. The password entry field can be configured to be mandatory. Other entry fields can be hidden through configuration and the page the user is taken to after login can be configured.

Also look at the Similar modules section of PRLP.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.