簡體   English   中英

設計skip_confirmation! 無法避免發送確認指示

[英]Devise skip_confirmation! fails to avoid to send the confirmation instructions

我的應用程序已設置好,如果用戶使用Oauth或Openid登錄,則無需確認其電子郵件地址。 但是,Devise仍在發送電子郵件確認。 當我調用User.skip_confirmation時! 我得到一個未定義的方法錯誤。 我的模特:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, 
  :trackable, :validatable, :confirmable, :lockable, :token_authenticatable, :omniauthable

  attr_accessible :username, :email, :password, :password_confirmation, :remember_me
  validates_presence_of :username
  validates_uniqueness_of :username, :case_sensitive => false

  def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
    data = access_token.extra.raw_info
    if user = User.where(:email => data.email).first
      user
    else 
      #User.skip_confirmation!
      User.create!(:username => data.name, :email => data.email, :password =>    Devise.friendly_token[0,20]) 
    end
  end

  def skip_confirmation!
   self.confirmed_at = Time.now
 end
end

我的控制器:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
    @user.skip_confirmation!
    if @user.persisted?
      sign_in @user
      @fname = @user.username
      redirect_to root_path, :flash => { :success => "Welcome #{@fname}!" }
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
end

謝謝你的幫助。

在創建User對象並將其持久保存到數據庫之前,您需要跳過確認。 因此,方法的用戶創建部分看起來像

user = User.new(:username => data.name, :email => data.email, :password =>    Devise.friendly_token[0,20])
user.skip_confirmation!
user.save

如果您要更新用戶記錄,請確保使用skip_reconfirmation! (介意重新

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM