vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

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; 
Authors

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

Copyright

© 2012-2013 Sönke Ludwig

License

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