vibe.d beta banner
get vibe.d
0.7.30

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.

Prototype

bool opCast() const;

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

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

Copyright

© 2012-2013 RejectedSoftware e.K.

License

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