簡體   English   中英

在devise 2.0上跳過omniauth-twitter的電子郵件驗證

[英]Skip email validation for omniauth-twitter on devise 2.0

我正在使用devise 2.0和gem omn​​iauth-twitter

問題是twitter沒有響應發送電子郵件,因此我的應用程序的模型用戶驗證了有一封電子郵件,我在回調中收到以下錯誤:

Email can't be blank

我在我的user.rb模型中有這個:

#config omniauth twitter
def self.find_for_twitter_oauth(access_token, signed_in_resource = nil)
    data = access_token.extra.raw_info
    if user = User.where(:username => data.screen_name).first
        user
    else
        User.create!(:username => data.screen_name, :password => Devise.friendly_token)
    end
end

我在omn​​iauth_callbacks_controller.rb中有這個

  def twitter
    @user = User.find_for_twitter_oauth(request.env["omniauth.auth"], current_user)
    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
      sign_in_and_redirect @user, :event => :authentication
    else
      # http://stackoverflow.com/questions/7117200/devise-for-twitter-cookie-overflow-error
      session["devise.twitter_data"] = request.env["omniauth.auth"].except('extra')
      redirect_to new_user_registration_url
    end
   end

我希望用戶強制為發送簡報,廣告客戶等提供電子郵件地址

我該如何解決這個問題?

謝謝!

將其添加到您的用戶模型:

def email_required?
  super && provider.blank?
end

您可以使用等效的密碼方法:

def password_required?
  super && provider.blank?
end

這應該在使用Omniauth提供程序時覆蓋字段要求。

我面臨同樣的問題,Twitter沒有通過oauth給你發電子郵件,你必須以另一種方式思考獲取電子郵件。 我想出的唯一解決方案是覆蓋回調並使用twitter數據自動填充表單,並讓用戶有機會自己完成郵件,然后注冊並將用戶保存在數據庫中。

看下面的問題:

有沒有辦法在使用OAuth驗證他/她的Twitter身份后獲取用戶的電子郵件ID?

這里詳細解釋了一個解決方案: http//asciicasts.com/episodes/236-omniauth-part-2

在GitHub上: https//github.com/fertapric/rails3-mongoid-devise-omniauth/wiki/How-To :-Retrieve-email-information-(middle-step)-from-providers-like-Twitter- or -LinkedIn

出於某種原因,這個問題在Google的排名中比這些鏈接更高,所以我想我會將它們添加到答案中。

您需要刪除電子郵件字段的狀態驗證。 請關注此帖 ,看看是否有效。 對於遲到的回復感到抱歉,希望這有幫助。

暫無
暫無

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

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