[英]Devise: How do I invalidate or cancel an email confirmation token?
In Devise 2.2.3 and Rails 3.2.x, I want to create a routine whereby users can manually invalidate a confirmation token/email that they may have sent to the wrong email address. 在Devise 2.2.3和Rails 3.2.x中,我想创建一个例程,使用户可以手动使可能已发送到错误电子邮件地址的确认令牌/电子邮件无效。
I'm thinking I need to nullify the unconfirmed email and the confirmation token. 我在想我需要取消未确认的电子邮件和确认令牌。 Is this right?
这是正确的吗?
I don't see anything on Google or the Devise documentation about this procedure. 我没有在Google或Devise文档中看到有关此过程的任何内容。
Scenario: 场景:
Thanks! 谢谢!
Since I don't want to unconfirm the user, I ended up doing this: 由于我不想取消确认用户,因此我这样做了:
def cancel_change_email!
self.confirmation_token = nil
self.unconfirmed_email = nil
self.save!
end
Seems to work. 似乎可以工作。 I threw this method into a module I'm including into the User model, but you can put it right into the user model if that's how you roll.
我将此方法放入了包含在User模型中的模块中,但是如果您采用这种方式,则可以将其正确放入用户模型中。 I guess this is easy enough, but I kinda figured it'd be built in to Devise.
我想这很容易,但是我有点想它会内置到Devise中。
I don't think Devise provides a method for it, but you can do it yourself like this: 我不认为Devise提供了一种方法,但是您可以自己这样做:
user = User.find(1)
user.confirmation_token = nil
user.confirmed_at = nil
user.save!
Yes, you can just manually nil stuff out in some sort of callback and then resend the confirmation instructions. 是的,您可以手动在某些回调中清除所有内容,然后重新发送确认说明。 But, you can also achieve this using Devise's support for reconfirmable, which can be used when a user changes their email address.
但是,您还可以使用Devise对reconfirmable的支持来实现此目的,该支持可在用户更改其电子邮件地址时使用。 If this is set the user is required to "reconfirm" their account, and you can even delay the email change until they successfully confirm again.
如果设置了此选项,则要求用户“重新确认”他们的帐户,您甚至可以延迟电子邮件更改,直到他们再次成功确认为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.