默认情况下,devise使用电子邮件地址进行注册并登录。
但我希望用户可以更改电子邮件地址。
如果我允许用户编辑电子邮件地址,并且用户指定“不正确”(即错误拼写错误)电子邮件地址,然后用户注销,和用户也会忘记错误的电子邮件是,用户现在无法访问用户帐户!
如何最好地解决这个问题? (除了创建一个单独的,不可更改的用户名字段,始终允许用户登录)
答案 0 :(得分:12)
如果他更改了电子邮件,您可以强制用户再次确认其帐户。
有一次,您更新了相关用户的密码,您需要取消确认该用户,然后重新发送确认电子邮件。
取消确认用户:
user = User.find(1)
if user.confirmed?
user.confirmed_at = nil
user.save(:validate => false)
end
要重新发送电子邮件确认信息:
user = User.find(1)
user.send_confirmation_instructions
希望这有帮助!
答案 1 :(得分:9)
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
在confirmable module中,您可能会看到它是如何运作的。