如何"安全地"更改设备中的用户的电子邮件地址?

Zab*_*bba 7 devise ruby-on-rails-3

默认情况下,设计使用电子邮件地址进行注册和登录.

但我希望用户可以更改电子邮件地址.

如果我允许用​​户编辑电子邮件地址,并且用户指定"不正确"(即错误拼写错误)电子邮件地址,然后用户注销,并且用户也忘记错字电子邮件是什么,现在是用户帐户是用户无法访问的!

如何最好地解决这个问题?(除了创建一个单独的,不可更改的用户名字段,始终允许用户登录)

Ark*_*kan 12

如果他更改了电子邮件,您可以强制用户再次确认其帐户.

一旦您更新了相关用户的密码,您需要取消确认该用户,然后重新发送确认电子邮件.

要取消确认用户:

user = User.find(1)
if user.confirmed?
  user.confirmed_at = nil
  user.save(:validate => false)
end
Run Code Online (Sandbox Code Playgroud)

要重新发送电子邮件确认:

user = User.find(1)
user.send_confirmation_instructions
Run Code Online (Sandbox Code Playgroud)

希望这有帮助!


per*_*ine 11

Devise开箱即用.以下是初始化程序的信息:

# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
Run Code Online (Sandbox Code Playgroud)

在可确认模块中,您可以看到它是如何工作的.