From c0c16e7e25fb8d52f796d03a65153b8d5d2ea9b0 Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Thu, 30 Aug 2018 18:16:37 +0200 Subject: [PATCH] last login date in user api (#24411) --- src/authentic2/api_views.py | 5 ++++- src/authentic2/custom_user/models.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py index b6fa431a..57f933be 100644 --- a/src/authentic2/api_views.py +++ b/src/authentic2/api_views.py @@ -31,6 +31,7 @@ from .custom_user.models import User from . import utils, decorators, attribute_kinds, app_settings, hooks from .models import Attribute, PasswordReset, Service from .a2_rbac.utils import get_default_ou +from . import constants class HookMixin(object): @@ -300,7 +301,9 @@ password_change = PasswordChange.as_view() def user(request): if request.user.is_anonymous(): return {} - return request.user.to_json() + return request.user.to_json( + last_login=request.session.get(constants.LAST_LOGIN_SESSION_KEY) + ) def attributes_hash(attributes): diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py index ea3f4fba..1dbcf9f2 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -219,7 +219,7 @@ class User(AbstractBaseUser, PermissionMixin): def has_verified_attributes(self): return AttributeValue.objects.with_owner(self).filter(verified=True).exists() - def to_json(self): + def to_json(self, *args, **kwargs): d = {} for av in AttributeValue.objects.with_owner(self): d[str(av.attribute.name)] = av.to_python() @@ -236,6 +236,7 @@ class User(AbstractBaseUser, PermissionMixin): 'is_superuser': self.is_superuser, 'roles': [role.to_json() for role in self.roles_and_parents()], 'services': [service.to_json(roles=self.roles_and_parents()) for service in Service.objects.all()], + 'last_login': kwargs.get('last_login') }) return d -- 2.19.0.rc1