-
Notifications
You must be signed in to change notification settings - Fork 166
LG-6205: Add endpoint, button to trigger password reset (IdV app) #6360
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f920282
LG-6205: Add endpoint, button to trigger password reset (IdV app)
aduth f8cc201
Remove unnecessary demo code
aduth 06c1b79
Handle outline spinner button styles with wrapper class
aduth c458ec6
Define window navigation as component prop
aduth 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| class SpinnerButtonComponent < BaseComponent | ||
| attr_reader :action_message, :button_options | ||
| attr_reader :action_message, :button_options, :outline | ||
|
|
||
| # @param [String] action_message Message describing the action being performed, shown visually to | ||
| # users when the animation has been active for a long time, and | ||
| # immediately to users of assistive technology. | ||
| def initialize(action_message: nil, **button_options) | ||
| @action_message = action_message | ||
| @button_options = button_options | ||
| @outline = button_options[:outline] | ||
| end | ||
|
|
||
| def css_class | ||
| 'spinner-button--outline' if outline | ||
| 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,23 @@ | ||
| module Api | ||
| module Verify | ||
| class PasswordResetController < Api::BaseController | ||
| def create | ||
| analytics.idv_forgot_password_confirmed | ||
| request_id = sp_session[:request_id] | ||
| email = current_user.email | ||
| reset_password(email, request_id) | ||
|
|
||
| render json: { redirect_url: forgot_password_url(request_id: request_id) }, | ||
| status: :accepted | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def reset_password(email, request_id) | ||
| sign_out | ||
| RequestPasswordReset.new(email: email, request_id: request_id, analytics: analytics).perform | ||
| session[:email] = email | ||
| end | ||
| end | ||
| 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
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
27 changes: 27 additions & 0 deletions
27
app/javascript/packages/verify-flow/steps/password-confirm/password-reset-button.spec.tsx
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,27 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { useSandbox } from '@18f/identity-test-helpers'; | ||
| import PasswordResetButton, { API_ENDPOINT } from './password-reset-button'; | ||
|
|
||
| describe('PasswordResetButton', () => { | ||
| const sandbox = useSandbox(); | ||
|
|
||
| const REDIRECT_URL = '/password_reset'; | ||
|
|
||
| before(() => { | ||
| sandbox | ||
| .stub(window, 'fetch') | ||
| .withArgs(API_ENDPOINT) | ||
| .resolves({ | ||
| status: 202, | ||
| json: () => Promise.resolve({ redirect_url: REDIRECT_URL }), | ||
| } as Response); | ||
| }); | ||
|
|
||
| it('triggers password reset API call and redirects', (done) => { | ||
| const { getByRole } = render(<PasswordResetButton onNavigate={() => done()} />); | ||
|
|
||
| const button = getByRole('button'); | ||
| userEvent.click(button); | ||
| }); | ||
| }); |
48 changes: 48 additions & 0 deletions
48
app/javascript/packages/verify-flow/steps/password-confirm/password-reset-button.tsx
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 @@ | ||
| import { SpinnerButton } from '@18f/identity-spinner-button'; | ||
| import { t } from '@18f/identity-i18n'; | ||
| import { isErrorResponse, post } from '../../services/api'; | ||
| import type { ErrorResponse } from '../../services/api'; | ||
|
|
||
| /** | ||
| * API endpoint for password reset. | ||
| */ | ||
| export const API_ENDPOINT = '/api/verify/v2/password_reset'; | ||
|
|
||
| /** | ||
| * API response shape. | ||
| */ | ||
| interface PasswordResetSuccessResponse { | ||
| redirect_url: string; | ||
| } | ||
|
|
||
| /** | ||
| * API response shape. | ||
| */ | ||
| type PasswordResetResponse = PasswordResetSuccessResponse | ErrorResponse; | ||
|
|
||
| /** | ||
| * Navigates user to the given URL. | ||
| * | ||
| * @param url Destination URL. | ||
| */ | ||
| function navigate(url) { | ||
| window.location.href = url; | ||
| } | ||
|
|
||
| function PasswordResetButton({ onNavigate = navigate }) { | ||
| async function requestReset() { | ||
| const json = await post<PasswordResetResponse>(API_ENDPOINT, {}, { csrf: true, json: true }); | ||
| if (!isErrorResponse(json)) { | ||
| const { redirect_url: redirectURL } = json; | ||
| onNavigate(redirectURL); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <SpinnerButton isBig isOutline isWide onClick={requestReset}> | ||
| {t('idv.forgot_password.reset_password')} | ||
| </SpinnerButton> | ||
| ); | ||
| } | ||
|
|
||
| export default PasswordResetButton; |
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
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.