1

We are migrating users from a e-commerce site to a new craft commerce 2.x site.

Apparently it's a little too confusing for our customers to use the "forgot password" link to obtain a new password.

So our idea was to send them an email with their username and a link where they can directly set their password.

e.g. "user1", "https://mysite.com/actions/users/set-password?code=qwaZDk6mSa0tbnLBx8U4WkTnTBclK1ZZ&id=779e05ca-5c39-4f66-a56c-9a431bd0b355"

Is it possible to obtain these links programmatically.

We have about 800 users, so copy/pasting them would be very tedious.

any hints?

Cheers
Stefan

1 Answer 1

0

Given a list of elements/User that you want to get the password reset URL for, you can loop through them and call this for each one:

$url = Craft::$app->getUsers()->getPasswordResetUrl($user)'
2
  • Hi, I wanted to do this in a template. I've discovered that the password reset link is a combination of the "uid" and a code: /actions/users/set-password?code=<code>&id=<uid>. I can fetch the uid with the following code: {% set users = craft.users().status(null).addSelect(['users.uid']).all() %}, but where does this "code" come from?
    – outline4
    Nov 18, 2019 at 10:56
  • 1
    I am sorry... I've discovered that you can use: {{ craft.app.getUsers.getPasswordResetUrl(user) }}. Works like a charm! Thanks!
    – outline4
    Nov 18, 2019 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.