How to use the safety.models.Session function in safety

To help you get started, we’ve selected a few safety examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ulule / django-safety / safety / admin.py View on Github external
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)
github ulule / django-safety / safety / models.py View on Github external
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
github ulule / django-safety / safety / models.py View on Github external
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)