Sha256: ce77890b6bca86407649df6348e4b34b84d185b2924c5240557627300b62345f
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literals: true module Jobshop class User < ApplicationRecord self.primary_keys = %i[ organization_id user_id ] after_initialize { self.user_id ||= SecureRandom.uuid if new_record? } belongs_to :organization, inverse_of: :users has_many :role_assignments, inverse_of: :user, foreign_key: %i[ organization_id user_id ] has_many :roles, through: :role_assignments has_many :sessions, inverse_of: :user, dependent: :destroy, foreign_key: %i[ organization_id user_id ] validates :email, presence: { if: :email_required? }, format: { if: :email_required?, with: /\A[^@\s]+@[^@\s]+\z/ }, uniqueness: { if: :email_changed?, scope: :organization_id, case_sensitive: false } validates :password_digest, presence: true validates :password, presence: { if: :password_required? }, confirmation: { if: :password_required? } has_secure_password def activate_session session_activations.activate(SecureRandom.hex).activation_token end def exclusive_session(id) session_activations.exclusive(id) end def session_active?(id) session_activations.active?(id) end private def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end def email_required? true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jobshop-0.0.163 | app/models/jobshop/user.rb |