0001-last-login-date-in-user-api-24411.patch
src/authentic2/api_views.py | ||
---|---|---|
31 | 31 |
from . import utils, decorators, attribute_kinds, app_settings, hooks |
32 | 32 |
from .models import Attribute, PasswordReset, Service |
33 | 33 |
from .a2_rbac.utils import get_default_ou |
34 |
from . import constants |
|
34 | 35 | |
35 | 36 | |
36 | 37 |
class HookMixin(object): |
... | ... | |
300 | 301 |
def user(request): |
301 | 302 |
if request.user.is_anonymous(): |
302 | 303 |
return {} |
303 |
return request.user.to_json() |
|
304 |
return request.user.to_json( |
|
305 |
last_login=request.session.get(constants.LAST_LOGIN_SESSION_KEY) |
|
306 |
) |
|
304 | 307 | |
305 | 308 | |
306 | 309 |
def attributes_hash(attributes): |
src/authentic2/custom_user/models.py | ||
---|---|---|
219 | 219 |
def has_verified_attributes(self): |
220 | 220 |
return AttributeValue.objects.with_owner(self).filter(verified=True).exists() |
221 | 221 | |
222 |
def to_json(self): |
|
222 |
def to_json(self, *args, **kwargs):
|
|
223 | 223 |
d = {} |
224 | 224 |
for av in AttributeValue.objects.with_owner(self): |
225 | 225 |
d[str(av.attribute.name)] = av.to_python() |
... | ... | |
236 | 236 |
'is_superuser': self.is_superuser, |
237 | 237 |
'roles': [role.to_json() for role in self.roles_and_parents()], |
238 | 238 |
'services': [service.to_json(roles=self.roles_and_parents()) for service in Service.objects.all()], |
239 |
'last_login': kwargs.get('last_login') |
|
239 | 240 |
}) |
240 | 241 |
return d |
241 | 242 | |
242 |
- |