Simple API for connecting bots.
[redakcja.git] / src / redakcja / api / auth.py
diff --git a/src/redakcja/api/auth.py b/src/redakcja/api/auth.py
new file mode 100644 (file)
index 0000000..ccc5863
--- /dev/null
@@ -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)