Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ typings/


### VisualStudioCode template
.vscode/
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
15 changes: 15 additions & 0 deletions teleband/users/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()