Class: User
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- User
- Includes:
- Authorizable
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
-
#login ⇒ Object
Virtual attribute for authenticating by either username or email.
Class Method Summary collapse
-
.find_for_database_authentication(warden_conditions) ⇒ Object
Devise method overridden to allow sign in with email or username.
Instance Method Summary collapse
- #active_for_authentication? ⇒ Boolean
- #disable! ⇒ Object
- #disabled? ⇒ Boolean
- #display_name ⇒ Object
- #enable! ⇒ Object
- #enabled? ⇒ Boolean
- #inactive_message ⇒ Object
- #ldap_user? ⇒ Boolean
Methods included from Authorizable
Instance Attribute Details
#login ⇒ Object
Virtual attribute for authenticating by either username or email
7 8 9 |
# File 'app/models/user.rb', line 7 def login @login end |
Class Method Details
.find_for_database_authentication(warden_conditions) ⇒ Object
Devise method overridden to allow sign in with email or username
19 20 21 22 23 24 25 26 27 |
# File 'app/models/user.rb', line 19 def self.find_for_database_authentication(warden_conditions) conditions = warden_conditions.dup login = conditions.delete(:login) if login where(conditions).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first else where(conditions).first end end |
Instance Method Details
#active_for_authentication? ⇒ Boolean
49 50 51 |
# File 'app/models/user.rb', line 49 def active_for_authentication? super && enabled? end |
#disable! ⇒ Object
45 46 47 |
# File 'app/models/user.rb', line 45 def disable! update!(enabled: false) end |
#disabled? ⇒ Boolean
37 38 39 |
# File 'app/models/user.rb', line 37 def disabled? !self.enabled end |
#display_name ⇒ Object
14 15 16 |
# File 'app/models/user.rb', line 14 def display_name fullname.presence || username end |
#enable! ⇒ Object
41 42 43 |
# File 'app/models/user.rb', line 41 def enable! update!(enabled: true) end |
#enabled? ⇒ Boolean
33 34 35 |
# File 'app/models/user.rb', line 33 def enabled? self.enabled end |
#inactive_message ⇒ Object
53 54 55 |
# File 'app/models/user.rb', line 53 def I18n.t('chaltron.users.inactive_message') end |
#ldap_user? ⇒ Boolean
29 30 31 |
# File 'app/models/user.rb', line 29 def ldap_user? provider == 'ldap' end |