Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created January 30, 2016 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevesohcot/fbb938fbb2df0bd2de08 to your computer and use it in GitHub Desktop.
Save stevesohcot/fbb938fbb2df0bd2de08 to your computer and use it in GitHub Desktop.
OmniAuth - User model
class User < ActiveRecord::Base
validates_uniqueness_of :email
def self.from_omniauth(auth,params)
find_by(provider: auth.provider, uid: auth.uid) || create_from_omniauth(auth,params)
end
def self.create_from_omniauth(auth,params)
create! do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.user_hash = SecureRandom.uuid.gsub(/\-/,'') # Used for the "remember me" cookie
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment