Wednesday, April 06, 2011 at 12:01 AM.


on checkCookie (urlRedirect, adrusername, flredirect=true) {
		<<4/3/11; 4:25:32 PM by DW
			<<Call opmleditor.init. If the request is coming from the local machine, and we can't validate the user via cookies, the user is automatically "admin" -- if the pref is set true.
		<<3/7/11; 7:11:23 PM by DW
			<<Don't look for the specific cookie if there are no cookies at all.
		<<3/7/11; 8:36:59 AM by DW
			<<Return true if the user has the cookie and a valid username and password, else redirect to the indicated address.
				<<The cookie looks like this: "username%3Ddave%26password%3Dbloing"
			<<Added optional flredirect param. Our menu code wants to display an abbreviated menu if the user is not a member, so it doesn't want the redirect.
	local (pta = html.getpagetableaddress (), now = ());
	local (adrgroup = opmlEditor.member.initGroup ());
	opmlEditor.init ();
	if defined (pta^.requestHeaders.cookies) {
		local (adrcookie = @pta^.requestHeaders.cookies.[adrgroup^.cookiename]);
		if defined (adrcookie^) {
			local (args);
			new (tabletype, @args);
			webserver.parseargs (string.urldecode (adrcookie^), @args);
			if defined (args.username) and defined (args.password) {
				if opmlEditor.member.validate (args.username, args.password) {
					adrusername^ = args.username;
					return (true)}}}};
	bundle { //allow access for local user, as admin, 4/3/11 by DW
		if user.opmlEditor.prefs.flLocalMemberIsAdmin {
			if opmlEditor.isSameMachine (pta^.client) {
				local (username = "admin");
				local (adrmember = opmlEditor.member.initMember (username, flcreate:true));
				adrmember^.stats.whenLastLocalAccess = now;
				adrusername^ = username;
				return (true)}}};
	if flredirect {
		webserver.redirect (pta, urlRedirect)};
	return (false)};
bundle { //test code
	html.setpagetableaddress (@scratchpad.radio2params);
	checkcookie ("")}

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.