vibe.d beta banner
get vibe.d

Function 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.


bool opCast() const;


//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 { return m_id; 

Jan Krüger, Sönke Ludwig, Ilya Shipunov


© 2012-2013 RejectedSoftware e.K.


Subject to the terms of the MIT license, as written in the included LICENSE.txt file.