astrofication completed, not working. grrrrr
This commit is contained in:
parent
6f63b4806a
commit
d98ec229cc
6 changed files with 1316 additions and 0 deletions
52
static/js/activate.js
Normal file
52
static/js/activate.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
$('#activate').click(function(ev) {
|
||||
var activate = $('#activate');
|
||||
activate.hide();
|
||||
ev.preventDefault();
|
||||
|
||||
var token = activate.attr('data-token');
|
||||
var salt = activate.attr('data-salt');
|
||||
var password1 = $('#password1').val();
|
||||
var password2 = $('#password2').val();
|
||||
|
||||
function progress(s) {
|
||||
$('#progress').text(s);
|
||||
}
|
||||
function fail(s) {
|
||||
progress(s);
|
||||
activate.show();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Validate form data */
|
||||
if (password1 != password2)
|
||||
return fail("Passwords must match");
|
||||
|
||||
/* Calculate salted password */
|
||||
progress("Salting password");
|
||||
var salted = hmac(salt, password1);
|
||||
|
||||
/* Request salt+challenge for hashing */
|
||||
progress("Requesting account activation...");
|
||||
$.ajax({ type: 'POST',
|
||||
data: {
|
||||
salted: salted
|
||||
},
|
||||
url: '/activate/' + token,
|
||||
success: function(response) {
|
||||
if (response && response.welcome) {
|
||||
progress("Welcome to Bitlove!");
|
||||
document.location = response.welcome;
|
||||
} else {
|
||||
fail((response && response.error) || "Cannot activate");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
fail("Error sending request");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function hmac(key, text) {
|
||||
var hmac = new jsSHA(text, 'ASCII');
|
||||
return hmac.getHMAC(key, 'HEX', 'SHA-1', 'HEX');
|
||||
}
|
4
static/js/jquery-1.7.1.min.js
vendored
Normal file
4
static/js/jquery-1.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1164
static/js/jsSHA.js
Normal file
1164
static/js/jsSHA.js
Normal file
File diff suppressed because it is too large
Load diff
62
static/js/login.js
Normal file
62
static/js/login.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
$('#login').click(function(ev) {
|
||||
$('#login').hide();
|
||||
$('.login input').prop('disabled', 'disabled');
|
||||
ev.preventDefault();
|
||||
|
||||
var username = $('#username').val();
|
||||
var password = $('#password').val();
|
||||
|
||||
function progress(s) {
|
||||
$('#progress').text(s);
|
||||
}
|
||||
function fail(s) {
|
||||
progress(s);
|
||||
$('.login input').prop('disabled', false);
|
||||
$('#login').show();
|
||||
}
|
||||
/* Request salt+challenge for hashing */
|
||||
progress("Obtaining challenge...");
|
||||
$.ajax({ type: 'POST',
|
||||
data: {
|
||||
username: username
|
||||
},
|
||||
url: '/login',
|
||||
success: function(challenge) {
|
||||
if (challenge && challenge.salt && challenge.token) {
|
||||
progress("HMAC 1");
|
||||
var salted = hmac(challenge.salt, password);
|
||||
progress("HMAC 2");
|
||||
var response = hmac(challenge.token, salted);
|
||||
progress("Sending response");
|
||||
$.ajax({ type: 'POST',
|
||||
data: {
|
||||
token: challenge.token,
|
||||
response: response
|
||||
},
|
||||
url: '/login',
|
||||
success: function(response) {
|
||||
if (response && response.welcome) {
|
||||
progress("Welcome to Bitlove!");
|
||||
document.location = response.welcome;
|
||||
} else {
|
||||
fail((response && response.error) || "Cannot authenticate");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
fail("Error sending response");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fail((challenge && challenge.error) || "Cannot login");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
fail("Error obtaining challenge");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function hmac(key, text) {
|
||||
var hmac = new jsSHA(text, 'ASCII');
|
||||
return hmac.getHMAC(key, 'HEX', 'SHA-1', 'HEX');
|
||||
}
|
18
static/js/signup.js
Normal file
18
static/js/signup.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
var username = $('#username');
|
||||
var hint = $('#usernamehint');
|
||||
function fixUsername() {
|
||||
var s = username.val().
|
||||
toLowerCase().
|
||||
replace(/[^0-9a-z\-_]/g, "");
|
||||
|
||||
if (s !== username.val())
|
||||
username.val(s);
|
||||
|
||||
if (s.length > 0)
|
||||
hint.text("http://bitlove.org/" + s);
|
||||
else
|
||||
hint.text("");
|
||||
}
|
||||
username.bind('change', fixUsername);
|
||||
username.bind('input', fixUsername);
|
||||
username.bind('keyup', fixUsername);
|
16
templates/activate.hamlet
Normal file
16
templates/activate.hamlet
Normal file
|
@ -0,0 +1,16 @@
|
|||
$newline always
|
||||
<noscript>You need to have Javascript enabled
|
||||
<form class="login">
|
||||
<h3>Activate your account
|
||||
<p>
|
||||
<label for="password1">Password:
|
||||
<input id="password1" type="password" required>
|
||||
<p>
|
||||
<label for="password2">Confirm your password:
|
||||
<input id="password2" type="password" required>
|
||||
<p id="progress">
|
||||
<input id="activate" type="submit" value="Activate" data-token="#{token}" data-salt="#{hexSalt}">
|
||||
|
||||
<script src="/static/js/jquery-1.7.1.min.js" type="text/javascript">
|
||||
<script src="/static/js/jsSHA.js" type="text/javascript">
|
||||
<script src="/static/js/activate.js" type="text/javascript">
|
Loading…
Reference in a new issue