[mw-devel] MW3 r1227 - in trunk/webclient: . templates

dez at sucs.org dez at sucs.org
Wed Oct 20 01:01:34 BST 2010


Author: dez
Date: 2010-10-20 01:01:33 +0100 (Wed, 20 Oct 2010)
New Revision: 1227

Added:
   trunk/webclient/person.png
   trunk/webclient/templates/createaccount.html
Modified:
   trunk/webclient/index.php
   trunk/webclient/mw.css
   trunk/webclient/say.js
   trunk/webclient/send.php
   trunk/webclient/startup.php
   trunk/webclient/templates/front.html
   trunk/webclient/templates/main.html
Log:
Adds who list support
Adds sucssite authentication and user creation
Probably some other things that I failed to commit before too...


Modified: trunk/webclient/index.php
===================================================================
--- trunk/webclient/index.php	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/index.php	2010-10-20 00:01:33 UTC (rev 1227)
@@ -18,14 +18,18 @@
 	setcookie("mwsess", "");
 	unset($mwsess);
 }
-if ($action == "login") {
+if ($action == "login" || $action == "create") {
 require("startup.php");
 }
 
 if (!isset($mwsess)) {
-	$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
-	$smarty->display("main.html");
-	exit;
+	if (@$_REQUEST['sucssite_loggedin']=="true") {
+		require("startup.php");
+	} else {
+		$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
+		$smarty->display("main.html");
+		exit;
+	}
 }
 
 $session = unserialize($mwsess);

Modified: trunk/webclient/mw.css
===================================================================
--- trunk/webclient/mw.css	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/mw.css	2010-10-20 00:01:33 UTC (rev 1227)
@@ -1,3 +1,38 @@
+.whoinfo {
+	padding: 5px;
+	background: #fff;
+	border: 1px solid black;
+	width: 200px;
+	position: relative;
+	top: -1.4em;
+	left: -217px;
+	z-index: 1000;
+	display: none;
+	color: black;
+}
+
+
+.whoinfo img {
+	float: right;
+	margin-left: 0.5em;
+}
+
+.whoinfo br {
+	clear: right;
+}
+
+.who a {
+	display: block;
+	width: 100%;
+	height: 100%;
+	color: inherit;
+	text-decoration: none;
+	background: inherit;
+}
+
+.who a:hover .whoinfo {
+	display: block;
+}
 textarea {
 	margin: 0;
 }
@@ -5,13 +40,6 @@
 	margin: 0;
 }
 
-#milliways {
-	width: 100%;
-	height: 90%;
-	min-width: 40em;
-	min-height: 20em;
-}
-
 #textouter, #sayit, #textlist table, #wholist, #milliways {
 	font-family: Monaco, "Lucida Sans Typewriter", "Lucida Console", monospace;
 	font-size: 9pt;
@@ -19,30 +47,31 @@
 
 #whoouter {
 	float: right;
-	background-color: #000000;
+	right: 10px;
+padding-top: 2px;
 	color: #d6d6d6;
-	width: 11em;
-	height: 100%;
-	overflow: auto;
 }
 
 #wholist {
-	width: 100%;
+	background-color: #000000;
+	width: 10em;
 	list-style: none;
 	margin: 0;
 	padding: 0;
 	padding-top: 5px;
 	padding-bottom: 5px;
-
+/* overflow: auto; */
 }
 
 #wholist li {
 	padding-left: 5px;
 	padding-right: 5px;
+	height: 1.3em;
 }
 
 #textouter, #sayit {
 	float: left;
+	width: 80%;
 	overflow: auto;
 	white-space: pre-wrap;
 }
@@ -61,15 +90,15 @@
 }
 
 #textouter {
-	height: 100%;
-	width: 100%;
+	height: 30em;
 }
 
 #sayit {
 	height: 4em;
-	width: 100%;
 	padding: 5px;
+	margin-top: 5px;
 	border: 1px solid black;
