diff --git a/.gitignore b/.gitignore index b1565d1..24dcd3c 100644 --- a/.gitignore +++ b/.gitignore @@ -151,7 +151,6 @@ typings/ ### VisualStudioCode template -.vscode/ .vscode/* !.vscode/settings.json !.vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e9f62bf --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Django", + "type": "debugpy", + "request": "launch", + "args": [ + "runserver" + ], + "django": true, + "autoStartBrowser": false, + "program": "${workspaceFolder}/manage.py" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e2590f2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.formatOnSave": true + } +} \ No newline at end of file diff --git a/teleband/users/api/views.py b/teleband/users/api/views.py index 988cdc0..f47be9f 100644 --- a/teleband/users/api/views.py +++ b/teleband/users/api/views.py @@ -6,6 +6,7 @@ from django.contrib.auth.models import Group from django.core.exceptions import ValidationError from django.core.validators import validate_email +from django.utils.timezone import now from rest_framework import permissions from rest_framework import status @@ -124,5 +125,19 @@ def delete(self, request, *args, **kwargs): except Token.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) + # with thanks to https://chatgpt.com/share/66ee4879-8d84-800f-b18c-7d63efbb2c43 + def post(self, request, *args, **kwargs): + # Call the original implementation to get the authenticated user and token + response = super().post(request, *args, **kwargs) + token = Token.objects.get(key=response.data["token"]) + user = token.user + + # Update last_login and save the user instance + user.last_login = now() + user.save() + + # Return the response with the token and any additional data + return response + obtain_delete_auth_token = ObtainDeleteAuthToken.as_view()