class User < ApplicationRecord has_many :screenshots, :inverse_of=>:user # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, # :registerable, # :recoverable, # :rememberable, :trackable, # :validatable, :timeoutable, # :lockable, :omniauthable, :omniauth_providers => [ :launchpad, :stackexchange, :google_oauth2, :amazon, :github ] # Return a human-friendly string describing the user's SSO provider def pretty_provider case self.provider when 'launchpad' 'Ubuntu One/Launchpad' when 'stackexchange' 'StackExchange' when 'google_oauth2' 'Google' when 'amazon' 'Amazon' when 'github' 'GitHub' when 'debian-sso' 'Debian single-signon' else 'local authentication' end end def is_admin? self.admin == 1 end def self.from_omniauth(auth) where(provider: auth.provider, email: auth.info.email).first_or_create do |user| user.provider = auth.provider user.uid = auth.uid user.email = auth.info.email user.name = auth.info.name # Set a random password user.password = Devise.friendly_token[0,20] end end end