Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
yflory 8 years ago
commit 702798f65a

@ -101,20 +101,6 @@ define([
$('button.nologin').click(function (e) {
document.location.href = '/drive/';
});
$('button.knowmore').click(function (e) {
e.preventDefault();
$('html, body').animate({
scrollTop: $('#knowmore').offset().top
}, 500);
});
$('button.tryit').click(function (e) {
e.preventDefault();
$('html, body').animate({
scrollTop: $('#tryit').offset().top
}, 500);
});
var $passwd = $('#password');
$passwd.on('keyup', function (e) {

@ -68,17 +68,11 @@ define([
var userNameKey = common.userNameKey = 'User_name';
var fileHashKey = common.fileHashKey = 'FS_hash';
var login = common.login = function (hash, name, remember, cb) {
var login = common.login = function (hash, name, cb) {
if (!hash) { throw new Error('expected a user hash'); }
if (!name) { throw new Error('expected a user name'); }
if (!remember) {
sessionStorage.setItem(userHashKey, hash);
sessionStorage.setItem(userNameKey, name);
}
else {
localStorage.setItem(userHashKey, hash);
localStorage.setItem(userNameKey, name);
}
localStorage.setItem(userHashKey, hash);
localStorage.setItem(userNameKey, name);
if (cb) { cb(); }
};
@ -86,9 +80,10 @@ define([
// delete sessionStorage values that might have been left over
// from the main page's /user redirect
[
'login',
'login_user',
'login_pass',
'login_remember',
'login_rmb',
'register'
].forEach(function (k) {
delete sessionStorage[k];

@ -52,12 +52,12 @@
<div id="login-panel" class="panel">
<div id="warning" data-localization="login_warning"></div>
<input type="text" name="username" id="username" data-localization-placeholder="login_username" autofocus><br />
<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
type="text" name="username" id="username" data-localization-placeholder="login_username" autofocus><br />
<input type="password" name="password" id="password" data-localization-placeholder="login_password"><br />
<input type="password" class="register" name="confirm" id="confirm_register" data-localization-placeholder="login_confirm"><br />
<button id="login" data-localization="login_login"></button>
<div style="display: none;"><input type="checkbox" name="remember" id="remember" checked="true"><label for="remember" data-localization="login_remember"></label></div>
</div>
<div id="notice-panel" class="panel">
@ -89,7 +89,7 @@
<p><span data-localization="username_label"></span>
<strong id="user-name" class="display"></strong></p>
<p>View your <a href="/drive" target="_blank">CryptDrive</a>.</p>
<p>View your <a href="/drive/" target="_blank">CryptDrive</a>.</p>
</div>
</div>

@ -18,8 +18,6 @@ define([
Crypto: Crypto,
};
var $warning = $('#warning');
// login elements
var $loginBox = $('#login-panel');
var $login = $('#login');
@ -27,7 +25,6 @@ define([
var $username = $('#username');
var $password = $('#password');
var $password_register = $('#confirm_register');
var $remember = $('#remember');
// hashing elements
var $noticeBox = $('#notice-panel');
@ -37,6 +34,10 @@ define([
$notice.text(s);
};
APP.redirectToDrive = function () {
document.location.href = '/drive/';
};
// confirm elements
var $confirmBox = $('#confirm-panel');
var $confirm = $('#confirm');
@ -63,13 +64,7 @@ define([
var revealConfirm = APP.revealConfirm = revealer($confirmBox);
var revealLogout = APP.revealLogout= revealer($logoutBox);
var revealUser_false = APP.revealUser_false = revealer($userBox);
var revealUser = APP.revealUser = function (state) {
if (!state) {
revealUser_false(state);
}
document.location.href = '/drive';
};
var revealUser = APP.revealUser = revealer($userBox);
var getDisplayName = APP.getDisplayName = function (proxy) {
return proxy['cryptpad.username'];
@ -108,7 +103,7 @@ define([
revealLogin(true);
revealUser(false);
APP.abort();
$username.focus();
//$username.focus();
});
});
};
@ -131,10 +126,9 @@ define([
APP.setAccountName(getAccountName(proxy));
APP.setDisplayName(getDisplayName(proxy));
Cryptpad.login(opt.userHash, getAccountName(proxy), opt.remember);
Cryptpad.login(opt.userHash, getAccountName(proxy));
APP.revealLogin(false);
APP.revealUser(true);
APP.revealLogout(true);
APP.redirectToDrive();
};
var abortRegistration = function () {
@ -167,8 +161,8 @@ define([
});
};
addEnterListener($confirm, function () {
$register.click();
addEnterListener($password_register, function () {
$login.click();
});
addEnterListener($password, function () {
$login.click();
@ -271,11 +265,6 @@ define([
var useBytes = function (bytes, opt) {
opt = opt || {};
if (opt.remember) {
console.log("user would like to stay logged in");
} else {
console.log("user would like to be forgotten");
}
var dispense = Cred.dispenser(bytes);
@ -326,33 +315,30 @@ define([
console.log(info);
});
};
Cryptpad.ready(function () {
if (Cryptpad.getUserHash()) {
var showUserInfo = function () {
/* TODO use something like this for a user preferences page
revealLogout(true);
var proxy = Cryptpad.getStore().getProxy().proxy;
APP.setAccountName(proxy.login_name);
APP.setDisplayName(getDisplayName(proxy));
return;
revealUser(true);
} else {
if (sessionStorage.register || document.location.hash.slice(1) === 'register') {
document.location.hash = 'register';
$login.text(Cryptpad.Messages.login_register);
$('#login-panel .register').show();
}
revealLogin(true);
}
*/
};
$username.focus();
Cryptpad.ready(function () {
// If the user is already logged in...
// TODO show user preferences
if (Cryptpad.getUserHash()) { return APP.redirectToDrive(); }
$login.click(function () {
var uname = $username.val().trim();
var passwd = $password.val();
var passwd_confirm = $password_register.val();
var confirm = $confirm.val();
var remember = $remember[0].checked;
remember = true; // TODO : find a way to use a sessionStorage shared with all tabs
var register = document.location.hash.slice(1) === 'register';
@ -370,39 +356,50 @@ define([
revealNotice(true);
revealLogin(false, function () {
window.setTimeout(function () {
resetUI();
// dispense 128 bytes, to be divided later
// we can safely increase this size, but we don't need much right now
Cred.deriveFromPassphrase(uname, passwd, 128, function (bytes) {
revealNotice(false);
window.setTimeout(function () {
useBytes(bytes, {
remember: remember,
register: register,
name: uname,
password: passwd,
});
}, 75);
});
}, 75);
window.setTimeout(function () {
resetUI();
// dispense 128 bytes, to be divided later
// we can safely increase this size, but we don't need much right now
Cred.deriveFromPassphrase(uname, passwd, 128, function (bytes) {
revealNotice(false);
window.setTimeout(function () {
useBytes(bytes, {
register: register,
name: uname,
password: passwd,
});
}, 75);
});
}, 75);
});
});
if (sessionStorage.login) {
$username.val(sessionStorage.login_user);
$password.val(sessionStorage.login_pass);
$remember.attr('checked', sessionStorage.login_rmb === "true");
$login.click();
// if the user is not logged in...
if (sessionStorage.register || document.location.hash.slice(1) === 'register') {
Cryptpad.replaceHash('register');
$login.text(Cryptpad.Messages.login_register);
$('#login-panel .register').show();
}
if (sessionStorage.register) {
$username.focus();
if (sessionStorage.login || sessionStorage.register) {
$username.val(sessionStorage.login_user);
$password.val(sessionStorage.login_pass);
$remember.attr('checked', sessionStorage.login_rmb === "true");
}
['login', 'register', 'login_user', 'login_pass', 'login_rmb'].forEach(function (k) {
delete sessionStorage[k];
});
if (sessionStorage.login) {
APP.setNotice(Cryptpad.Messages.login_hashing);
APP.revealNotice(true, function () {
$login.click();
Cryptpad.eraseTempSessionValues();
});
return;
}
revealLogin(true, function () {
if (sessionStorage.register) { $password_register.focus(); }
Cryptpad.eraseTempSessionValues();
});
});
});

Loading…
Cancel
Save