MITLibraries/QuickSubmit

View on GitHub
app/models/user.rb

Summary

Maintainability
A
0 mins
Test Coverage
# == Schema Information
#
# Table name: users
#
#  id         :integer          not null, primary key
#  email      :string           not null
#  uid        :string           not null
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  admin      :boolean          default(FALSE)
#

class User < ActiveRecord::Base
  if ENV['FAKE_AUTH_ENABLED'] == 'true'
    devise :omniauthable, omniauth_providers: [:developer]
  else
    devise :omniauthable, omniauth_providers: [:mit_oauth2]
  end

  has_many :submissions

  def self.from_omniauth(auth)
    where(uid: auth.uid).first_or_create do |user|
      user.email = auth.info.email
    end
  end
end