大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 使用omniauth时设计跳过确认,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
user.rb:
# Finds or creates user based on omniauth hash from given provider def self.from_omniauth(auth) where(provider: auth.provider,uid: auth.uid).first_or_create do |user| user.provider = auth.provider user.uid = auth.uid user.first_name = auth.info.first_name user.last_name = auth.info.last_name user.email = auth.info.email end end # Overrides class method 'new_with_session' to persist and validate attributes def self.new_with_session(params,session) if session["devise.user_attributes"] new(session["devise.user_attributes"],without_protection: truE) do |user| user.attributes = params user.valid? end else super end end
omniauth_callBACks_controller.rb
class Users::OmniauthCallBACksController < Devise::OmniauthCallBACksController def all user = User.from_omniauth(request.env["omniauth.auth"]) if user.persisted? flash.notice = "Signed in!" sign_in_and_redirect user else session["devise.user_attributes"] = user.attributes redirect_to new_user_registration_url end end alias_method :facebook,:all end
def self.from_omniauth(auth) where(provider: auth.provider,uid: auth.uid). first_or_initialize do |user| user.provider = auth.provider user.uid = auth.uid user.first_name = auth.info.first_name user.last_name = auth.info.last_name user.email = auth.info.email user.skip_confirmation! user.save! end end
以上是大佬教程为你收集整理的ruby-on-rails – 使用omniauth时设计跳过确认全部内容,希望文章能够帮你解决ruby-on-rails – 使用omniauth时设计跳过确认所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。