Change user's email without verification

Maybe I’m missing something obvious, but I cannot find it. As an admin, can I change someone’s email address without them having to verify it?

Off-hand, I’d guess something like this would work:

cd /var/discourse
./launcher enter app
rails c
User.find_by(email: "chowder@mmmm.fooo").update(email: "bisque@soup.mmmm")
exit
exit

That’s console access, obviously.

3 个赞

I vaguely recall another topic here about this exact situation; try some searches.

1 个赞

Try this, the verification mail goes out, but they don’t have to respond to it:

Too late for me to edit that now, but it should be deactivate, change, reactivate iirc.

4 个赞

No problem I made it a wiki.

2 个赞

I am a new discourse user and I ran into the same issue. When I try the same approach (deactivate the user, update the email address, and then activate the user) it sending an email to confirm and it is only updating the email address after clicking the confirm email link. Is there a way to avoid this? I am using the API to do all the three actions.

There has been a change in the way emails are stored in the database.

The following commands should work:

cd /var/discourse
sudo ./launcher enter app
rails c

UserEmail.find_by(email: "oid@example.com").update(email: "new@example.com")
7 个赞

This will work fine but I am trying to do this via API as I will have to update multiple email addresses on a daily basis. Is it possible to do this via API?

3 个赞

大规模死灵法术,是的,但我遇到了类似的问题,既然搜索把我带到了这里,根据我的经验更新相关命令可能是有必要的。

我的情况如下:

  • 我的一些用户尝试更改他们的主要电子邮件地址。

  • 他们声称操作未成功。他们收到了确认邮件,但点击链接时总是显示“已过期/无效”的错误信息。

  • 我以管理员身份进入,通过编辑他们的资料来更改该电子邮件地址。

  • 现在主要电子邮件显示为“等待确认/验证”。

  • 用户没有收到任何确认邮件。

  • 无论我在他们的资料页面点击多少次“重新发送验证/确认邮件”选项,邮件都不会发出(我在管理员/邮件部分检查过,没有该邮件的发出记录。具有讽刺意味的是,如果我点击发送“重置密码邮件”,那封邮件确实会发出)。

问题是,如果这些用户中的任何一人清除了 Cookie 等数据,他们将无法再次访问自己的账户(实际上这种情况现在正在发生)。所以我尝试了以下方法:

但我遇到了 NoMethodError: undefined method `update' for nil:NilClass 错误。所以也许这两个字段在过去两年中又发生了变化?:stuck_out_tongue:

欢迎提供任何帮助。

附注:此外,如果我尝试将电子邮件更改为其他地址或改回旧地址,我现在(作为管理员)会收到“您执行此操作的次数过多,请稍后再试”的提示。这个“稍后”具体是多久?为什么管理员在更改电子邮件时会受到速率限制,而我只操作了一次?我可能做错了什么但没意识到::facepalm:

1 个赞

因此,邮件发送功能是正常的,可能是服务器时间不正确?如果您的服务器时间有误,就可能出现这种情况。

在我这里可以正常工作!如果你仍然遇到这个问题(或者任何找到这个主题的人 :sweat_smile:),我想如果 UserEmail.find_by(email: "oid@example.com") 没有返回任何结果,就会出现该错误。值得仔细检查一下邮箱地址是否完全匹配。

1 个赞