class Account
Attributes
password[RW]
password_confirmation[RW]
Public Class Methods
authenticate(email, password)
click to toggle source
This method is for authentication purpose
# File lib/bolton_cms/models/account.rb, line 29 def self.authenticate(email, password) account = where(email: /#{Regexp.escape(email)}/i).first if email.present? account && account.has_password?(password) ? account : nil end
find_by_id(id)
click to toggle source
This method is used by AuthenticationHelper
# File lib/bolton_cms/models/account.rb, line 37 def self.find_by_id(id) find(id) rescue nil end
Public Instance Methods
has_password?(password)
click to toggle source
# File lib/bolton_cms/models/account.rb, line 41 def has_password?(password) ::BCrypt::Password.new(crypted_password) == password end
Private Instance Methods
encrypt_password()
click to toggle source
# File lib/bolton_cms/models/account.rb, line 47 def encrypt_password self.crypted_password = ::BCrypt::Password.create(self.password) end
password_required()
click to toggle source
# File lib/bolton_cms/models/account.rb, line 51 def password_required crypted_password.blank? || self.password.present? end