Sha256: 6529b7c3603a8dc9bc2606a8c4148180da7e9776a2ba4580b071147178961729
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
module Jobshop class User < ApplicationRecord self.primary_keys = :organization_id, :user_id has_secure_password after_create do self.class.connection.clear_query_cache @attributes = self.class.unscoped { self.class.find_by!(organization: organization, email: email) }.instance_variable_get(:@attributes) @new_record = false self end belongs_to :organization, inverse_of: :users has_many :role_assignments, inverse_of: :user, foreign_key: [ :organization_id, :user_id ] has_many :roles, through: :role_assignments has_many :sessions, inverse_of: :user, dependent: :destroy, foreign_key: [ :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? } def name @name = [ forename, surname ].join(" ") end 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.157 | app/models/jobshop/user.rb |