Session.opCast

Checks if the session is active.

This operator enables a Session value to be used in conditionals to check if they are actially valid/active.

struct Session
const @safe
bool
opCast
()

Examples

//import vibe.http.server;
// workaround for cyclic module ctor compiler error
class HTTPServerRequest { Session session; string[string] form; }
class HTTPServerResponse { Session startSession() { assert(false); } }

void login(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
	// TODO: validate username+password

	// ensure that there is an active session
	if (!req.session) req.session = res.startSession();

	// update session variables
	req.session.set("loginUser", req.form["user"]);
}

Meta