Tuesday, March 08, 2011 at 12:00 AM.


on signin (urlRedirect) {
		<<3/6/11; 6:36:11 PM by DW
			<<Cookie-based signin. If it's a post, check adrpostresult. If true, the user validated, send him to the home page (probably). If false, display the returned HTML.
	local (pta = html.getpagetableaddress (), t, now = clock.now ());
	pta^.title = "Sign in";
	<<adrpostresult^ = false //not a post, or didn't validate
	bundle { //initial setup of t
		new (tabletype, @t);
		t.message = "";
		t.username = ""};
	<<scratchpad.signinparams = pta^; edit (@scratchpad.signinparams)
	if pta^.method == "POST" {
		local (args);
		new (tabletype, @args);
		webserver.parseargs (pta^.requestbody, @args);
		<<scratchpad.args = args; edit (@scratchpad.args)
		if opmlEditor.member.validate (args.username, args.password) {
			local (adrgroup = opmlEditor.member.initGroup ());
			local (cookievalue = "username=" + args.username + "&password=" + args.password);
			webserver.util.setCookie (pta, adrgroup^.cookiename, cookievalue, adrgroup^.cookiedomain, adrgroup^.cookieexpires);
			<<scratchpad.signinparams = pta^; edit (@scratchpad.signinparams)
			<<adrpostresult^ = true
			webserver.redirect (pta, urlRedirect);
			return ("")}
		else {
			t.username = args.username; //save the trouble of entering it again
			t.message = "Incorrect username or password."}};
	return (string.multiplereplaceall (string (opmlEditor.data.outlines.signInTemplate), @t, false, "<%", "%>"))}

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.