handle more possible cases

pull/1/head
ansuz 8 years ago
parent 1682d23c1c
commit 86cda4357b

@ -124,9 +124,24 @@ define([
/* if the user is registering, we expect that the userDoc will be empty /* if the user is registering, we expect that the userDoc will be empty
*/ */
var proxykeys = Object.keys(proxy);
if (opt.register) { if (opt.register) {
if (Object.keys(proxy).length) { if (proxyKeys.length) {
// user is trying to register, but the userDoc is not empty
// tell them they are already registered.
alreadyExists(); alreadyExists();
} else {
// trying to register, and the object is empty, as expected
}
} else {
if (proxyKeys.length) {
} else {
} }
} }
@ -196,39 +211,41 @@ define([
$register[0].checked = false; $register[0].checked = false;
}; };
if (Cryptpad.getUserHash()) { Cryptpad.ready(function () {
//Cryptpad.alert("You are already logged in!"); if (Cryptpad.getUserHash()) {
$logoutBox.slideDown(); //Cryptpad.alert("You are already logged in!");
} else { $logoutBox.slideDown();
revealLogin(); } else {
} revealLogin();
$login.click(function () {
var uname = $username.val();
var passwd = $password.val();
var confirm = $confirm.val();
var remember = $remember[0].checked;
var register = $register[0].checked;
if (!Cred.isValidUsername(uname)) {
return void Cryptpad.alert('invalid username');
}
if (!Cred.isValidPassword(passwd)) {
return void Cryptpad.alert('invalid password');
}
if (register && !Cred.passwordsMatch(passwd, confirm)) {
return mismatchedPasswords();
} }
resetUI(); $login.click(function () {
var uname = $username.val();
var passwd = $password.val();
var confirm = $confirm.val();
var remember = $remember[0].checked;
var register = $register[0].checked;
if (!Cred.isValidUsername(uname)) {
return void Cryptpad.alert('invalid username');
}
if (!Cred.isValidPassword(passwd)) {
return void Cryptpad.alert('invalid password');
}
if (register && !Cred.passwordsMatch(passwd, confirm)) {
return mismatchedPasswords();
}
resetUI();
// consume 128 bytes, to be divided later // consume 128 bytes, to be divided later
// we can safely increase this size, but we don't need much right now // we can safely increase this size, but we don't need much right now
hashFromCreds(uname, passwd, 128, function (bytes) { hashFromCreds(uname, passwd, 128, function (bytes) {
useBytes(bytes, { useBytes(bytes, {
remember: remember, remember: remember,
register: register, register: register,
name: uname, name: uname,
});
}); });
}); });
}); });

Loading…
Cancel
Save