Sha256: 57110e3562717e2243bf2d18736edc8071204fdf2a9a93fbeb94fb05d0d5e71b

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 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? }

    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

5 entries across 5 versions & 1 rubygems

Version Path
jobshop-0.0.41 app/models/jobshop/user.rb
jobshop-0.0.37 app/models/jobshop/user.rb
jobshop-0.0.29 app/models/jobshop/user.rb
jobshop-0.0.23 app/models/jobshop/user.rb
jobshop-0.0.16 app/models/jobshop/user.rb