2014-01-10 16:35:58 +01:00
|
|
|
require 'digest/md5'
|
|
|
|
|
2013-11-14 10:54:09 +01:00
|
|
|
class User < ActiveRecord::Base
|
2014-01-10 16:35:58 +01:00
|
|
|
# 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-01-10 16:35:58 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
conditions = warden_conditions.dup
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def password_digest(password)
|
|
|
|
Digest::MD5.hexdigest password
|
|
|
|
end
|
2013-11-14 10:54:09 +01:00
|
|
|
end
|