Created
January 30, 2016 19:46
-
-
Save stevesohcot/fbb938fbb2df0bd2de08 to your computer and use it in GitHub Desktop.
OmniAuth - User model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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