Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class PasswordChangeAdmin(admin.ModelAdmin):
list_display = ('user', 'last_change_date', 'required')
raw_id_fields = ('user',)
class SessionAdmin(admin.ModelAdmin):
list_display = ('user', 'ip', 'last_activity', 'location', 'device', 'is_valid')
raw_id_fields = ('user',)
def is_valid(self, obj):
return obj.expiration_date > now()
is_valid.boolean = True
admin.site.register(PasswordChange, PasswordChangeAdmin)
admin.site.register(Session, SessionAdmin)
def deactivate_session(sender, request, user, **kwargs):
try:
key = request.session.session_key
instance = Session.objects.get(user=user, session_key=key)
instance.active = False
instance.save()
except Session.DoesNotExist:
pass
key = request.session.session_key
instance = Session.objects.get(user=user, session_key=key)
instance.active = False
instance.save()
except Session.DoesNotExist:
pass
# Connected to post_delete for Session model
def post_delete_session(sender, instance, **kwargs):
instance.delete_store_session()
user_logged_in.connect(create_session)
user_logged_out.connect(deactivate_session)
post_delete.connect(post_delete_session, sender=Session)