Module: Revise::Models::Invitable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/revise/models/invitable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- MAILERS =
['Invitable']
- HELPERS =
['Authentication']
- CONTROLLERS =
['Main', 'Sessions', 'Accounts', 'Invitations']
Instance Attribute Summary collapse
-
#completing_invite ⇒ Object
Returns the value of attribute completing_invite.
-
#skip_invitation ⇒ Object
Returns the value of attribute skip_invitation.
Class Method Summary collapse
Instance Method Summary collapse
-
#accept_invitation! ⇒ Object
Accept an invitation by clearing invitation token and and setting invitation_accepted_at Confirms it if model is confirmable.
-
#accepted_or_not_invited? ⇒ Boolean
Verifies whether a user has accepted an invitation (or is accepting it), or was never invited.
-
#invitation_accepted? ⇒ Boolean
Verifies whether a user accepted an invitation (or is accepting it).
- #invitation_fields ⇒ Object
-
#invite!(invited_by = nil) ⇒ Object
Reset invitation token and send invitation again.
- #invite_key_valid? ⇒ Boolean
-
#invited_to_sign_up? ⇒ Boolean
Verifies whether a user has been invited or not.
- #password_required? ⇒ Boolean
- #reset_password!(new_password, new_password_confirmation) ⇒ Object
-
#valid_invitation? ⇒ Boolean
Verify whether a invitation is active or not.
-
#valid_password?(password) ⇒ Boolean
Only verify password when is not invited.
Instance Attribute Details
#completing_invite ⇒ Object
Returns the value of attribute completing_invite.
11 12 13 |
# File 'lib/revise/models/invitable.rb', line 11 def completing_invite @completing_invite end |
#skip_invitation ⇒ Object
Returns the value of attribute skip_invitation.
10 11 12 |
# File 'lib/revise/models/invitable.rb', line 10 def skip_invitation @skip_invitation end |
Class Method Details
.required_fields(klass) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/revise/models/invitable.rb', line 31 def self.required_fields(klass) fields = [:invitation_token, :invitation_sent_at, :invitation_accepted_at, :invitation_limit, :invited_by_id, :invited_by_type] fields -= [:invited_by_type] if Revise.invited_by_class_name fields end |
Instance Method Details
#accept_invitation! ⇒ Object
Accept an invitation by clearing invitation token and and setting invitation_accepted_at Confirms it if model is confirmable
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/revise/models/invitable.rb', line 46 def accept_invitation! self.invitation_accepted_at = Time.now.utc if self.invited_to_sign_up? && self.valid? run_callbacks :invitation_accepted do self.invitation_token = nil self.confirmed_at = self.invitation_accepted_at if self.respond_to?(:confirmed_at) self.save(:validate => false) end end end |
#accepted_or_not_invited? ⇒ Boolean
Verifies whether a user has accepted an invitation (or is accepting it), or was never invited
68 69 70 |
# File 'lib/revise/models/invitable.rb', line 68 def accepted_or_not_invited? invitation_accepted? || !invited_to_sign_up? end |
#invitation_accepted? ⇒ Boolean
Verifies whether a user accepted an invitation (or is accepting it)
63 64 65 |
# File 'lib/revise/models/invitable.rb', line 63 def invitation_accepted? invitation_accepted_at end |
#invitation_fields ⇒ Object
38 39 40 41 42 |
# File 'lib/revise/models/invitable.rb', line 38 def invitation_fields fields = [:invitation_sent_at, :invited_by_id, :invited_by_type] fields -= [:invited_by_type] if Revise.invited_by_class_name fields end |
#invite!(invited_by = nil) ⇒ Object
Reset invitation token and send invitation again
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/revise/models/invitable.rb', line 73 def invite!(invited_by = nil) was_invited = invited_to_sign_up? # Required to workaround confirmable model's confirmation_required? method # being implemented to check for non-nil value of confirmed_at if self.new_record? && self.respond_to?(:confirmation_required?) def self.confirmation_required?; false; end end generate_invitation_token if self.invitation_token.nil? self.invitation_sent_at = Time.now.utc self.invited_by = invited_by if invited_by # Call these before_validate methods since we aren't validating on save self.downcase_keys if self.new_record? && self.respond_to?(:downcase_keys) self.strip_whitespace if self.new_record? && self.respond_to?(:strip_whitespace) if save(:validate => false) self.invited_by.decrement_invitation_limit! if !was_invited and self.invited_by.present? deliver_invitation unless @skip_invitation end end |
#invite_key_valid? ⇒ Boolean
113 114 115 116 117 118 |
# File 'lib/revise/models/invitable.rb', line 113 def invite_key_valid? return true unless self.class.invite_key.is_a? Hash # FIXME: remove this line when deprecation is removed self.class.invite_key.all? do |key, regexp| regexp.nil? || self.send(key).try(:match, regexp) end end |
#invited_to_sign_up? ⇒ Boolean
Verifies whether a user has been invited or not
58 59 60 |
# File 'lib/revise/models/invitable.rb', line 58 def invited_to_sign_up? invitation_token end |
#password_required? ⇒ Boolean
120 121 122 |
# File 'lib/revise/models/invitable.rb', line 120 def password_required? !@skip_password && (encrypted_password.blank? || password.present?) end |
#reset_password!(new_password, new_password_confirmation) ⇒ Object
108 109 110 111 |
# File 'lib/revise/models/invitable.rb', line 108 def reset_password!(new_password, new_password_confirmation) super accept_invitation! end |
#valid_invitation? ⇒ Boolean
Verify whether a invitation is active or not. If the user has been invited, we need to calculate if the invitation time has not expired for this user, in other words, if the invitation is still valid.
99 100 101 |
# File 'lib/revise/models/invitable.rb', line 99 def valid_invitation? invited_to_sign_up? && invitation_period_valid? end |
#valid_password?(password) ⇒ Boolean
Only verify password when is not invited
104 105 106 |
# File 'lib/revise/models/invitable.rb', line 104 def valid_password?(password) super unless invited_to_sign_up? end |