The example from the site:
import vibe.d;
void login(HTTPServerRequest req, HTTPServerResponse res)
{
enforceHTTP("username" in req.form && "password" in req.form,
HTTPStatus.badRequest, "Missing username/password field.");
// todo: verify user/password here
auto session = res.startSession();
session["username"] = req.form["username"];
session["password"] = req.form["password"];
res.redirect("/home");
}
void logout(HTTPServerRequest req, HTTPServerResponse res)
{
res.terminateSession();
res.redirect("/");
}
void checkLogin(HTTPServerRequest req, HTTPServerResponse res)
{
// force a redirect to / for unauthenticated users
if( req.session is null )
res.redirect("/");
}
shared static this()
{
auto router = new URLRouter;
router.get("/", staticTemplate!"index.dl");
router.post("/login", &login);
router.post("/logout", &logout);
// restrict all following routes to authenticated users:
router.any("*", &checkLogin);
router.get("/home", staticTemplate!"home.dl");
auto settings = new HTTPServerSettings;
settings.sessionStore = new MemorySessionStore;
// ...
}
But lets say I didnt want to pass the ServerResponse throughout my program into every function. For example, what if the res.session was storing the id of the current user. This is used often, so I wouldnt want this passed through each function. How do I store this session info globally? Assuming there's multiple users using the site.