Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/users/user.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Schema Information
Table name: users
id :integer not null, primary key
username :string(32) default(""), not null
email :string(254) default(""), not null
first_name :string(32)
last_name :string(32)
title :string(64)
company :string(64)
alt_email :string(64)
phone :string(32)
mobile :string(32)
aim :string(32)
yahoo :string(32)
google :string(32)
encrypted_password :string(255) default(""), not null
password_salt :string(255) default(""), not null
last_sign_in_at :datetime
current_sign_in_at :datetime
last_sign_in_ip :string(255)
current_sign_in_ip :string(255)
sign_in_count :integer default(0), not null
deleted_at :datetime
created_at :datetime
updated_at :datetime
admin :boolean default(FALSE), not null
suspended_at :datetime
unconfirmed_email :string(254) default(""), not null
reset_password_token :string(255)
reset_password_sent_at :datetime
remember_token :string(255)
remember_created_at :datetime
authentication_token :string(255)
confirmation_token :string(255)
confirmed_at :datetime
confirmation_sent_at :datetime
Class Method Summary collapse
- .can_signup? ⇒ Boolean
-
.find_for_database_authentication(warden_conditions) ⇒ Object
Overrides Devise sign-in to use either username or email (case-insensitive) —————————————————————————-.
Instance Method Summary collapse
-
#ability ⇒ Object
Returns permissions ability object.
- #active_for_authentication? ⇒ Boolean
-
#awaits_approval? ⇒ Boolean
—————————————————————————-.
-
#destroyable?(current_user) ⇒ Boolean
Returns true if this user is allowed to be destroyed.
-
#emailable? ⇒ Boolean
Send emails to active users only —————————————————————————-.
-
#full_name ⇒ Object
—————————————————————————-.
-
#has_related_assets? ⇒ Boolean
Prevent deleting a user unless she has no artifacts left.
- #inactive_message ⇒ Object
-
#name ⇒ Object
—————————————————————————-.
- #password_required? ⇒ Boolean
-
#preference ⇒ Object
(also: #pref)
—————————————————————————-.
-
#set_individual_locale ⇒ Object
Override global I18n.locale if the user has individual local preference.
-
#suspend_if_needs_approval ⇒ Object
Suspend newly created user if signup requires an approval.
-
#suspended? ⇒ Boolean
—————————————————————————-.
-
#to_json(_options = nil) ⇒ Object
Generate the value of single access token if it hasn’t been set already.
- #to_xml(_options = nil) ⇒ Object
Class Method Details
.can_signup? ⇒ Boolean
200 201 202 |
# File 'app/models/users/user.rb', line 200 def can_signup? i[allowed needs_approval].include? Setting.user_signup end |
.find_for_database_authentication(warden_conditions) ⇒ Object
Overrides Devise sign-in to use either username or email (case-insensitive)
206 207 208 209 210 211 |
# File 'app/models/users/user.rb', line 206 def find_for_database_authentication(warden_conditions) conditions = warden_conditions.dup if login = conditions.delete(:email) where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { value: login.downcase }]).first end end |
Instance Method Details
#ability ⇒ Object
Returns permissions ability object.
170 171 172 |
# File 'app/models/users/user.rb', line 170 def ability @ability ||= Ability.new(self) end |
#active_for_authentication? ⇒ Boolean
120 121 122 |
# File 'app/models/users/user.rb', line 120 def active_for_authentication? super && confirmed? && !awaits_approval? && !suspended? end |
#awaits_approval? ⇒ Boolean
116 117 118 |
# File 'app/models/users/user.rb', line 116 def awaits_approval? suspended? && sign_in_count == 0 && Setting.user_signup == :needs_approval end |
#destroyable?(current_user) ⇒ Boolean
Returns true if this user is allowed to be destroyed.
176 177 178 |
# File 'app/models/users/user.rb', line 176 def destroyable?(current_user) current_user != self && ! end |
#emailable? ⇒ Boolean
Send emails to active users only
138 139 140 |
# File 'app/models/users/user.rb', line 138 def emailable? confirmed? && !awaits_approval? && !suspended? && email.present? end |
#full_name ⇒ Object
106 107 108 |
# File 'app/models/users/user.rb', line 106 def full_name first_name.blank? && last_name.blank? ? email : "#{first_name} #{last_name}".strip end |
#has_related_assets? ⇒ Boolean
Prevent deleting a user unless she has no artifacts left.
188 189 190 191 192 193 194 195 |
# File 'app/models/users/user.rb', line 188 def sum = %w[Account Campaign Lead Contact Opportunity Comment Task].detect do |asset| klass = asset.constantize asset != "Comment" && klass.assigned_to(self).exists? || klass.created_by(self).exists? end !sum.nil? end |
#inactive_message ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/users/user.rb', line 124 def if !confirmed? super elsif awaits_approval? I18n.t(:msg_account_not_approved) elsif suspended? I18n.t(:msg_invalig_login) else super end end |
#name ⇒ Object
101 102 103 |
# File 'app/models/users/user.rb', line 101 def name first_name.blank? ? username : first_name end |
#password_required? ⇒ Boolean
164 165 166 |
# File 'app/models/users/user.rb', line 164 def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end |
#preference ⇒ Object Also known as: pref
143 144 145 |
# File 'app/models/users/user.rb', line 143 def preference @preference ||= preferences.build end |
#set_individual_locale ⇒ Object
Override global I18n.locale if the user has individual local preference.
150 151 152 |
# File 'app/models/users/user.rb', line 150 def set_individual_locale I18n.locale = preference[:locale] if preference[:locale] end |
#suspend_if_needs_approval ⇒ Object
Suspend newly created user if signup requires an approval.
182 183 184 |
# File 'app/models/users/user.rb', line 182 def suspend_if_needs_approval self.suspended_at = Time.now if Setting.user_signup == :needs_approval && !admin end |
#suspended? ⇒ Boolean
111 112 113 |
# File 'app/models/users/user.rb', line 111 def suspended? suspended_at != nil end |
#to_json(_options = nil) ⇒ Object
Generate the value of single access token if it hasn’t been set already.
156 157 158 |
# File 'app/models/users/user.rb', line 156 def to_json( = nil) [name].to_json end |
#to_xml(_options = nil) ⇒ Object
160 161 162 |
# File 'app/models/users/user.rb', line 160 def to_xml( = nil) [name].to_xml end |