mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-13 13:12:42 +00:00
Track when an account last logged into a community auth site
This information can be useful when trying to debug issues with the community auth and the wonders of distributed data... No actual django model is created because django still doesn't support multi-column primary keys. Thus no tool to use the data yet other than psql.
This commit is contained in:
@ -9,7 +9,7 @@ from django.utils.http import urlsafe_base64_encode
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django.contrib.auth import logout as django_logout
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.db import transaction, connection
|
||||
from django.db.models import Q
|
||||
|
||||
import base64
|
||||
@ -528,6 +528,14 @@ def communityauth(request, siteid):
|
||||
return HttpResponseRedirect('/account/auth/{0}/consent/?{1}'.format(siteid,
|
||||
urllib.parse.urlencode({'next': '/account/auth/{0}/{1}'.format(siteid, urldata)})))
|
||||
|
||||
# Record the login as the last login to this site. Django doesn't support tables with
|
||||
# multi-column PK, so we have to do this in a raw query.
|
||||
with connection.cursor() as curs:
|
||||
curs.execute("INSERT INTO account_communityauthlastlogin (user_id, site_id, lastlogin, logincount) VALUES (%(userid)s, %(siteid)s, CURRENT_TIMESTAMP, 1) ON CONFLICT (user_id, site_id) DO UPDATE SET lastlogin=CURRENT_TIMESTAMP, logincount=EXCLUDED.logincount+1", {
|
||||
'userid': request.user.id,
|
||||
'siteid': site.id,
|
||||
})
|
||||
|
||||
info = {
|
||||
'u': request.user.username.encode('utf-8'),
|
||||
'f': request.user.first_name.encode('utf-8'),
|
||||
|
Reference in New Issue
Block a user