Sha256: fa023c30dae5843ff29a31f1caeb1959365c0647adaa221eeababf7da5944679
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
# include MuckUsers::Models::MuckAccessCodeRequest module MuckUsers module Models module MuckAccessCodeRequest extend ActiveSupport::Concern included do validates_presence_of :email validates_uniqueness_of :email scope :unfullfilled, where('access_code_requests.code_sent_at IS NULL') scope :by_newest, order("created_at DESC") scope :by_oldest, order("created_at ASC") end module ClassMethods def get_requests(limit = nil) if limit && limit.to_i > 0 self.by_oldest.unfullfilled.all(:limit => limit) else self.by_oldest.unfullfilled end end def mark_fullfilled(access_code_requests) access_code_requests.each do |request| request.update_attribute(:code_sent_at, DateTime.now) end end end def send_access_code(subject, message) access_code = AccessCode.create!(:unlimited => false, :use_limit => 1, :uses => 0, :code => AccessCode.random_code) UserMailer.access_code(self.email, subject, message, access_code.code).deliver success = AccessCodeRequest.mark_fullfilled(self) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
muck-users-3.1.8 | lib/muck-users/models/access_code_request.rb |