add support for logging in from register page

pull/1/head
ansuz 8 years ago
parent 11ff3f5347
commit 09afba80db

@ -94,17 +94,21 @@ define([
res.realtime = rt.realtime;
res.network = rt.network;
// they're registering...
res.userHash = opt.userHash;
res.userName = uname;
// they tried to just log in but there's no such user
if (!isRegister && isProxyEmpty(rt.proxy)) {
rt.network.disconnect(); // clean up after yourself
return void cb('NO_SUCH_USER', res);
}
// they're registering...
res.userHash = opt.userHash;
res.userName = uname;
//res.displayName // TODO
// they tried to register, but those exact credentials exist
if (isRegister && !isProxyEmpty(rt.proxy)) {
rt.network.disconnect();
return void cb('ALREADY_REGISTERED', res);
}
cb(void 0, res);
});

@ -61,6 +61,25 @@ define([
var $register = $('button#register');
var logMeIn = function (result) {
localStorage.User_hash = result.userHash;
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
if (sessionStorage.redirectTo) {
var h = sessionStorage.redirectTo;
var parser = document.createElement('a');
parser.href = h;
if (parser.origin === window.location.origin) {
delete sessionStorage.redirectTo;
window.location.href = h;
return;
}
}
window.location.href = '/drive/';
});
});
};
$register.click(function () {
var uname = $uname.val();
var passwd = $passwd.val();
@ -101,14 +120,27 @@ define([
Cryptpad.alert(Messages.login_invalPass);
});
break;
case 'ALREADY_REGISTERED':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.confirm(Messages.register_alreadyRegistered, function (yes) {
if (!yes) { return; }
result.proxy.login_name = uname;
if (!result.proxy[Cryptpad.displayNameKey]) {
result.proxy[Cryptpad.displayNameKey] = uname;
}
Cryptpad.eraseTempSessionValues();
logMeIn(result);
});
});
break;
default: // UNHANDLED ERROR
Cryptpad.errorLoadingScreen(Messages.login_unhandledError);
}
return;
}
var proxy = result.proxy;
localStorage.User_hash = result.userHash;
Cryptpad.eraseTempSessionValues();
if (shouldImport) {
sessionStorage.migrateAnonDrive = 1;
@ -118,21 +150,7 @@ define([
proxy[Cryptpad.displayNameKey] = uname;
sessionStorage.createReadme = 1;
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
if (sessionStorage.redirectTo) {
var h = sessionStorage.redirectTo;
var parser = document.createElement('a');
parser.href = h;
if (parser.origin === window.location.origin) {
delete sessionStorage.redirectTo;
window.location.href = h;
return;
}
}
window.location.href = '/drive/';
});
});
logMeIn(result);
});
}, {
ok: Messages.register_writtenPassword, //'I have written down my password, proceed',

Loading…
Cancel
Save