Class: Tkellem::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/tkellem/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(username, password) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/tkellem/models/user.rb', line 25

def self.authenticate(username, password)
  authentication_methods.each do |m|
    result = m.call(username, password)
    return result if result.is_a?(self)
  end
  nil
end

Instance Method Details

#admin?Boolean



50
51
52
# File 'lib/tkellem/models/user.rb', line 50

def admin?
  role == 'admin'
end

#nameObject



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

def name
  username
end

#password=(password) ⇒ Object



46
47
48
# File 'lib/tkellem/models/user.rb', line 46

def password=(password)
  write_attribute(:password, password ? OpenSSL::Digest::SHA1.hexdigest(password) : nil)
end

#username=(val) ⇒ Object



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

def username=(val)
  write_attribute(:username, val.try(:downcase))
end

#valid_password?(password) ⇒ Boolean



41
42
43
44
# File 'lib/tkellem/models/user.rb', line 41

def valid_password?(password)
  require 'openssl'
  self.password == OpenSSL::Digest::SHA1.hexdigest(password)
end