$(document).ready(function() {
	
	$('#signin').submit(function(e) {
		e.preventDefault();
		
		var email = $('#signin').find('input[name="email"]').val();
		var password = $('#signin').find('input[name="password"]').val();
		var remember = $('#signin').find('input[name="rememberMe"]').attr('checked') ? true: false;
		
		$.ajax({
			type: "post",
			url: "/login",
			data: { "username": email, "password": password, "rememberMe": remember },
			dataType: "text",
			success: function(data) {
				window.location.replace("/dashboard");
			},
			error: function(jqXHR, textStatus, errorThrown) {
				window.location.replace("/dashboard");
			}
		});
	});
	
	$('#signup').submit(function(e) {
		e.preventDefault();
		
		var emailField = $('#signup').find('input[name="email"]');
		var email = emailField.val();
		
		var signUpBtn = $('#signup').find('input[type="submit"]');
		setButtonState(signUpBtn, false);
		
		$.ajax({
			type: "post",
			url: "/register",
			data: JSON.stringify({ "email": email }),
			dataType: "text",
			contentType: "application/json",
			success: function(data) {
				emailField.val("");
				showAlert("alert-success", "An e-mail has been sent to <strong>" + email 
						+ "</strong>.<br/>This e-mail contains futher instructions on how to complete your registration.");
				setButtonState(signUpBtn, true);
			},
			error: function(jqXHR, textStatus, errorThrown) {
				showAlert("alert-info", jqXHR.responseText);
				setButtonState(signUpBtn, true);
			}
		});
	});
	
	function setButtonState(button, valid) {
		if (valid) {
			button.removeAttr("disabled");
		}
		else {
			button.attr("disabled", "disabled");
		}
	}
	
	function showAlert(type, message) {
		var alerts = $('.alerts');
		var alert = "<div class=\"alert " + type + "\"><a class=\"close\" data-dismiss=\"alert\" href=\"#\">&times;</a>" + message + "</div>";
		alerts.empty().append(alert);
	}
	
});
@@ -597,46 +597,196 @@
 %09%09%09%09
-window.location.replace(%22/dashboard%22);
+if (jqXHR.status === 405) %7B%0A%09%09%09%09%09window.alert(%22Wrong username or password%22);%0A%09%09%09%09%09$('#signin').find('input%5Bname=%22password%22%5D').val(%22%22);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09window.alert(%22Uknown error%22);%0A%09%09%09%09%7D
 %0A%09%09%09

give a reasonable answer