From 48796e6961b0f61366e3ff77f2b78a371153768e Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Thu, 17 Dec 2020 21:46:56 +0100 Subject: [PATCH] fixes #149 --- src-ui/src/app/interceptors/csrf.interceptor.ts | 7 +++++-- src/documents/templates/index.html | 1 + src/documents/views.py | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/interceptors/csrf.interceptor.ts b/src-ui/src/app/interceptors/csrf.interceptor.ts index 32f3e99dc..2ef03dc56 100644 --- a/src-ui/src/app/interceptors/csrf.interceptor.ts +++ b/src-ui/src/app/interceptors/csrf.interceptor.ts @@ -7,16 +7,19 @@ import { } from '@angular/common/http'; import { Observable } from 'rxjs'; import { CookieService } from 'ngx-cookie-service'; +import { Meta } from '@angular/platform-browser'; @Injectable() export class CsrfInterceptor implements HttpInterceptor { - constructor(private cookieService: CookieService) { + constructor(private cookieService: CookieService, private meta: Meta) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { - let csrfToken = this.cookieService.get('csrftoken') + + let prefix = this.meta.getTag('name=cookie_prefix').content + let csrfToken = this.cookieService.get(`${prefix?prefix:''}csrftoken`) if (csrfToken) { request = request.clone({ setHeaders: { diff --git a/src/documents/templates/index.html b/src/documents/templates/index.html index 728f3a0e7..06dbb678e 100644 --- a/src/documents/templates/index.html +++ b/src/documents/templates/index.html @@ -8,6 +8,7 @@ PaperlessUi + diff --git a/src/documents/views.py b/src/documents/views.py index bf31c749b..f90e9f7bc 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -54,6 +54,11 @@ from .serialisers import ( class IndexView(TemplateView): template_name = "index.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['cookie_prefix'] = settings.COOKIE_PREFIX + return context + class CorrespondentViewSet(ModelViewSet): model = Correspondent