Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. # Include default devise modules. Others available are:
  3. # :token_authenticatable, :confirmable, :lockable and :timeoutable
  4. devise :database_authenticatable, :registerable,
  5. :recoverable, :rememberable, :trackable, :validatable
  6.  
  7. # Setup accessible (or protected) attributes for your model
  8. attr_accessible :email, :password, :password_confirmation, :remember_me
  9.  
  10. has_many :authentications
  11.  
  12. def apply_omniauth(omniauth)
  13. if email.blank?
  14. self.email = omniauth['user_info']['email'] ||
  15. omniauth['extra']['user_hash']['email']
  16. end
  17.  
  18. if name.blank?
  19. self.name = omniauth['user_info']['first_name'] + ' ' +
  20. omniauth['user_info']['last_name']
  21. end
  22.  
  23. authentications.build(
  24. :provider => omniauth['provider'],
  25. :uid => omniauth['uid']
  26. )
  27. end
  28.  
  29. def password_required?
  30. (authentications.empty? || !password.blank?) && super
  31. end
  32.  
  33. end
Add Comment
Please, Sign In to add comment