gpt4 book ai didi

ruby-on-rails - devise_invitable : Confirm after Invitation

转载 作者:行者123 更新时间:2023-12-04 05:59:11 26 4
gpt4 key购买 nike

我覆盖 设计 的确认!向我的用户发送欢迎消息的方法:

class User < ActiveRecord::Base

devise :invitable, :database_authenticatable, :registerable, :recoverable,
:rememberable, :confirmable, :validatable, :encryptable

# ...

# Devise confirm! method overriden
def confirm!
UserMailer.welcome_alert(self).deliver
super
end

end

使用 devise_invitable 当用户接受邀请并设置他的密码时, 确认! 方法永远不会被触发,是否可以强制它? devise_invitable 如何确认用户?

或者,也许我可以用同样的方式覆盖 accept_invite(或其调用的任何东西)方法?

我希望受邀用户保持未确认状态,然后在接受邀请时进行确认。

谢谢,非常感谢任何帮助!

Original Source

更新

查看 devise_invitable model 我发现了可能导致这种不当行为的两种方法:
  # Accept an invitation by clearing invitation token and confirming it if model
# is confirmable
def accept_invitation!
if self.invited? && self.valid?
self.invitation_token = nil
self.save
end
end

# Reset invitation token and send invitation again
def invite!
if new_record? || invited?
@skip_password = true
self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
generate_invitation_token if self.invitation_token.nil?
self.invitation_sent_at = Time.now.utc
if save(:validate => self.class.validate_on_invite)
self.invited_by.decrement_invitation_limit! if self.invited_by
!!deliver_invitation unless @skip_invitation
end
end
end

最佳答案

class User < ActiveRecord::Base
devise :invitable, :database_authenticatable, :registerable, :recoverable,
:rememberable, :confirmable, :validatable, :encryptable

# ...

# devise confirm! method overriden
def confirm!
welcome_message
super
end

# devise_invitable accept_invitation! method overriden
def accept_invitation!
self.confirm!
super
end

# devise_invitable invite! method overriden
def invite!
super
self.confirmed_at = nil
self.save
end

private

def welcome_message
UserMailer.welcome_message(self).deliver
end

end

关于ruby-on-rails - devise_invitable : Confirm after Invitation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6052376/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com