From 3d5904326105961632bcc5940cf017c7a731499e Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 10 Aug 2017 02:57:31 +0200 Subject: [PATCH] use a better way to redirect to login if not authenticated --- source/calendarwebapp.d | 6 +++--- views/layout.dt | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/calendarwebapp.d b/source/calendarwebapp.d index 1c2b7d4..745e5d3 100644 --- a/source/calendarwebapp.d +++ b/source/calendarwebapp.d @@ -22,12 +22,12 @@ import vibe.web.web : errorDisplay, noRoute, redirect, render, SessionVar, @requiresAuth class CalendarWebapp { - @noRoute AuthInfo authenticate(scope HTTPServerRequest req, scope HTTPServerResponse res) @trusted + @noRoute AuthInfo authenticate(scope HTTPServerRequest req, scope HTTPServerResponse res) @safe { if (!req.session || !req.session.isKeySet("auth")) { - redirect("/login"); - throw new HTTPStatusException(HTTPStatus.forbidden, "Du musst dich erst einloggen"); + () @trusted{ redirect("/login"); }(); + return AuthInfo.init; } return req.session.get!AuthInfo("auth"); } diff --git a/views/layout.dt b/views/layout.dt index 5cabeff..b15f0ad 100644 --- a/views/layout.dt +++ b/views/layout.dt @@ -8,5 +8,3 @@ html block navigation include navigation block content - -