Module: Devise::Models::ChallengeQuestionable::ClassMethods

Defined in:
lib/devise_challenge_questionable/model.rb

Instance Method Summary collapse

Instance Method Details

#reset_challenge_questions_by_token(attributes = {}) ⇒ Object

Attempt to find a user by it’s reset_challenge_questions_token to reset it’s challenge_question. If a user is found, reset it’s challenge_question and automatically try saving the record. If not user is found, returns a new user containing an error in reset_challenge_questions_token attribute. Attributes must contain reset_challenge_questions_token, challenge_question and confirmation



98
99
100
101
102
# File 'lib/devise_challenge_questionable/model.rb', line 98

def reset_challenge_questions_by_token(attributes={})
  challenge_questionable = find_or_initialize_with_error_by(:reset_challenge_questions_token, attributes[:reset_challenge_questions_token])
  challenge_questionable.reset_challenge_questions!(attributes) if challenge_questionable.persisted?
  challenge_questionable
end

#reset_challenge_questions_tokenObject

Generate a token checking if one does not already exist in the database.



89
90
91
# File 'lib/devise_challenge_questionable/model.rb', line 89

def reset_challenge_questions_token
  generate_token(:reset_challenge_questions_token)
end

#send_reset_challenge_questions_instructions(attributes = {}) ⇒ Object

Attempt to find a user by it’s email. If a record is found, send new challenge_question instructions to it. If not user is found, returns a new user with an email not found error. Attributes must contain the user email



82
83
84
85
86
# File 'lib/devise_challenge_questionable/model.rb', line 82

def send_reset_challenge_questions_instructions(attributes={})
  challenge_questionable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
  challenge_questionable.send_reset_challenge_questions_instructions if challenge_questionable.persisted?
  challenge_questionable
end