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

46 lines
1.1 KiB
Ruby

require 'digest/md5'
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, authentication_keys: [:login]
#, :registerable, :validatable
has_many :notes
def encrypted_password=(pass)
write_attribute :password, pass
end
def encrypted_password
read_attribute :password
end
def self.find_first_by_auth_conditions(warden_conditions)
logger.info 'XXXXXXXXX'
conditions = warden_conditions.dup
logger.info conditions
if login = conditions.delete(:login)
where(conditions).where(["login = :value", { value: login }]).first
else
where(conditions).first
end
end
def valid_password?(password)
encrypted_password == password_digest(password)
logger.info 'XXXXXXXXX'
logger.info encrypted_password
logger.info password_digest(password)
end
def to_s
"#{firstname} #{lastname}"
end
protected
def password_digest(password)
Digest::MD5.hexdigest password
end
end