Repository navigation
feat: resend account activation email on request, login and OAuth sign-in #321
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
17 commits
Select commit
Hold shift + click to select a range
105d509
feat: resend account activation email endpoint
hhvrc 9e021d7
Merge develop into feature/resend-activation-email
hhvrc bce4c6d
Merge remote-tracking branch 'origin/develop' into feature/resend-act…
hhvrc a3b819b
refactor: return a plain 200 from the activation resend endpoint
hhvrc 89def06
Merge branch 'develop' into feature/resend-activation-email
hhvrc 2f951af
Merge branch 'develop' into feature/resend-activation-email
hhvrc 6b16e04
fix: require turnstile on the resend activation endpoint
hhvrc b07a228
Merge remote-tracking branch 'origin/develop' into feature/resend-act…
hhvrc 5e1310e
feat: resend activation email on login, rate limit resends
hhvrc a6ee16c
fix: serialize activation resends per user, make login resend best-ef…
hhvrc bddabc6
fix: hide account-dependent failures from the public activation resend
hhvrc 6430200
feat: completing a password reset activates the account
hhvrc de288d8
feat: identify activation resend by a signup cookie instead of an email
hhvrc 3cc552a
fix: make the activation resend cookie readable by the frontend
hhvrc cfbba98
fix: neutral wording for activation resend errors
hhvrc 7e51c75
Merge remote-tracking branch 'origin/develop' into feature/resend-act…
hhvrc ba2ae50
refactor: use a switch expression for the activation resend result
hhvrc 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,56 @@ | ||
| using System.Diagnostics; | ||
| using System.Net.Mime; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.RateLimiting; | ||
| using OpenShock.API.Services.Account; | ||
| using OpenShock.Common.Authentication; | ||
| using OpenShock.Common.Errors; | ||
| using OpenShock.Common.Problems; | ||
| using OpenShock.Internal.Common.Problems; | ||
| using Results = OpenShock.Common.Results; | ||
|
|
||
| namespace OpenShock.API.Controller.Account; | ||
|
|
||
| public sealed partial class AccountController | ||
| { | ||
| /// <summary> | ||
| /// Resend the account activation email for the account this browser just signed up | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Identifies the account by the activation-resend cookie set on signup, not by an email address, | ||
| /// so it can only target an account created from this browser and can't be used to probe registered emails. | ||
| /// </remarks> | ||
| /// <response code="200">Activation email enqueued</response> | ||
| /// <response code="400">No pending activation for this browser (missing/expired cookie, or already activated)</response> | ||
| /// <response code="429">An activation email was sent too recently</response> | ||
| [HttpPost("activate/resend")] | ||
| [EnableRateLimiting("auth")] | ||
| [MapToApiVersion("1")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType<OpenShockProblem>(StatusCodes.Status400BadRequest, MediaTypeNames.Application.ProblemJson)] // AccountActivationResendUnavailable | ||
| [ProducesResponseType<OpenShockProblem>(StatusCodes.Status429TooManyRequests, MediaTypeNames.Application.ProblemJson)] // AccountActivationResendTooMany | ||
| public async Task<IActionResult> ResendActivation(CancellationToken cancellationToken) | ||
| { | ||
| if (!ActivationResendCookie.TryGetUserId(HttpContext, out var userId)) | ||
| { | ||
| // Tampered or expired (a no-op when there is no cookie), so the frontend stops offering the button. | ||
| ActivationResendCookie.Remove(HttpContext); | ||
| return Problem(AccountError.AccountActivationResendUnavailable); | ||
| } | ||
|
|
||
| var result = await _accountService.ResendActivationEmailAsync(userId.Value, cancellationToken); | ||
|
|
||
| // Already activated, deactivated, or gone: the cookie has nothing left to do. | ||
| if (result is AccountDeactivated or Results.NotFound) | ||
| ActivationResendCookie.Remove(HttpContext); | ||
|
|
||
| return result switch | ||
| { | ||
| Results.Success => Ok(), | ||
| TooManyActivationResends => Problem(AccountError.AccountActivationResendTooMany), | ||
| AccountDeactivated or Results.NotFound => Problem(AccountError.AccountActivationResendUnavailable), | ||
| _ => throw new UnreachableException() | ||
| }; | ||
| } | ||
| } |
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.
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.