Sha256: 8bfe2d0c917b30b96ce43461151d67047ce5e8271cee79f55d5ce91e741fa545

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

class User < ApplicationRecord
  devise :database_authenticatable, :registerable, :timeoutable,
         :recoverable, :rememberable, :trackable, :validatable,
         :doorkeeper, :omniauthable, omniauth_providers: [:mlh]

  has_one :questionnaire
  has_many :access_grants, class_name: "Doorkeeper::AccessGrant",
                           foreign_key: :resource_owner_id,
                           dependent: :delete_all # or :destroy if you need callbacks
  has_many :access_tokens, class_name: "Doorkeeper::AccessToken",
                           foreign_key: :resource_owner_id,
                           dependent: :delete_all # or :destroy if you need callbacks

  after_create :queue_reminder_email

  def active_for_authentication?
    true
  end

  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end

  def queue_reminder_email
    return if reminder_sent_at
    Mailer.delay_for(1.day).incomplete_reminder_email(id)
    update_attribute(:reminder_sent_at, Time.now)
  end

  def email=(value)
    super value.try(:downcase)
  end

  def first_name
    return "" if questionnaire.blank?
    questionnaire.first_name
  end

  def last_name
    return "" if questionnaire.blank?
    questionnaire.last_name
  end

  def full_name
    return "" if questionnaire.blank?
    questionnaire.full_name
  end

  def self.from_omniauth(auth)
    matching_provider = where(provider: auth.provider, uid: auth.uid)
    matching_email = where(email: auth.info.email)
    matching_provider.or(matching_email).first_or_create do |user|
      user.uid               = auth.uid
      user.email             = auth.info.email
      user.password          = Devise.friendly_token[0, 20]
    end
  end

  def self.without_questionnaire
    User.left_outer_joins(:questionnaire).where(questionnaires: { id: nil }, admin: false)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hackathon_manager-0.12.2 app/models/user.rb
hackathon_manager-0.12.1 app/models/user.rb
hackathon_manager-0.12.0 app/models/user.rb
hackathon_manager-0.11.2 app/models/user.rb
hackathon_manager-0.11.1 app/models/user.rb
hackathon_manager-0.11.0 app/models/user.rb
hackathon_manager-0.10.3 app/models/user.rb
hackathon_manager-0.10.2 app/models/user.rb
hackathon_manager-0.10.1 app/models/user.rb
hackathon_manager-0.10.0 app/models/user.rb