Changing users email address

Hi,

I found the email template “confirm old email” which says that “Before we can change your email address, we need you to…”
How can I change any user email address? I cannot see any option in the profile, only the “show” option.

Are you using SSO? If so, it’s likely that your email addresses/usernames are being handled outside of native Discourse by the SSO authenticator.

no, SSO options are ticked off.

If users cannot change their email address themselves, I was wondering how can I change it for them.

There is a topic on this. Pls search.

Short answer: Deactivate the account, change email, reactivate.

2 Likes

Are you referring to staff? Only staff have the restriction that both emails must be confirmed for security reasons.

It does not work anymore. :frowning:

Can you be more specific? What exactly doesn’t work anymore?

2 Likes

Also, selecting user, then Show Public Profile, Preferences. Here one can change the email

Nope. Not any more. It seems to send an email asking for verification.

This topic is asking how to change the email address without the verification step.

The way to do this now is:

1 Like

I just tried this (assuming that the cd /var/discourse is a line by itself and that sudo … is a separate line) and I just got the error:

-bash: syntax error near unexpected token ‘(’

Then I tried

cd /var/discourse 
sudo ./launcher enter app rails c UserEmail.find_by(email: "oid@example.com").update(email: "new@example.com")

which didn’t work and then I tried

cd /var/discourse 
sudo ./launcher enter app rails c 
UserEmail.find_by(email: "oid@example.com").update(email: "new@example.com")

(using the appropriate email addresses of course) and got the error

bash: syntax error near unexpected token `email:'

So how exactly should this be entered?

Four lines, just as shown in the linked topic:

  1. cd /var/discourse
  2. sudo ./launcher enter app
  3. rails c
  4. UserEmail.find_by(email: "oid@example.com").update(email: "new@example.com")
5 Likes

For the record, if you just read the text, you see everything merged into a single line

However, I had tried that and it didn’t seem to work either. Turns out one has to wait about 30 seconds and then I got a message “This monkey patch is no longer required”, then another 15 seconds delay and finally a prompt

 [1] pry(main)

and now it worked.

(I’m posting this in case anyone else runs into the same issue - quite likely if one is not experienced with ruby and rails, etc)

Thanks for the help.

Or you should click into the linked post and you’ll find that there are actually four commands in four separate lines.

What you see here is simply an excerpt of the post with all the line breaks removed and merged into one line in order to save space.

1 Like

Sorry but it was not obvious to me at the time. Maybe excerpts of posts that have commands in them should not have their line endings removed.

For some reason this seems to have stopped working for me. I did an edit on a users email but made a mistake with the name. Now every time I run :UserEmail.find_by(email: "oid@example.com").update(email: "new@example.com")
I get: NoMethodError: undefined method `update’ for nil:NilClass
Has something changed?

Try UserEmail.find_by(email: "oid@example.com") alone, if it returns nil, then it means there are no UserEmail records with that email address :wink:

3 Likes