-
Notifications
You must be signed in to change notification settings - Fork 363
[ENG-9994][ENG-12168] Add API endpoint/view for resend confirmation URL #11913
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
bodintsov
wants to merge
3
commits into
CenterForOpenScience:feature/pbs-26-18
Choose a base branch
from
bodintsov:feature/ENG-9994
base: feature/pbs-26-18
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.
+68
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -935,6 +935,65 @@ def post(self, request, *args, **kwargs): | |
| content_type='application/vnd.api+json; application/json', | ||
| ) | ||
|
|
||
| class ResendConfirmation(JSONAPIBaseView, generics.ListCreateAPIView): | ||
| """ | ||
| View for handling resend confirmation URL requests. | ||
|
|
||
| GET: | ||
| - Takes an email as a query parameter. | ||
| - If the email is not provided or invalid, returns a validation error. | ||
| - If the user has recently requested a resend URL, returns a throttling error. | ||
| """ | ||
| permission_classes = ( | ||
| drf_permissions.AllowAny, | ||
| ) | ||
| view_category = 'users' | ||
| view_name = 'request-resend-confirmation' | ||
| throttle_classes = (NonCookieAuthThrottle, BurstRateThrottle, RootAnonThrottle, SendEmailThrottle) | ||
|
|
||
| def get(self, request, *args, **kwargs): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition, take a look at the legacy view, e.g.
|
||
| email = request.query_params.get('email', None) | ||
| if not email: | ||
| raise ValidationError('Request must include email in query params.') | ||
|
|
||
| status_message = language.RESEND_CONFIRMATION_SUCCESS_STATUS_MESSAGE.format(email=email) | ||
| # check if the user exists | ||
| user_obj = get_user(email=email) | ||
|
|
||
| if user_obj: | ||
| # rate limit resend_confirmation_post | ||
| if not throttle_period_expired(user_obj.email_last_sent, settings.SEND_EMAIL_THROTTLE): | ||
| return Response( | ||
| { | ||
| 'message': language.THROTTLE_RESEND_CONFIRMATION_ERROR_MESSAGE, | ||
| 'kind': 'error', | ||
| }, | ||
| status=status.HTTP_429_TOO_MANY_REQUESTS, | ||
| ) | ||
| else: | ||
| notification_type = NotificationTypeEnum.USER_INITIAL_CONFIRM_EMAIL | ||
| confirmation_url = user_obj.get_confirmation_url( | ||
| email, | ||
| external=True, | ||
| force=True, | ||
| renew=False, | ||
| ) | ||
| notification_type.instance.emit( | ||
| destination_address=email, | ||
| event_context={ | ||
| 'user_fullname': user_obj.fullname, | ||
| 'confirmation_url': f'{confirmation_url}', | ||
| }, | ||
| save=False, | ||
| ) | ||
|
|
||
| return Response( | ||
| status=status.HTTP_200_OK, | ||
| data={ | ||
| 'message': status_message, | ||
| 'kind': 'success', | ||
| }, | ||
| ) | ||
|
|
||
| class UserSettings(JSONAPIBaseView, generics.RetrieveUpdateAPIView, UserMixin): | ||
| permission_classes = ( | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a
POSTrequest?GETview is replaced by Angular FEPOSTview needs to be replaced by this PR