-
Notifications
You must be signed in to change notification settings - Fork 194
E2604. Finish Password Resets #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnmweisz
wants to merge
81
commits into
expertiza:main
Choose a base branch
from
johnmweisz:development
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
17db68a
add: passwords_controller, user.rb
174bd98
add: setup mailer functionality
53c71b0
update: routes.rb to accomodate password_resets
34c89bd
Updated backend to work with frontend
galav12 e10708a
update: fixed mailer not sending email issue by adding smtp user and …
4fc00e2
fix: mailer adjusted to expertiza mailer
27fa103
add: spec test for passwords_controller and user model
07438d8
update: README.md with testing information
7e5eb99
Merge remote-tracking branch 'upstream/main' into E2604-password-reset
johnmweisz 6a6bf06
fix routing and namespace
johnmweisz 830f01c
use modern token method
johnmweisz 00dcb47
add passwordless fallback
johnmweisz 3b7354e
Merge pull request #2 from johnmweisz/E2604-password-reset
JaredM2028 7df5da1
make baseurl configurable, align email and template
johnmweisz 24cff9c
The unit tests weren't working, so made updates to get them working
josev814 d1ad85a
added a test for token expiration
josev814 4eb405d
Merge pull request #17 from johnmweisz/7-update-reset-email-make-conf…
johnmweisz 122a4d3
Merge branch 'development' into jvargas6/functioning_unit_tests
johnmweisz 40d31fc
Merge pull request #18 from johnmweisz/jvargas6/functioning_unit_tests
johnmweisz 5fa7eb8
remove mailer credentials
johnmweisz 6d8e72c
needed to add time_helpers to th rails_helper
josev814 51206f0
remove mailer credentials, fix subject typo
johnmweisz 8f4af85
wrap mailer in conditional
johnmweisz 527b058
remove misleading config
johnmweisz 383af48
Merge pull request #20 from johnmweisz/jweisz/remove-mailer-credentials
JaredM2028 43c6d8f
Merge pull request #19 from johnmweisz/jvargas6/travel_to_issue
josev814 0e088af
Cleaning up user tests and adding mailer tests
josev814 ca472dd
removing extra code from testing
josev814 eb28d32
Merge pull request #21 from johnmweisz/jvargas6/fixing_user_password_…
josev814 e2ce30a
Merge branch 'main' into development
johnmweisz c61e8fc
Minimally cleaned up dead code.
JaredM2028 91b1d26
Merge pull request #23 from johnmweisz/dead_code_cleanup
JaredM2028 db84640
add mailer config
johnmweisz e0eca05
fix syntax
johnmweisz 9c90171
fix configs
johnmweisz a7d4010
refactor
johnmweisz aecc20b
making pr updates to namings of user_mailer methods
josev814 7f656f9
Merge pull request #30 from johnmweisz/jvargas6/user_mailer_review_ad…
josev814 af5d4c3
Merge branch 'development' into jweisz/move-config
johnmweisz b567023
updating user_mailer_spec to prevent accessing private send method
josev814 39a4a36
Address PR review comments: rename env example, fix deliveries, spaci…
Copilot 1d31888
add comments/refine config
johnmweisz 272f91d
more comments
johnmweisz b13ca39
cleanup
johnmweisz 679b550
Update sample.env
johnmweisz 9eb1fe8
treating blank as unset
johnmweisz b955c01
treating blank as unset 2
johnmweisz 25e77d6
Add :admin alias trait in users factory for backward compatibility
Copilot 8c111ae
update spec refs to admin
johnmweisz f425627
Merge pull request #33 from johnmweisz/jvargas6/user_mailer_spec_revi…
josev814 27a7e1f
Merge pull request #31 from johnmweisz/jweisz/move-config
johnmweisz 6f25406
Addressed R1 feedback.
JaredM2028 6be1a99
Normalize email getter and controller lookup.
JaredM2028 2cf2187
Split lookup logic and render invalid response.
JaredM2028 fc8d5ad
Normalize all emails.
JaredM2028 016b69a
Refactored for DRY purposes.
JaredM2028 c31e71b
Preserve nil if passed in by user.
JaredM2028 823abb0
Updated tests.
JaredM2028 dd8d876
Centralize email normalization across User model and email-based look…
JaredM2028 3c56639
Condensed email normalization.
JaredM2028 b5cfca5
Test coverage for email normalization.
JaredM2028 3b3ab31
Explicitly splitting token lookup for users. All tests still pass and…
JaredM2028 84eb3c5
Tests updated to be more robust for token searching. Tests to come.
JaredM2028 745c8fb
Added email normalization to user model and reverted lookups. Tests t…
JaredM2028 fe274e0
Removed empty lines.
JaredM2028 5f6d5ca
Merge pull request #34 from johnmweisz/refine_pw_reset_TESTS
johnmweisz fd09ef1
Merge remote-tracking branch 'origin/development' into refine_pw_cont…
johnmweisz db37764
Merge pull request #32 from johnmweisz/refine_pw_controller
johnmweisz eb382f5
Making FRONTEND_URL use environment settings as requested
josev814 1501654
Merge branch 'development' into jvargas6/frontend_url_to_envconfig
josev814 70240bf
cleaning up the readme.md file a little
josev814 0900776
Apply suggestions from code review
josev814 9a25afb
adding to the rspec user_mailer test
josev814 3639eef
adding additional test for the mailer
josev814 e8661f9
Apply suggestions from code review
josev814 ec413e5
Apply suggestions from code review
josev814 792d9ce
using uti generic to build the frontend url
josev814 6950bc8
with uri generation we should not include :// in the scheme
josev814 595c39a
Merge pull request #35 from johnmweisz/jvargas6/frontend_url_to_envco…
josev814 f064482
readme update was messed up
josev814 6ad90d7
Merge pull request #36 from johnmweisz/jvargas6/readme_fix
josev814 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| class PasswordResetsController < ApplicationController | ||
| before_action :find_user_by_email, only: [:create] | ||
| before_action :load_user_by_token, only: [:update] | ||
| before_action :require_valid_token!, only: [:update] | ||
| skip_before_action :authenticate_request!, only: [:create, :update] | ||
|
|
||
| # POST /password_resets | ||
| def create | ||
| if @user | ||
| token = @user.generate_token_for(:password_reset) | ||
| UserMailer.password_reset_email(@user, token).deliver_later | ||
| end | ||
|
|
||
| # Always return a 200 OK to prevent email enumeration attacks | ||
| render json: { message: I18n.t('password_reset.email_sent') }, status: :ok | ||
| end | ||
|
|
||
| # PATCH/PUT /password_resets/:token | ||
| def update | ||
| if @user.update(password_params) | ||
| render json: { message: I18n.t('password_reset.updated') }, status: :ok | ||
| else | ||
| render json: { errors: @user.errors.full_messages }, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def find_user_by_email | ||
| @user = User.find_by(email: params[:email]) | ||
| end | ||
|
|
||
| def load_user_by_token | ||
| @user = User.find_by_token_for(:password_reset, params[:token]) | ||
| end | ||
|
|
||
| def require_valid_token! | ||
| render_invalid_token_response unless @user | ||
| end | ||
|
|
||
| def render_invalid_token_response | ||
| render json: { error: I18n.t('password_reset.errors.token_expired') }, status: :unprocessable_entity | ||
| end | ||
|
|
||
| def password_params | ||
| params.require(:user).permit(:password, :password_confirmation) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class UserMailer < ApplicationMailer | ||
| default from: "expertizamailer@gmail.com" | ||
|
|
||
| def password_reset_email(user, token) | ||
| @user = user | ||
| @reset_url = password_reset_url(token) | ||
| mail(to: @user.email, subject: I18n.t('password_reset.email_subject')) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def password_reset_url(token) | ||
| "#{FRONTEND_URL}/password_edit/check_reset_url?token=#{token}" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <html> | ||
| <head> | ||
| <title>Expertiza password reset</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <p>Hi <%= @user.full_name %>,</p> | ||
| <p>Reset your password, and we'll get you on your way.</p> | ||
| <p>To change your password, click or paste the following link into your browser:</p> | ||
| <p><a href="<%= @reset_url %>"><%= @reset_url %></a></p> | ||
| <p>The link will expire in 15 minutes, so be sure to use it right away.</p> | ||
| </body> | ||
| </html> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # ── Frontend Configuration ── | ||
| # Scheme should be either 'http' or 'https' | ||
| # Defaults: 'http' in development/test, 'https' in production | ||
| FRONTEND_SCHEME= | ||
| # The domain of the front-end | ||
| # Defaults: 'localhost' in development/test, 'expertiza.ncsu.com' in production | ||
| # Should be explicitly set in non-development environments (e.g. staging, production) | ||
| # Examples: 'localhost' (dev/test), 'staging.expertiza.ncsu.edu' (staging), 'expertiza.ncsu.com' (production) | ||
| FRONTEND_DOMAIN= | ||
| # Optional: Port number for the frontend service | ||
| # Defaults: 3000 in development/test, omitted (standard port) in production | ||
| # Omit this (or leave blank) to use standard ports (80 for http, 443 for https) | ||
| # Examples: '3000' (dev/test), '8443' (custom HTTPS port) | ||
| FRONTEND_PORT= | ||
|
|
||
| # ── Mailer Configuration ── | ||
| # All values are optional in development; see config/application.rb for defaults. | ||
| # In production, set at minimum MAILER_SERVER, MAILER_USER, and MAILER_PASSWORD. | ||
|
|
||
| # MAILER_USER: the email address used to authenticate with the SMTP server (e.g. no-reply@example.com) | ||
| # When blank, authentication is skipped entirely. | ||
| MAILER_USER= | ||
| # MAILER_PASSWORD: the password or app-specific password for the MAILER_USER account | ||
| MAILER_PASSWORD= | ||
| # MAILER_SERVER: the hostname of your outgoing SMTP server (e.g. smtp.gmail.com) | ||
| # Defaults to "localhost" if unset. | ||
| MAILER_SERVER= | ||
| # MAILER_SERVER_PORT: the port used by the SMTP server (commonly 587 for STARTTLS, 25 for unencrypted) | ||
| # Defaults to 587 if unset. | ||
| MAILER_SERVER_PORT= | ||
| # MAILER_DOMAIN: the HELO/EHLO domain sent to the SMTP server (e.g. example.com) | ||
| # Defaults to "localhost" if unset. | ||
| MAILER_DOMAIN= | ||
| # MAILER_ENABLE_STARTTLS: set to "false" to disable STARTTLS (e.g. for local relays that don't support TLS) | ||
| # Defaults to "true" if unset. | ||
| MAILER_ENABLE_STARTTLS= |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.