module RedTokenAuth::Password

Public Instance Methods

generate_reset_password_token() click to toggle source
# File lib/red_token_auth/password.rb, line 17
def generate_reset_password_token
  update(reset_password_token: random_token, reset_password_token_sent_at: Time.zone.now)
end
random_token() click to toggle source
# File lib/red_token_auth/password.rb, line 43
def random_token
  SecureRandom.hex(3)
end
reset_password(params = {}) click to toggle source
# File lib/red_token_auth/password.rb, line 32
def reset_password(params = {})
  if params[:reset_password_token] == reset_password_token
    update(password: params[:password], password_confirmation: params[:password_confirmation], reset_password_token_sent_at: nil)
  else
    #HACK: It would be nicer if this logic was inside a validation.
    #TODO: Add message yml.
    errors.add(:current_password, :wrong_reset_password_token)
    return false
  end
end
update_password(params = {}) click to toggle source
# File lib/red_token_auth/password.rb, line 21
def update_password(params = {})
  if authenticate(params[:current_password]) && !params[:current_password].blank?
    update(password: params[:password], password_confirmation: params[:password_confirmation])
  else
    #HACK: It would be nicer if this logic was inside a validation.
    #TODO: Add message yml.
    errors.add(:current_password, :wrong_password)
    return false
  end
end