Module: Devise::Models::Approvable
- Defined in:
- lib/devise_approvable/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#active_for_authentication? ⇒ Boolean
override.
- #approve! ⇒ Object
-
#approved? ⇒ Boolean
Verifies whether a user is confirmed or not.
-
#inactive_message ⇒ Object
override.
-
#send_approval_instructions ⇒ Object
Send approval instructions by email.
- #skip_approval! ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/devise_approvable/model.rb', line 5 def self.included(base) puts "Devise::Models::Approvable module injected into #{self.class} class" base.class_eval do extend ClassMethods before_create :generate_approval_token, :if => :approval_required? after_create :send_approval_instructions, :unless => :approved? end end |
Instance Method Details
#active_for_authentication? ⇒ Boolean
override
17 18 19 |
# File 'lib/devise_approvable/model.rb', line 17 def active_for_authentication? super && approved? end |
#approve! ⇒ Object
31 32 33 34 35 |
# File 'lib/devise_approvable/model.rb', line 31 def approve! self.approved_at = Time.now.utc self.approval_token = nil save(:validate => false) end |
#approved? ⇒ Boolean
Verifies whether a user is confirmed or not
38 39 40 |
# File 'lib/devise_approvable/model.rb', line 38 def approved? !!self.approved_at end |
#inactive_message ⇒ Object
override
22 23 24 25 26 27 28 |
# File 'lib/devise_approvable/model.rb', line 22 def if !approved? :not_approved else super # Use whatever other message end end |
#send_approval_instructions ⇒ Object
Send approval instructions by email
48 49 50 51 52 53 54 55 |
# File 'lib/devise_approvable/model.rb', line 48 def send_approval_instructions unless @raw_approval_token generate_approval_token! end opts = { to: self.class.admin_email } send_devise_notification(:approval_instructions, @raw_approval_token, opts) end |
#skip_approval! ⇒ Object
42 43 44 45 |
# File 'lib/devise_approvable/model.rb', line 42 def skip_approval! self.approved_at = Time.now.utc @skip_approval = true end |