Function Session.opCast
Checks if the session is active.
bool opCast() @safe const;
This operator enables a Session
value to be used in conditionals
to check if they are actially valid/active.
Example
//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"]);
}
}
/// Returns the unique session id of this session.
@property string id() const @safe { return m_id;