Skip to content

Instantly share code, notes, and snippets.

@kaileeagray
Created August 23, 2016 15:07
Show Gist options
  • Save kaileeagray/21d073cf3e223df06fc4b0bbdfa8ce94 to your computer and use it in GitHub Desktop.
Save kaileeagray/21d073cf3e223df06fc4b0bbdfa8ce94 to your computer and use it in GitHub Desktop.

Revisions

  1. kaileeagray created this gist Aug 23, 2016.
    14 changes: 14 additions & 0 deletions user.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    class User < ApplicationRecord
    validates :email, :presence => true
    validates :email, :uniqueness => true
    has_secure_password


    def self.find_or_create_by_omniauth(auth)
    oauth_email = auth["info"]["email"] || auth["info"]["nickname"] || auth["info"]["name"]
    self.where(:email => oauth_email).first_or_create do |user|
    user.password = SecureRandom.hex
    end
    end
    end