Sha256: 9033f2bb3cfe7bcd9a954e3067972cd39c65c51a8c7bc9d09006c34c08bc0eaa

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

module Jobshop
  class User < ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :recoverable, :rememberable

    belongs_to :team, optional: true
    has_one :default_dashboard, class_name: "Jobshop::Dashboard", through: :team

    validates :email,
      presence:   { if: :email_required? },
      format:     { if: :email_required?, with: /\A[^@\s]+@[^@\s]+\z/ },
      uniqueness: { if: :email_changed?, scope: :team_id }

    validates :password,
      presence:     { if: :password_required? },
      confirmation: { if: :password_required? }

    def self.find_for_authentication(warden_conditions)
      where(email:   warden_conditions[:email],
            team_id: warden_conditions[:team_id]).first
    end

    def onboard?
      # TODO: Implement this correctly.
      false
    end

  private
    def generate_email_authentication_token
      loop do
        token = Devise.friendly_token
        break token unless Jobshop::User.where(email_authentication_token: token).first
      end
    end

    def password_required?
      !persisted? || !password.nil? || !password_confirmation.nil?
    end

    def email_required?
      true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jobshop-0.0.101 app/models/jobshop/user.rb
jobshop-0.0.67 app/models/jobshop/user.rb
jobshop-0.0.61 app/models/jobshop/user.rb
jobshop-0.0.59 app/models/jobshop/user.rb