On Sunday, 25 March 2012 at 19:37:12 UTC, dnewbie wrote:
This is what I was looking for. Rock'n'roll!!
BTW I tried to keep Session simple, and there's some
doc comments, but the basic usage is as simple as:
// loads the session, or creates a new one if needed
auto session = new Session(cgi);
// it does NOT auto save, so you want to call
// session.commit() when you're done.
// scope(exit) makes that easy.
scope(exit) session.commit();
bool checkLogin() {
if(session.hasKey("user_id")) { // see if a key is set
// the user is logged in
string uid = session.user_id; // can get data via
opDispatch
return true;
}
return false;
}
void logout() {
session.invalidate(); // clears and deletes the session
}
void login() {
session.invalidate(); // kill the guest session
session.user_id = uid; // save the user id in the session via
opDispatch
}
If you use web.d's FancyMain, it creates a session for
you, so your ApiProvider class already has a session
member you can tap right into.
import web.d;
class MySite : ApiProvider {
void something () {
session.cool = "something"; // works
}
}
mixin FancyMain!MySite;