Class: User

Inherits:
ApplicationRecord show all
Defined in:
app/models/user.rb

Overview

Schema Information

Table name: users

id                     :integer          not null, primary key
email                  :string           default(""), not null
encrypted_password     :string           default(""), not null
reset_password_token   :string
reset_password_sent_at :datetime
remember_created_at    :datetime
sign_in_count          :integer          default(0), not null
current_sign_in_at     :datetime
last_sign_in_at        :datetime
current_sign_in_ip     :string
last_sign_in_ip        :string
created_at             :datetime         not null
updated_at             :datetime         not null
first_name             :string
last_name              :string
authentication_token   :string           not null
staff                  :boolean          default(FALSE), not null
failed_attempts        :integer          default(0), not null
unlock_token           :string
locked_at              :datetime
organizations_count    :integer          default(0)
active                 :boolean          default(TRUE)

Indexes

index_users_on_authentication_token  (authentication_token) UNIQUE
index_users_on_email                 (email) UNIQUE
index_users_on_reset_password_token  (reset_password_token) UNIQUE
index_users_on_unlock_token          (unlock_token) UNIQUE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_for_authentication(warden_conditions) ⇒ Object



63
64
65
# File 'app/models/user.rb', line 63

def self.find_for_authentication(warden_conditions)
  where(warden_conditions.merge(active: true)).first
end

Instance Method Details

#to_sString Also known as: name

Returns human-friendly name for this user, depending on which of the name columns are filled-in; falls back to email address

Returns:

  • (String)

    human-friendly name for this user, depending on which of the name columns are filled-in; falls back to email address



68
69
70
71
72
73
74
# File 'app/models/user.rb', line 68

def to_s
  if !first_name.blank? || !last_name.blank?
    [first_name, last_name].join(' ')
  else
    email
  end
end

#usernameObject

Note:

for audit log



79
80
81
# File 'app/models/user.rb', line 79

def username
  to_s
end