-
Notifications
You must be signed in to change notification settings - Fork 0
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
Account deletion must be confirmed #95
base: main
Are you sure you want to change the base?
Conversation
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.
I added a few comments, please take a look.
Also, the tests are still missing. Since you're working against API endpoints, I'm fine with tests directly talking to the API, but UI-based tests (or both) would be even better.
|
||
send_mail( | ||
'Confirm Your Account Deletion', | ||
f'Click the link to confirm deletion: {confirm_url}', |
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.
Please add a note to the email how long the token is valid.
user = User.objects.filter(email=email).first() | ||
|
||
if user: | ||
if user.deleted: |
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.
Is this the case when a user is deleted and then logs in again?
path("request_delete/", views.request_delete, name="request_delete"), | ||
path("confirm-delete/<str:token>/", views.confirm_account_deletion, name="confirm_delete"), | ||
path("finalize-delete/", views.finalize_account_deletion, name="finalize_delete"), |
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.
Please stick to one style of URLs - I suggest to stick with hyphens only.
cache.set(f"delete_token_{token}", user.id, timeout=3600) | ||
|
||
confirm_url = request.build_absolute_uri(reverse('optimap:confirm_delete', args=[token])) | ||
|
||
send_mail( |
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.
Suggest to define the pre-string only in one location and then import that string here, and elsewhere. If you search the code for "delete_token", you'll find multiple spots.
Also, we might have other tokens in the future, so user_delete_token
would be more explicit.
def confirm_account_deletion(request, token): | ||
user_id = cache.get(f"delete_token_{token}") | ||
|
||
if user_id is None: |
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.
What about checking that the currently logged in user actually is the to be deleted user?
user.deleted = True | ||
user.deleted_at = now() | ||
user.save() |
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.
Can you put these lines in a try catch block?
If something goes wrong during the save, the cache.delete(..
and the removal of the token from the session might not be properly called.
Closes #25