Module: RailsJwtAuth::Recoverable
- Defined in:
- app/models/concerns/rails_jwt_auth/recoverable.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 33 def self.included(base) base.class_eval do if defined?(Mongoid) && base.ancestors.include?(Mongoid::Document) # include GlobalID::Identification to use deliver_later method # http://edgeguides.rubyonrails.org/active_job_basics.html#globalid include GlobalID::Identification if RailsJwtAuth.deliver_later field :reset_password_token, type: String field :reset_password_sent_at, type: Time end validate :validate_reset_password_token, if: :password_digest_changed? before_update do if password_digest_changed? && reset_password_token self.reset_password_token = nil end end end end |
Instance Method Details
#send_reset_password_instructions ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 3 def send_reset_password_instructions if self.class.ancestors.include?(RailsJwtAuth::Confirmable) && !confirmed? errors.add(:email, I18n.t('rails_jwt_auth.errors.unconfirmed')) return false end self.reset_password_token = SecureRandom.base58(24) self.reset_password_sent_at = Time.now return false unless save mailer = Mailer.reset_password_instructions(self) RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver end |
#set_and_send_password_instructions ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 17 def set_and_send_password_instructions return if password.present? self.password = SecureRandom.base58(48) self.password_confirmation = self.password self.skip_confirmation! if self.class.ancestors.include?(RailsJwtAuth::Confirmable) self.reset_password_token = SecureRandom.base58(24) self.reset_password_sent_at = Time.now return false unless save mailer = Mailer.set_password_instructions(self) RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver true end |