use a better way to redirect to login if not authenticated

This commit is contained in:
Johannes Loher 2017-08-10 02:57:31 +02:00
parent 8473bc1930
commit 3d59043261
2 changed files with 3 additions and 5 deletions

View file

@ -22,12 +22,12 @@ import vibe.web.web : errorDisplay, noRoute, redirect, render, SessionVar,
@requiresAuth class CalendarWebapp @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")) if (!req.session || !req.session.isKeySet("auth"))
{ {
redirect("/login"); () @trusted{ redirect("/login"); }();
throw new HTTPStatusException(HTTPStatus.forbidden, "Du musst dich erst einloggen"); return AuthInfo.init;
} }
return req.session.get!AuthInfo("auth"); return req.session.get!AuthInfo("auth");
} }

View file

@ -8,5 +8,3 @@ html
block navigation block navigation
include navigation include navigation
block content block content