Class: Gaku::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gaku/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loginObject

Returns the value of attribute login.



11
12
13
# File 'app/models/gaku/user.rb', line 11

def 
  @login
end

Class Method Details

.find_first_by_auth_conditions(warden_conditions) ⇒ Object

Override Devise::Models::Authenticatable#find_first_by_auth_conditions so login can be authenticated against username or email



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/gaku/user.rb', line 25

def self.find_first_by_auth_conditions(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

#role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

def role?(role)
  roles.where(name: role.to_s.camelize).any?
end

#to_sObject



19
20
21
# File 'app/models/gaku/user.rb', line 19

def to_s
  username
end