Class: Masks::Rails::Email
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Masks::Rails::Email
- Defined in:
- app/models/masks/rails/email.rb
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #notified? ⇒ Boolean
- #notify!(session) ⇒ Object
- #taken? ⇒ Boolean
- #to_param ⇒ Object
- #verify! ⇒ Object
Instance Method Details
#expired? ⇒ Boolean
55 56 57 58 59 60 |
# File 'app/models/masks/rails/email.rb', line 55 def expired? return false unless notified? notified_at <= (Masks.configuration.lifetimes[:verification_email] || 1.hour).ago end |
#notified? ⇒ Boolean
51 52 53 |
# File 'app/models/masks/rails/email.rb', line 51 def notified? notified_at.present? end |
#notify!(session) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/masks/rails/email.rb', line 19 def notify!(session) return if verified? if expired? && !verified? self.notified_at = nil self.token = nil generate_token end return if notified? self.notified_at = Time.current return unless valid? save ActorMailer.with(session:, email: self).verify_email.deliver_now end |
#taken? ⇒ Boolean
62 63 64 |
# File 'app/models/masks/rails/email.rb', line 62 def taken? self.class.where(email:, verified: true).any? end |
#to_param ⇒ Object
47 48 49 |
# File 'app/models/masks/rails/email.rb', line 47 def to_param token end |
#verify! ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/masks/rails/email.rb', line 39 def verify! return if verified? self.verified_at = Time.current self.verified = true save! end |