How to use the safety.models.PasswordChange 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 / example / urls.py View on Github external
def update_password(request):
    if request.user.is_authenticated():
        pr, created = PasswordChange.objects.get_or_create_for_user(request.user)
        pr.required = True
        pr.save()
    return redirect(reverse('home'))
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 / decorators.py View on Github external
def inner(request, *args, **kwargs):
        if not request.user.is_authenticated():
            return func(request, *args, **kwargs)

        required = PasswordChange.objects.is_required_for_user(request.user)
        url = reverse('safety:password_change')
        is_excluded_url = request.path.startswith(url)

        if required and not is_excluded_url:
            return redirect(url)

        return func(request, *args, **kwargs)
    return inner