|
|
@ -91,7 +91,7 @@ define([
|
|
|
|
return Object.keys(proxy).length === 0;
|
|
|
|
return Object.keys(proxy).length === 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Exports.loginOrRegister = function (uname, passwd, isRegister, cb) {
|
|
|
|
Exports.loginOrRegister = function (uname, passwd, isRegister, shouldImport, cb) {
|
|
|
|
if (typeof(cb) !== 'function') { return; }
|
|
|
|
if (typeof(cb) !== 'function') { return; }
|
|
|
|
|
|
|
|
|
|
|
|
// Usernames are all lowercase. No going back on this one
|
|
|
|
// Usernames are all lowercase. No going back on this one
|
|
|
@ -144,49 +144,54 @@ define([
|
|
|
|
return void cb('ALREADY_REGISTERED', res);
|
|
|
|
return void cb('ALREADY_REGISTERED', res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(function () { cb(void 0, res); });
|
|
|
|
if (isRegister) {
|
|
|
|
|
|
|
|
var proxy = rt.proxy;
|
|
|
|
|
|
|
|
proxy.edPublic = res.edPublic;
|
|
|
|
|
|
|
|
proxy.edPrivate = res.edPrivate;
|
|
|
|
|
|
|
|
proxy.curvePublic = res.curvePublic;
|
|
|
|
|
|
|
|
proxy.curvePrivate = res.curvePrivate;
|
|
|
|
|
|
|
|
proxy.login_name = uname;
|
|
|
|
|
|
|
|
proxy[Constants.displayNameKey] = uname;
|
|
|
|
|
|
|
|
sessionStorage.createReadme = 1;
|
|
|
|
|
|
|
|
Feedback.send('REGISTRATION', true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Feedback.send('LOGIN', true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldImport) {
|
|
|
|
|
|
|
|
sessionStorage.migrateAnonDrive = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Realtime.whenRealtimeSyncs(rt.realtime, function () {
|
|
|
|
|
|
|
|
LocalStore.login(res.userHash, res.userName, function () {
|
|
|
|
|
|
|
|
cb(void 0, res);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Exports.redirect = 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/';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Exports.loginOrRegisterUI = function (uname, passwd, isRegister, shouldImport, testing, test) {
|
|
|
|
Exports.loginOrRegisterUI = function (uname, passwd, isRegister, shouldImport, testing, test) {
|
|
|
|
var hashing = true;
|
|
|
|
var hashing = true;
|
|
|
|
|
|
|
|
|
|
|
|
var proceed = function (result) {
|
|
|
|
var proceed = function (result) {
|
|
|
|
var proxy = result.proxy;
|
|
|
|
hashing = false;
|
|
|
|
proxy.edPublic = result.edPublic;
|
|
|
|
if (test && typeof test === "function" && test()) { return; }
|
|
|
|
proxy.edPrivate = result.edPrivate;
|
|
|
|
|
|
|
|
proxy.curvePublic = result.curvePublic;
|
|
|
|
|
|
|
|
proxy.curvePrivate = result.curvePrivate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isRegister) {
|
|
|
|
|
|
|
|
Feedback.send('REGISTRATION', true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Feedback.send('LOGIN', true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Realtime.whenRealtimeSyncs(result.realtime, function () {
|
|
|
|
Realtime.whenRealtimeSyncs(result.realtime, function () {
|
|
|
|
try {
|
|
|
|
Exports.redirect();
|
|
|
|
LocalStore.login(result.userHash, result.userName, function () {
|
|
|
|
|
|
|
|
hashing = false;
|
|
|
|
|
|
|
|
if (test && typeof test === "function" && test()) { console.log('testing');
|
|
|
|
|
|
|
|
return; }
|
|
|
|
|
|
|
|
if (shouldImport) {
|
|
|
|
|
|
|
|
sessionStorage.migrateAnonDrive = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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/';
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) { console.error(e); }
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -200,7 +205,7 @@ define([
|
|
|
|
// We need a setTimeout(cb, 0) otherwise the loading screen is only displayed
|
|
|
|
// We need a setTimeout(cb, 0) otherwise the loading screen is only displayed
|
|
|
|
// after hashing the password
|
|
|
|
// after hashing the password
|
|
|
|
window.setTimeout(function () {
|
|
|
|
window.setTimeout(function () {
|
|
|
|
Exports.loginOrRegister(uname, passwd, isRegister, function (err, result) {
|
|
|
|
Exports.loginOrRegister(uname, passwd, isRegister, shouldImport, function (err, result) {
|
|
|
|
var proxy;
|
|
|
|
var proxy;
|
|
|
|
if (result) { proxy = result.proxy; }
|
|
|
|
if (result) { proxy = result.proxy; }
|
|
|
|
|
|
|
|
|
|
|
@ -261,10 +266,6 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
if (testing) { return void proceed(result); }
|
|
|
|
if (testing) { return void proceed(result); }
|
|
|
|
|
|
|
|
|
|
|
|
proxy.login_name = uname;
|
|
|
|
|
|
|
|
proxy[Constants.displayNameKey] = uname;
|
|
|
|
|
|
|
|
sessionStorage.createReadme = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proceed(result);
|
|
|
|
proceed(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|