2

I have a couple of issues regarding administering users passwords from the front-end of my site.

Firstly, I'm trying to implement the Set Password form as listed at https://craftcms.com/docs/templating/set-password-form.

I have created a single pointing to the path specified in the setPasswordPath config entry, using a template containing the above form. However, when I navigate to the setPasswordPath page it is erroring saying that 'Variable "code" does not exist'. When I remove the hidden code field, the id variable errors in the same way.

Secondly, the forgot password form listed at https://craftcms.com/docs/templating/forgot-password-form works great, except for when the user navigates to the link in the e-mail, and then enters their new password, they are redirected the Craft dashboard login, which a lot of the end users should never really see. Is it possible to redirect people to my home page login form on the front-end?

6

The form that lives at setPasswordPath assumes that the user arrived there by clicking on the link in the validation email that was sent to the provided email address. That link includes a code=somelongid querystring parameter in the URL that the form is looking for.

If you're just loading that URL directly, then you'll get the "Variable 'code' does not exist" error. You could always do something like this to guard against it:

{% set code = craft.request.getParam('code') %}

{% if not code %}
    {% exit 503 %}
{% endif %}

Regarding the forgot password form, upon successfully setting their new password, Craft will check to see if the user has control panel access. If they do not, it will check the setPasswordSuccessPath config variable and redirect there. If they do, Craft will send them to the dashboard (which will redirect to the login page if you don't have autoLoginAfterAccountActivation set.

  • I'm still a bit unsure about the setPasswordPath mechanic. Can I load that form directly with no code query parameter? You have it exiting there, whereas I want to display the form. If I check whether it is set and then don't include the hidden code field if it isn't, submitting the form ends up with the same problem. – Alex H Jul 3 '14 at 15:13
  • No, that form is only meant to be displayed when the user clicks the link in the email, whether that was generated from an account activation email, or a forgot password email. The code in the querystring is absolutely necessary. The additional check I gave in the example is just for if you're worried people will try to load the template directly. – Brad Bell Jul 3 '14 at 15:24
  • Ah, okay, that makes sense, thanks. Is there a way to integrate change password functionality with the User Profile form? Or is the only way to change password via the email? – Alex H Jul 3 '14 at 15:38
  • Yeah, but we don't exactly have that documented yet. Basically it's a combination of buildwithcraft.com/docs/templating/user-profile-form and buildwithcraft.com/docs/templating/user-registration-form. But users/saveProfile is no longer necessary and you can just call users/saveUser. Also, when changing the password of an existing user, you need to inputs, one called "password" which is the user's existing password, and "newPassword", which is the new one. Craft will validate the existing one before updating to the new one. – Brad Bell Jul 3 '14 at 15:44
  • 1
    Also, feel free to mark this as the answer as well. :) – Brad Bell Jul 3 '14 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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