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
{
@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");
}

View file

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