Module: RailsJwtAuth::Recoverable
- Defined in:
- app/models/concerns/rails_jwt_auth/recoverable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clean_reset_password ⇒ Object
- #expired_reset_password_token? ⇒ Boolean
- #send_reset_password_instructions ⇒ Object
- #set_reset_password(params) ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 3 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 end end |
Instance Method Details
#clean_reset_password ⇒ Object
58 59 60 61 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 58 def clean_reset_password self.reset_password_sent_at = nil self.reset_password_token = nil end |
#expired_reset_password_token? ⇒ Boolean
51 52 53 54 55 56 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 51 def expired_reset_password_token? expiration_time = RailsJwtAuth.reset_password_expiration_time return false if expiration_time.to_i.zero? reset_password_sent_at && reset_password_sent_at < expiration_time.ago end |
#send_reset_password_instructions ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 16 def send_reset_password_instructions email_field = RailsJwtAuth.email_field_name # ensure email field es valid if self.class.ancestors.include?(RailsJwtAuth::Confirmable) && !confirmed? errors.add(email_field, :unconfirmed) return false end if self.class.ancestors.include?(RailsJwtAuth::Lockable) && lock_strategy_enabled?(:failed_attempts) && access_locked? errors.add(email_field, :locked) return false end self.reset_password_token = generate_reset_password_token self.reset_password_sent_at = Time.current return false unless save RailsJwtAuth.send_email(:reset_password_instructions, self) end |
#set_reset_password(params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/concerns/rails_jwt_auth/recoverable.rb', line 37 def set_reset_password(params) self.assign_attributes(params) valid? errors.add(:password, :blank) if params[:password].blank? errors.add(:reset_password_token, :expired) if expired_reset_password_token? return false unless errors.empty? clean_reset_password self.auth_tokens = [] # reset all sessions save end |