Guest User

Untitled

a guest
Feb 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class User < ApplicationRecord
  2. has_secure_password
  3. validates_presence_of :username, :email
  4. validates_uniqueness_of :username, :email
  5. validates :password, presence: {on: :create}, length: {minimum: 6}, confirmation: true
  6. validates :password_confirmation, presence: true, if: '!password.nil?'
  7.  
  8. def self.find_or_create_by_omniauth(auth_hash)
  9. random_pass = SecureRandom.hex
  10. self.where(email: auth_hash["info"]["email"]).first_or_create do |user|
  11. user.username = auth_hash["info"]["name"]
  12. user.provider = auth_hash["provider"]
  13. user.password = random_pass
  14. user.password_confirmation = random_pass
  15. end
  16. end
  17. end
Add Comment
Please, Sign In to add comment