Feature 1792 - users can choose to recieve password resets via SMS#3757
Conversation
…d controller route
…ered (so email should not be sent)
|
@compwron @harsohailB @7riumph rspec is failing because the db is missing a "user reminder times" table and the lib/tasks tests depend on it. Looking at the schema, it seems to me someone refactored the "users reminder times" to "user case contact types reminders". Any clue to what's going on here? |
|
I'll work on fixing the code climate issues. Please don't merge yet or until everything is green. :) |
| end | ||
|
|
||
| validation = valid_phone_number(phone_number) | ||
| if validation[0] |
There was a problem hiding this comment.
Can we do something like this instead so its more readable than indexing:
phone_number_is_valid, error_message = valid_phone_number(phone_number)
if phone_number_is_valid
error_message = "Phone number not found" if User.find_by(phone_number: phone_number)
end
if error_message
resource.errors.add(:phone_number, error_message)
end| end | ||
|
|
||
| # otherwise, send reset email and sms | ||
| @resource = email.blank? ? User.find_by(phone_number: phone_number) : User.find_by(email: email) |
There was a problem hiding this comment.
Seems like you are already querying User.find_by(phone_number: phone_number) and User.find_by(email: email) above in the file to add error if the queries doesn't find anything. Maybe put these in a variable so you only call them once and reuse them if the query does find something?
| phone_number = params[resource_name][:phone_number] | ||
| reset_token = nil | ||
|
|
||
| if email.blank? && phone_number.blank? |
There was a problem hiding this comment.
I think you should have 2 clear paths for email and sms based on what is filled out. Right now, its hard to follow the logic as we have a lot if statements that keep checking email.blank? and phone_number.blank?. Maybe:
if !email.blank? && valid_email
# run this code which only has to do with the email
end
if !phone_number.blank? && valid_phone_number
# run this code which only has to do with the sms
end|
TO DO STILL:
|
|
This is exciting! |
…remaining rspec faliures
fixed! I drop the db and recreated it. It seemed the schema I had was outdated with some missing tables. |
| @@ -0,0 +1,71 @@ | |||
| class Users::PasswordsController < Devise::PasswordsController | |||
| tag.meta(property: "og:#{type}", **options) | ||
| end | ||
|
|
||
| def resource_name |
There was a problem hiding this comment.
yes, for devise. The devise view calls some internal methods like resource and resource_name. So we need to map these to use them in our controllers and specs


What github issue is this PR for, if any?
Resolves #1792
What changed, and why?
CASA users can now send password resets via SMS in addition to email.
Users can have the flexible options of getting a reset link via:
To achieve this:
How is this tested? (please write tests!) 💖💪
and redirects if no form errors occur
Screenshots please :)
SMS received via my phone (short link was visible thanks to @7riumph 's branded domain)
Feelings gif (optional)
I really enjoyed this issue - it allowed me to dive deeper into the internals of Devise