+	clear: left;
 }
 
 form {

Added: trunk/webclient/person.png
===================================================================
(Binary files differ)


Property changes on: trunk/webclient/person.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/webclient/say.js
===================================================================
--- trunk/webclient/say.js	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/say.js	2010-10-20 00:01:33 UTC (rev 1227)
@@ -4,6 +4,8 @@
 function pageInit() {
 	sendCmdHandle('who', drawWhoList);
 	sendCmdHandle('whoami', userProfile);
+	var sayit = document.getElementById("sayit");
+	sayit.focus();
 }
 
 	function addmsg(type, msg) {
@@ -217,8 +219,21 @@
 	return 0;
 }
 
-function drawWhoList(data, stat)
-{
+// For debugging purposes
+function concatObject(obj) {
+  str='';
+  for(prop in obj)
+  {
+    str+=prop + " => "+ obj[prop]+"\n";
+  }
+  return(str);
+}
+
+function userInit(data, stat) {
+
+}
+
+function drawWhoList(data, stat) {
 	var idleness;
 	userIndex=new Object;
 	$("li").remove();
@@ -230,9 +245,20 @@
 		var thisUsername=data[person].username.toLowerCase();
 		if (thisUsername in userIndex) usercount--;
 		userIndex[thisUsername]=usercount;
-		$("#wholist").append("<li class=\"who user_"+usercount+idleness+"\">"+data[person].username+"</li>");
+		var personinfo = "<div class=\"whoinfo\">";
+		if (data[person].hgwidth>0) personinfo += "<img src=\"https://sucs.org/pictures/people/"+data[person].username.toLowerCase()+".png\" width=\""+data[person].hgwidth+"\" height=\"64\" />";
+		else personinfo += "<img src=\"person.png\" width=\"64\" height=\"64\" />";
+		personinfo += "<strong>"+data[person].username+"</strong>";
+		personinfo += " "+data[person].doing;
+		personinfo += "<br />";
+		if (data[person].realname!=undefined) personinfo += data[person].realname+"<br />";
+		personinfo += "Room "+data[person].channel;
+		personinfo += "</div>";
+		$("#wholist").append("<li class=\"who user_"+usercount+idleness+"\"><a href=\"#\">"+data[person].username+personinfo+"</a></li>");
 		usercount++;
 	}
+	$("#debug").empty();
+	$("#debug").append(concatObject(userIndex));
 }
 
 function userProfile(data, stat) {

Modified: trunk/webclient/send.php
===================================================================
--- trunk/webclient/send.php	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/send.php	2010-10-20 00:01:33 UTC (rev 1227)
@@ -58,6 +58,21 @@
 	exit;
 }
 
+if ($_REQUEST['send']=="who") {
+	$who = json_decode($response, TRUE);
+	$pcount=0;
+	foreach ($who as $person) {
+		$im_file = "/var/www/sucssite/htdocs/pictures/people/".strtolower($person['username']).".png";
+		if (file_exists($im_file)) {
+			$size = getimagesize($im_file);
+			$factor = 64/$size[1];
+			$who[$pcount]['hgwidth']=(int)($size[0]*$factor);
+		}
+		$pcount++;
+	}
+	$response = json_encode($who);
+}
+
 echo $response."\n";
 
 fwrite($log, "Response '$response'\n");

Modified: trunk/webclient/startup.php
===================================================================
--- trunk/webclient/startup.php	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/startup.php	2010-10-20 00:01:33 UTC (rev 1227)
@@ -1,20 +1,52 @@
 <?
-
+$mwpoll = "~arthur/public_html/mw/mwpoll";
+$realuser = "Dez3"; // sucssite username - temporary bodge until we integrate with the site
 $username = trim($_REQUEST['username']);
 $password = trim($_REQUEST['password']);
 
-if (empty($username) || empty($password)) {
-	$smarty->assign("error", "username and password must both be not empty");
-	$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
-	$smarty->display("main.html");
-	exit;
+if (@$_REQUEST['sucssite_loggedin']!="true") {
+	if (empty($username) || empty($password)) {
+		$smarty->assign("error", "username and password must both be not empty");
+		$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
+		$smarty->display("main.html");
+		exit;
+	}
+
+	if (ctype_alnum($username) === FALSE) {
+		$smarty->assign("error", "alphanumeric usernames only");
+		$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
+		$smarty->display("main.html");
+		exit;
+	}
 }
 
-if (ctype_alnum($username) === FALSE) {
-	$smarty->assign("error", "alphanumeric usernames only");
-	$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
-	$smarty->display("main.html");
-	exit;
+if ($action=="create") {
+	$pass1 = @$_REQUEST['password1'];
+	$pass2 = @$_REQUEST['password2'];
+	if ($pass1 != $pass2) {
+		$smarty->assign("error", "Passwords don't match - please try again");
+		$smarty->assign_by_ref("body", $smarty->fetch("createaccount.html"));
+		$smarty->display("main.html");
+		exit;	
+	}
+	if (empty($pass1)) {
+		$smarty->assign("error", "Password cannot be blank");
+		$smarty->assign_by_ref("body", $smarty->fetch("createaccount.html"));
+		$smarty->display("main.html");
+		exit;	
+	}
+	if (ctype_alnum($pass1) === FALSE) {
+		$smarty->assign("error", "Milliways passwords can only contain alphanumeric characters");
+		$smarty->assign_by_ref("body", $smarty->fetch("createaccount.html"));
+		$smarty->display("main.html");
+		exit;	
+	}
+	if (strlen($pass1) < 6) {
+		$smarty->assign("error", "Milliways passwords must be 6 characters or more");
+		$smarty->assign_by_ref("body", $smarty->fetch("createaccount.html"));
+		$smarty->display("main.html");
+		exit;	
+	}
 }
 
 $desc = array( 
@@ -22,8 +54,17 @@
 	1 => array("pipe", "w"),
 );
 $pipes = array();
-$p = proc_open("~tswsl1989/mwpoll -u $username", $desc, $pipes);
 
+if (@$_REQUEST['sucssite_loggedin']=="true" && empty($username)) {
+	if ($action == "create") {
+		$p = proc_open($mwpoll." -a -u ".$realuser." -s", $desc, $pipes);	
+	} else {
+		$p = proc_open($mwpoll." -u ".$realuser." -s", $desc, $pipes);
+	}
+} else {
+	$p = proc_open($mwpoll." -u $username", $desc, $pipes);
+}
+
 if ($p === FALSE) {
 	$smarty->assign("error", "failed to exec mwpoll");
 	$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
@@ -31,10 +72,26 @@
 	exit;
 }
 
-fwrite($pipes[0], $password."\n");
+if (@$_REQUEST['sucssite_loggedin']=="true" && empty($username)) {
+// If we have a sucssite session cookie, use that
+	fwrite($pipes[0], trim($_REQUEST['sucssite_session'])."\n");
+	if ($action="create") {
+		fwrite($pipes[0], $pass1."\n");
+	}
+} else {
+// Try logging on using username and password
+	fwrite($pipes[0], $password."\n");
+}
 
 $pid = trim(fgets($pipes[1]));
 if (!is_numeric($pid)) {
+	if (substr($pid, -10) =="not found.") {
+	// User doesn't exist - ask for a Milliways password so we can create them!
+		$smarty->assign("error", $pid);
+		$smarty->assign_by_ref("body", $smarty->fetch("createaccount.html"));
+		$smarty->display("main.html");
+		exit;	
+	}
 	$smarty->assign("error", "Bad response: $pid");
 	$smarty->assign_by_ref("body", $smarty->fetch("login.html"));
 	$smarty->display("main.html");

Added: trunk/webclient/templates/createaccount.html
===================================================================
--- trunk/webclient/templates/createaccount.html	                        (rev 0)
+++ trunk/webclient/templates/createaccount.html	2010-10-20 00:01:33 UTC (rev 1227)
@@ -0,0 +1,24 @@
+<p>Please choose a password for Milliways</p>
+
+<form method=post action={$self}>
+<table>
+	<tr>
+		<td align="right">Password:</td>
+		<td>
+			<input type="password" name="password1" size="20">
+		</td>
+	</tr>
+	<tr>
+		<td align="right">Password again:</td>
+		<td>
+			<input type="password" name="password2" size="20">
+		</td>
+	</tr>
+	<tr>
+		<td colspan="2" align="center">
+			<input type="submit" name="submit" value="Create account">
+		</td>
+	</tr>
+</table>
+<input type="hidden" name="action" value="create">
+</form>

Modified: trunk/webclient/templates/front.html
===================================================================
--- trunk/webclient/templates/front.html	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/templates/front.html	2010-10-20 00:01:33 UTC (rev 1227)
@@ -1,29 +1,26 @@
 <h1>Milliways</h1>
 
-<table id="milliways" cellspacing="2" cellpadding="0" border="0">
-<tr><td>
-<div id="textouter"><div id="textlist"><p class="welcome">Milliways III - Web Edition</p></div></div>
-</td><td style="width: 11em; padding-left: 3px;">
 <div id="whoouter">
 <ul id="wholist">
 </ul>
 </div>
-</td></tr>
-<tr><td style="height: 4em;">
+
+<div id="textouter"><div id="textlist"><p class="welcome">Milliways III - Web Edition</p></div></div>
+
 <form action="" id="sayform">
 	<textarea name="sayit" id="sayit" onKeyDown="return submitenter(this,event)"></textarea>
 </form>
-</td><td>
+
+
 <form action="{$self}" method="post" id="logoutform">
 	<input type="hidden" name="action" value="logout">
 	<input type="button" name="escape" value="Escape" onclick="insertEscape(true);"><br />
 	<input type="submit" name="submit" value="Logout" onclick="sendCmd('quit');">
 </form>
-</td></tr>
-</table>
 
+<pre id="debug" style="clear: both;">
+</pre>
+
 <script language="javascript" type="text/javascript">
 pageInit();
-var sayit = document.getElementById("sayit");    
-sayit.focus();  
 </script>

Modified: trunk/webclient/templates/main.html
===================================================================
--- trunk/webclient/templates/main.html	2010-10-17 20:16:23 UTC (rev 1226)
+++ trunk/webclient/templates/main.html	2010-10-20 00:01:33 UTC (rev 1227)
@@ -1,6 +1,7 @@
 <html>
 <head>
 <title>MW Talker</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <script type="text/javascript" src="jquery.js"></script>
 <script type="text/javascript" src="say.js"></script>
 <link rel="stylesheet" type="text/css" media="all" href="mw.css" />




More information about the mw-devel mailing list