Redo auth flow with lit. Beef up the test a bit, accordingly.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4392 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										51
									
								
								core/auth.js
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								core/auth.js
									
									
									
									
									
								
							@@ -121,6 +121,7 @@ function handler(request, response) {
 | 
			
		||||
 | 
			
		||||
		let formData = form.decodeForm(request.query);
 | 
			
		||||
 | 
			
		||||
		print(request.method, utf8Decode(request.body), JSON.stringify(formData));
 | 
			
		||||
		if (request.method == "POST" || formData.submit) {
 | 
			
		||||
			sessionIsNew = true;
 | 
			
		||||
			formData = form.decodeForm(utf8Decode(request.body), formData);
 | 
			
		||||
@@ -178,46 +179,16 @@ function handler(request, response) {
 | 
			
		||||
		} else {
 | 
			
		||||
			File.readFile("core/auth.html").then(function(data) {
 | 
			
		||||
				let html = utf8Decode(data);
 | 
			
		||||
				let contents = "";
 | 
			
		||||
 | 
			
		||||
				if (entry) {
 | 
			
		||||
					if (sessionIsNew) {
 | 
			
		||||
						contents += '<div>Welcome back, ' + entry.name + '.</div>\n';
 | 
			
		||||
					} else {
 | 
			
		||||
						contents += '<div>You are already logged in, ' + entry.name + '.</div>\n';
 | 
			
		||||
					}
 | 
			
		||||
					contents += '<div><a href="/login/logout">Logout</a></div>\n';
 | 
			
		||||
				} else {
 | 
			
		||||
					contents += '<form method="POST">\n';
 | 
			
		||||
					if (loginError) {
 | 
			
		||||
						contents += "<p>" + loginError + "</p>\n";
 | 
			
		||||
					}
 | 
			
		||||
					contents += '<div id="auth_greeting"><b>Halt.  Who goes there?</b></div>\n'
 | 
			
		||||
					contents += '<div id="auth">\n';
 | 
			
		||||
					contents += '<div id="auth_login">\n'
 | 
			
		||||
					if (noAdministrator()) {
 | 
			
		||||
						contents += '<div class="notice">There is currently no administrator.  You will be made administrator.</div>\n';
 | 
			
		||||
					}
 | 
			
		||||
					contents += '<div><label for="name">Name:</label> <input type="text" id="name" name="name" value=""></div>\n';
 | 
			
		||||
					contents += '<div><label for="password">Password:</label> <input type="password" id="password" name="password" value=""></div>\n';
 | 
			
		||||
					contents += '<div id="confirmPassword" style="display: none"><label for="confirm">Confirm:</label> <input type="password" id="confirm" name="confirm" value=""></div>\n';
 | 
			
		||||
					contents += '<div><input type="checkbox" id="register" name="register" value="1" onchange="showHideConfirm()"> <label for="register">Register a new account</label></div>\n';
 | 
			
		||||
					contents += '<div><input id="loginButton" type="submit" name="submit" value="Login"></div>\n';
 | 
			
		||||
					contents += '</div>';
 | 
			
		||||
					contents += '<div class="auth_or"> - or - </div>';
 | 
			
		||||
					contents += '<div id="auth_guest">\n';
 | 
			
		||||
					contents += '<input id="guestButton" type="submit" name="submit" value="Proceeed as Guest">\n';
 | 
			
		||||
					contents += '</div>\n';
 | 
			
		||||
					contents += '</div>\n';
 | 
			
		||||
					contents += '<div style="text-align: center">\n';
 | 
			
		||||
					contents += '<h2>Code of Conduct</h2>\n';
 | 
			
		||||
					contents += `<div><textarea readonly rows=20 cols=80>${core.globalSettings.code_of_conduct}</textarea></div>\n`;
 | 
			
		||||
					contents += '</div>\n';
 | 
			
		||||
					contents += '</form>';
 | 
			
		||||
				}
 | 
			
		||||
				let text = html.replace("<!--SESSION-->", contents);
 | 
			
		||||
				response.writeHead(200, {"Content-Type": "text/html; charset=utf-8", "Set-Cookie": cookie, "Content-Length": text.length});
 | 
			
		||||
				response.end(text);
 | 
			
		||||
				let auth_data = {
 | 
			
		||||
					session_is_new: sessionIsNew,
 | 
			
		||||
					name: entry?.name,
 | 
			
		||||
					error: loginError,
 | 
			
		||||
					code_of_conduct: core.globalSettings.code_of_conduct,
 | 
			
		||||
					have_administrator: !noAdministrator(),
 | 
			
		||||
				};
 | 
			
		||||
				html = utf8Encode(html.replace('$AUTH_DATA', JSON.stringify(auth_data)));
 | 
			
		||||
				response.writeHead(200, {"Content-Type": "text/html; charset=utf-8", "Set-Cookie": cookie, "Content-Length": html.length});
 | 
			
		||||
				response.end(html);
 | 
			
		||||
			}).catch(function(error) {
 | 
			
		||||
				response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Connection": "close"});
 | 
			
		||||
				response.end("404 File not found");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user