Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'))
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 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