agenda-libre-ruby/app/models/user.rb

47 lines
1014 B
Ruby
Raw Normal View History

require 'digest/md5'
# Moderators, but using a failed pwd mechanism
# TODO, migrate to full active_admin
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, authentication_keys: [:login]
# :registerable, :validatable
2014-01-06 11:22:39 +01:00
has_many :notes
2014-09-03 02:14:21 +02:00
validates :login, presence: true
def encrypted_password=(pass)
self[:password] = pass
end
def encrypted_password
self[:password]
end
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
if login.present?
2016-10-15 16:39:15 +02:00
where(conditions).find_by login: login
else
find_first(conditions)
end
end
def valid_password?(password)
encrypted_password == password_digest(password)
end
2014-06-09 12:18:40 +02:00
def to_s
"#{firstname} #{lastname}"
end
protected
def password_digest(password)
Digest::MD5.hexdigest password
end
2013-11-14 10:54:09 +01:00
end