【问题标题】:how to avoid devise_invitable from sending a confirmation email?如何避免 devise_invitable 发送确认电子邮件?
【发布时间】:2013-03-18 20:25:01
【问题描述】:

从文档中我认为不应该发送确认电子邮件,但它正在这样做。

这是我对邀请操作的设置:

class Users::InvitationsController < Devise::InvitationsController

def multiple_create
    if params[:multiple_emails].blank?
        build_resource
        render :new, notice: "something went wrong"
    else
        params[:multiple_emails].each do |email|
            User.invite!({email: email}, current_user) # current_user will be set as invited_by
        end
        if current_user.errors.empty?
            set_flash_message :notice, :send_instructions, :email => params[:multiple_emails]
            respond_with current_user, :location => after_invite_path_for(current_user)
        else
            respond_with_navigational(current_user) { render :new }
        end
    end
end
end

【问题讨论】:

    标签: ruby-on-rails devise devise-confirmable devise-invitable


    【解决方案1】:

    对于必须使用:confirmable 进行用户注册并希望避免发送带有邀请的确认信的情况:

    class User < ApplicationRecord
      after_create :skip_confirmation_notification!, unless: Proc.new { self.invitation_token.nil? }
    end
    

    【讨论】:

    • :skip_confirmation! 如果您不希望将任何确认逻辑应用于此用户。 :skip_confirmation_notification! 将禁用信件,但仍会强制用户在允许他登录之前确认电子邮件
    【解决方案2】:

    为避免设计确认邮件,您必须从 User 模型中排除 :confirmable 选项。

    例如,改变:

     class User  
       devise :registerable, :confirmable
     end  
    

    收件人:

     class User  
       devise :registerable
     end  
    

    【讨论】:

    • 但如果您想确认未经邀请注册的用户怎么办?
    【解决方案3】:

    devise_invitable repo on github 的文档非常清楚地说明了如何跳过发送邀请电子邮件。查看Usage下的第二个代码sn -p,前面是这段文字:

    如果您想创建邀请但不发送,您可以设置 skip_invitation 为 true。

    【讨论】:

    • 我昨天加了一个答案,不知道在哪!我希望它跳过确认邮件,而不是邀请邮件。我入侵了邀请!方法并添加了 self.skip_confirmation!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 2016-09-22
    • 2012-11-19
    相关资源
    最近更新 更多