Merge branch 'dev' into feature-more-like-this

This commit is contained in:
jonaswinkler 2020-12-18 00:02:30 +01:00
commit 43c88ae0f0
3 changed files with 13 additions and 2 deletions

View File

@ -7,16 +7,21 @@ 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<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
let csrfToken = this.cookieService.get('csrftoken')
let prefix = ""
if (this.meta.getTag('name=cookie_prefix')) {
prefix = this.meta.getTag('name=cookie_prefix').content
}
let csrfToken = this.cookieService.get(`${prefix?prefix:''}csrftoken`)
if (csrfToken) {
request = request.clone({
setHeaders: {

View File

@ -8,6 +8,7 @@
<title>PaperlessUi</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="cookie_prefix" content="{{cookie_prefix}}">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="{% static 'frontend/styles.css' %}"></head>
<body>

View File

@ -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