Class: User

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Authorizable
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorizable

#is?, #roles, #roles=

Instance Attribute Details

#loginObject

Virtual attribute for authenticating by either username or email



7
8
9
# File 'app/models/user.rb', line 7

def 
  @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
   = conditions.delete(:login)
  if 
    where(conditions).where(['lower(username) = :value OR lower(email) = :value', { value: .downcase }]).first
  else
    where(conditions).first
  end
end

Instance Method Details

#active_for_authentication?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


37
38
39
# File 'app/models/user.rb', line 37

def disabled?
  !self.enabled
end

#display_nameObject



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

Returns:

  • (Boolean)


33
34
35
# File 'app/models/user.rb', line 33

def enabled?
  self.enabled
end

#inactive_messageObject



53
54
55
# File 'app/models/user.rb', line 53

def inactive_message
  I18n.t('chaltron.users.inactive_message')
end

#ldap_user?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/user.rb', line 29

def ldap_user?
  provider == 'ldap'
end