Manual login works again, too

This commit is contained in:
Rick Falkvinge
2014-11-06 01:11:22 +01:00
parent b8130f5993
commit e608bf6928
2 changed files with 98 additions and 7 deletions
+62 -4
View File
@@ -8,6 +8,7 @@
<!-- jQuery and plugins -->
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.json.min.js"></script>
<!-- fonts -->
<link href='https://fonts.googleapis.com/css?family=Permanent+Marker' rel='stylesheet' type='text/css' />
@@ -40,13 +41,70 @@
recheckLogin();
}, 1000);
$('.InputManualCredentials').on('input', function () {
onInputCredentials();
});
$('#TextLogin').focus();
}); // end of document.ready
var manualCredentialsTestTrigger;
function onInputCredentials() {
clearTimeout(manualCredentialsTestTrigger);
manualCredentialsTestTrigger = setTimeout(function () {
testManualCredentials();
}, 1000);
}
function testManualCredentials() {
// Submit credentials to server. If valid, they will validate through the recheckLogin call.
var jsonData = {};
jsonData.credentialsLogin = $('#TextLogin').val();
jsonData.credentialsPass = $('#TextPass').val();
jsonData.credentials2FA = $('#Text2FA').val();
jsonData.logonUriEncoded = bitIdUri;
$.ajax({
type: "POST",
url: "Login.aspx/TestCredentials",
data: $.toJSON(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d) {
alert('Logging in, please wait...');
} else {
// do nothing
}
},
error: function (msg) {
// retry after a second
alert(msg.responseText);
console.log(msg);
setTimeout(function () {
testManualCredentials();
}, 1000);
}
});
}
function recheckLogin() {
var jsonData = {};
jsonData.uriEncoded = bitIdUri;
jsonData.nonce = bitIdNonce;
$.ajax({
type: "POST",
url: "Login.aspx/TestLogin",
data: '{"uriEncoded": "' + bitIdUri + '","nonce": "' + bitIdNonce + '"}',
data: $.toJSON(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
@@ -113,9 +171,9 @@
<div class="box">
<div class="content" style="line-height:24px">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>User&nbsp;&nbsp;</td><td><input type="text" /></td></tr>
<tr><td>Pass&nbsp;&nbsp;</td><td><input type="text" /></td></tr>
<tr><td>2FA&nbsp;&nbsp;</td><td><input type="text" /></td></tr>
<tr><td>User&nbsp;&nbsp;</td><td align="right"><input id="TextLogin" class="InputManualCredentials" type="text" /></td></tr>
<tr><td>Pass&nbsp;&nbsp;</td><td align="right"><input id="TextPass" class="InputManualCredentials" type="password" /></td></tr>
<tr style="display:none"><td>2FA&nbsp;&nbsp;</td><td><input id="Text2FA" class="InputManualCredentials" type="password" /></td></tr>
</table>
</div>
</div>
+36 -3
View File
@@ -12,6 +12,7 @@ using System.Web.Services;
using System.Web.SessionState;
using System.Web.UI;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types;
using Swarmops.Database;
using Swarmops.Logic.Cache;
using Swarmops.Logic.Financial;
@@ -36,7 +37,7 @@ namespace Swarmops.Pages.Security
return;
}
Persistence.Key["Debug_RawData"] = Request.ToRaw();
// Persistence.Key["Debug_RawData"] = Request.ToRaw();
// Check for POST data - for BitId via Webform
@@ -65,7 +66,7 @@ namespace Swarmops.Pages.Security
BitIdCredentials credentials =
new JavaScriptSerializer().Deserialize<BitIdCredentials>(
new StreamReader(Request.InputStream).ReadToEnd());
// TODO: untested but seems to work. Throws?
// TODO: untested but seems to work. Throws?
ProcessRespondBitId(credentials, Response);
return;
@@ -193,7 +194,8 @@ namespace Swarmops.Pages.Security
response.StatusCode = 200;
response.SetJson();
response.Write("{\"address\":\"" + credentials.address + "\",\"signature\":\"" + credentials.signature + "\"}");
response.Write("{\"address\":\"" + credentials.address + "\",\"signature\":\"" + credentials.signature +
"\"}");
response.End();
}
else
@@ -238,6 +240,37 @@ namespace Swarmops.Pages.Security
}
}
[WebMethod]
// ReSharper disable once InconsistentNaming
public static bool TestCredentials(string credentialsLogin, string credentialsPass, string credentials2FA, string logonUriEncoded)
{
if (!string.IsNullOrEmpty(credentialsLogin.Trim()) && !string.IsNullOrEmpty(credentialsPass.Trim()))
{
string logonUri = HttpUtility.UrlDecode(logonUriEncoded);
try
{
Person authenticatedPerson = Swarmops.Logic.Security.Authentication.Authenticate(credentialsLogin,
credentialsPass);
// TODO: Determine last logged-on organization. Right now, log on to Sandbox.
GuidCache.Set(logonUri + "-LoggedOn",
authenticatedPerson.Identity.ToString(CultureInfo.InvariantCulture) + ",1,,AuthPlain");
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
}
return false;
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);