Sha256: bdd43640e47d1d5ad7b5eb5db5a6e1c776b7a0ff6bd20c92cc54dadc50233a7b
Contents?: true
Size: 1014 Bytes
Versions: 14
Compression:
Stored size: 1014 Bytes
Contents
class Account < ActiveRecord::Base ROLES = %w[admin guest] devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :timeoutable, :lockable, :validatable, :async before_validation :ensure_password, on: :create after_save :invalidate_cache validates :role, inclusion: {in: ROLES} def self.serialize_from_session(key, salt) # store the current_account in the cache so we do not perform a db lookup on each authenticated page single_key = key.is_a?(Array) ? key.first : key Rails.cache.fetch("account:#{single_key}") do Account.where(id: single_key).entries.first end end def self.generate_password(length = 10) Devise.friendly_token.first(length) end def is?(role_check) role.to_sym == role_check end private def ensure_password # only generate a password if it does not exist self.password ||= Account.generate_password end def invalidate_cache Rails.cache.delete("account:#{id}") end end
Version data entries
14 entries across 14 versions & 1 rubygems