Sha256: 35b1d1aab25ee709fa0dfa288d065dbd98724040ec68a91bd6f7960d02852052
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
module Janus module Models # = Confirmable # # Confirms an account's email by sending an email with an unique token. # This is necessary to be sure the user can be contacted on that email. # # IMPROVE: reconfirm whenever email changes. module Confirmable extend ActiveSupport::Concern included do begin attr_protected :confirmation_token, :confirmation_sent_at, :confirmed_at rescue end janus_config(:confirmation_key) before_create :generate_confirmation_token # before_update :generate_confirmation_token, :if => :email_changed? end # Generates the confirmation token, but won't save the record. def generate_confirmation_token self.confirmation_token = self.class.generate_token(:confirmation_token) self.confirmation_sent_at = Time.now end # Confirms the record. def confirm! self.confirmation_token = self.confirmation_sent_at = nil self.confirmed_at = Time.now save end # Checks wether the email of this user if confirmed, or not. def confirmed? confirmed_at? end module ClassMethods def find_for_confirmation(token) where(:confirmation_token => token).first unless token.blank? end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
janus-0.7.0 | lib/janus/models/confirmable.rb |