X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/0dd00c51dfdbda93e1b9c4612477cd05109d4517..9ff5f2ac22360b1ff3ef2473c15d4acfd1e7769b:/src/redakcja/api/auth.py?ds=sidebyside diff --git a/src/redakcja/api/auth.py b/src/redakcja/api/auth.py new file mode 100644 index 00000000..ccc58639 --- /dev/null +++ b/src/redakcja/api/auth.py @@ -0,0 +1,13 @@ +from django.utils.timezone import now +from rest_framework.authentication import TokenAuthentication as BaseTokenAuthentication +from . import models + + +class TokenAuthentication(BaseTokenAuthentication): + model = models.Token + + def authenticate_credentials(self, key): + user, token = super().authenticate_credentials(key) + token.last_seen_at = now() + token.save(update_fields=['last_seen_at']) + return (user, token)