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

pull/1/head
ansuz 8 years ago
commit 8f5989b6b0

@ -388,6 +388,11 @@
right: 0; right: 0;
text-align: center; text-align: center;
} }
@media screen and (max-height: 600px) {
.cp #loadingTip {
display: none;
}
}
.cp #loadingTip span { .cp #loadingTip span {
background-color: #302B28; background-color: #302B28;
color: #fafafa; color: #fafafa;

@ -119,54 +119,57 @@ define([
}); });
$('button.login').click(function () { $('button.login').click(function () {
Cryptpad.addLoadingScreen(Messages.login_hashing); // setTimeout 100ms to remove the keyboard on mobile devices before the loading screen pops up
// We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password
window.setTimeout(function () { window.setTimeout(function () {
loginReady(function () { Cryptpad.addLoadingScreen(Messages.login_hashing);
var uname = $uname.val(); // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password
var passwd = $passwd.val(); window.setTimeout(function () {
Login.loginOrRegister(uname, passwd, false, function (err, result) { loginReady(function () {
if (!err) { var uname = $uname.val();
var proxy = result.proxy; var passwd = $passwd.val();
Login.loginOrRegister(uname, passwd, false, function (err, result) {
// successful validation and user already exists if (!err) {
// set user hash in localStorage and redirect to drive var proxy = result.proxy;
if (proxy && !proxy.login_name) {
proxy.login_name = result.userName; // successful validation and user already exists
} // set user hash in localStorage and redirect to drive
if (proxy && !proxy.login_name) {
proxy.edPrivate = result.edPrivate; proxy.login_name = result.userName;
proxy.edPublic = result.edPublic; }
Cryptpad.whenRealtimeSyncs(result.realtime, function () { proxy.edPrivate = result.edPrivate;
Cryptpad.login(result.userHash, result.userName, function () { proxy.edPublic = result.edPublic;
document.location.href = '/drive/';
}); Cryptpad.whenRealtimeSyncs(result.realtime, function () {
}); Cryptpad.login(result.userHash, result.userName, function () {
return; document.location.href = '/drive/';
} });
switch (err) {
case 'NO_SUCH_USER':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_noSuchUser);
});
break;
case 'INVAL_USER':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_invalUser);
}); });
break; return;
case 'INVAL_PASS': }
Cryptpad.removeLoadingScreen(function () { switch (err) {
Cryptpad.alert(Messages.login_invalPass); case 'NO_SUCH_USER':
}); Cryptpad.removeLoadingScreen(function () {
break; Cryptpad.alert(Messages.login_noSuchUser);
default: // UNHANDLED ERROR });
Cryptpad.errorLoadingScreen(Messages.login_unhandledError); break;
} case 'INVAL_USER':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_invalUser);
});
break;
case 'INVAL_PASS':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_invalPass);
});
break;
default: // UNHANDLED ERROR
Cryptpad.errorLoadingScreen(Messages.login_unhandledError);
}
});
}); });
}); }, 0);
}, 0); }, 100);
}); });
/* End Log in UI */ /* End Log in UI */

@ -36,6 +36,9 @@
left: 0; left: 0;
right: 0; right: 0;
text-align: center; text-align: center;
@media screen and (max-height: @media-medium-screen) {
display: none;
}
span { span {
background-color: @bg-loading; background-color: @bg-loading;
color: @color-loading; color: @color-loading;

@ -150,34 +150,17 @@ define([
} }
/* add a history button */ /* add a history button */
var histConfig = {}; var histConfig = {
histConfig.onRender = function (val) { onLocal: config.onLocal(),
if (typeof val === "undefined") { return; } onRemote: config.onRemote(),
try { setHistory: setHistory,
var hjson = JSON.parse(val || '{}'); applyVal: function (val) {
var remoteDoc = hjson.content; var remoteDoc = JSON.parse(val || '{}').content;
editor.setValue(remoteDoc || ''); editor.setValue(remoteDoc || '');
editor.save(); editor.save();
} catch (e) { },
// Probably a parse error $toolbar: $bar
console.error(e);
}
};
histConfig.onClose = function () {
// Close button clicked
setHistory(false, true);
};
histConfig.onRevert = function () {
// Revert button clicked
setHistory(false, false);
config.onLocal();
config.onRemote();
};
histConfig.onReady = function () {
// Called when the history is loaded and the UI displayed
setHistory(true);
}; };
histConfig.$toolbar = $bar;
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$rightside.append($hist); $rightside.append($hist);

@ -24,7 +24,6 @@ define([
var wcId = common.hrefToHexChannelId(config.href || window.location.href); var wcId = common.hrefToHexChannelId(config.href || window.location.href);
console.log(wcId);
var createRealtime = function () { var createRealtime = function () {
return ChainPad.create({ return ChainPad.create({
userName: 'history', userName: 'history',
@ -80,11 +79,32 @@ define([
if (History.loading) { return void console.error("History is already being loaded..."); } if (History.loading) { return void console.error("History is already being loaded..."); }
History.loading = true; History.loading = true;
var $toolbar = config.$toolbar; var $toolbar = config.$toolbar;
var noFunc = function () {};
var render = config.onRender || noFunc; if (!config.applyVal || !config.setHistory || !config.onLocal || !config.onRemote) {
var onClose = config.onClose || noFunc; throw new Error("Missing config element: applyVal, onLocal, onRemote, setHistory");
var onRevert = config.onRevert || noFunc; }
var onReady = config.onReady || noFunc;
// config.setHistory(bool, bool)
// - bool1: history value
// - bool2: reset old content?
var render = function (val) {
if (typeof val === "undefined") { return; }
try {
config.applyVal(val);
} catch (e) {
// Probably a parse error
console.error(e);
}
};
var onClose = function () { config.setHistory(false, true); };
var onRevert = function () {
config.setHistory(false, false);
config.onLocal();
config.onRemote();
};
var onReady = function () {
config.setHistory(true);
};
var Messages = common.Messages; var Messages = common.Messages;

@ -84,6 +84,7 @@ define([
common.getEditHashFromKeys = Hash.getEditHashFromKeys; common.getEditHashFromKeys = Hash.getEditHashFromKeys;
common.getViewHashFromKeys = Hash.getViewHashFromKeys; common.getViewHashFromKeys = Hash.getViewHashFromKeys;
common.getFileHashFromKeys = Hash.getFileHashFromKeys;
common.getSecrets = Hash.getSecrets; common.getSecrets = Hash.getSecrets;
common.getHashes = Hash.getHashes; common.getHashes = Hash.getHashes;
common.createChannelId = Hash.createChannelId; common.createChannelId = Hash.createChannelId;

@ -367,7 +367,7 @@ define([
return "Loading share button"; return "Loading share button";
}; };
var createFileShare = function () { var createFileShare = function (toolbar) {
if (!window.location.hash) { if (!window.location.hash) {
throw new Error("Unable to display the share button: hash required in the URL"); throw new Error("Unable to display the share button: hash required in the URL");
} }
@ -380,6 +380,7 @@ define([
if (success) { Cryptpad.log(Messages.shareSuccess); } if (success) { Cryptpad.log(Messages.shareSuccess); }
}); });
toolbar.$leftside.append($button);
return $button; return $button;
}; };
@ -852,7 +853,7 @@ define([
tb['useradmin'] = createUserAdmin; tb['useradmin'] = createUserAdmin;
var addElement = function (arr, additionnalCfg, init) { var addElement = toolbar.addElement = function (arr, additionnalCfg, init) {
if (typeof additionnalCfg === "object") { $.extend(true, config, additionnalCfg); } if (typeof additionnalCfg === "object") { $.extend(true, config, additionnalCfg); }
arr.forEach(function (el) { arr.forEach(function (el) {
if (typeof el !== "string" || !el.trim()) { return; } if (typeof el !== "string" || !el.trim()) { return; }

@ -43,6 +43,9 @@ body {
margin-top: 0.5em; margin-top: 0.5em;
} }
} }
div:focus {
outline: none;
}
.fa { .fa {
/*min-width: 17px;*/ /*min-width: 17px;*/
margin-right: 3px; margin-right: 3px;

@ -70,6 +70,10 @@ body {
} }
} }
div:focus {
outline: none;
}
.fa { .fa {
/*min-width: 17px;*/ /*min-width: 17px;*/
margin-right: 3px; margin-right: 3px;

@ -14,7 +14,7 @@
<div class="app-container" tabindex="0"> <div class="app-container" tabindex="0">
<div id="tree"> <div id="tree">
</div> </div>
<div id="content"> <div id="content" tabindex="2">
</div> </div>
<div id="treeContextMenu" class="contextMenu dropdown clearfix"> <div id="treeContextMenu" class="contextMenu dropdown clearfix">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;"> <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">

@ -297,6 +297,7 @@ define([
}; };
$content.on('mousedown', function (e) { $content.on('mousedown', function (e) {
if (e.which !== 1) { return; } if (e.which !== 1) { return; }
$content.focus();
sel.down = true; sel.down = true;
if (!e.ctrlKey) { removeSelected(); } if (!e.ctrlKey) { removeSelected(); }
var rect = e.currentTarget.getBoundingClientRect(); var rect = e.currentTarget.getBoundingClientRect();
@ -359,13 +360,15 @@ define([
}; };
$content.mousemove(sel.move); $content.mousemove(sel.move);
}); });
$content.on('mouseup', function (e) { $(ifrw).on('mouseup', function (e) {
if (!sel.down) { return; }
if (e.which !== 1) { return; } if (e.which !== 1) { return; }
sel.down = false; sel.down = false;
sel.$selectBox.hide(); sel.$selectBox.hide();
$content.off('mousemove', sel.move); $content.off('mousemove', sel.move);
delete sel.move; delete sel.move;
$content.find('.selectedTmp').removeClass('selectedTmp').addClass('selected'); $content.find('.selectedTmp').removeClass('selectedTmp').addClass('selected');
e.stopPropagation();
}); });
$(ifrw).keydown(function (e) { $(ifrw).keydown(function (e) {
@ -520,6 +523,10 @@ define([
placeholder: name, placeholder: name,
value: name value: name
}).data('path', path); }).data('path', path);
// Stop propagation on keydown to avoid issues with arrow keys
$input.on('keydown', function (e) { e.stopPropagation(); });
$input.on('keyup', function (e) { $input.on('keyup', function (e) {
if (e.which === 13) { if (e.which === 13) {
removeInput(true); removeInput(true);
@ -560,7 +567,7 @@ define([
var filterContextMenu = function ($menu, paths) { var filterContextMenu = function ($menu, paths) {
//var path = $element.data('path'); //var path = $element.data('path');
if (!paths || paths.length === 0) { console.error('no paths'); } if (!paths || paths.length === 0) { logError('no paths'); }
var hide = []; var hide = [];
var hasFolder = false; var hasFolder = false;
@ -763,6 +770,7 @@ define([
var displayMenu = function (e, $menu) { var displayMenu = function (e, $menu) {
$menu.css({ display: "block" }); $menu.css({ display: "block" });
if (APP.mobile()) { return; }
var h = $menu.outerHeight(); var h = $menu.outerHeight();
var w = $menu.outerWidth(); var w = $menu.outerWidth();
var wH = window.innerHeight; var wH = window.innerHeight;
@ -1785,7 +1793,7 @@ define([
module.resetTree(); module.resetTree();
// in history mode we want to focus the version number input // in history mode we want to focus the version number input
if (!history.isHistoryMode) { $tree.find('#searchInput').focus(); } if (!history.isHistoryMode && !APP.mobile()) { $tree.find('#searchInput').focus(); }
$tree.find('#searchInput')[0].selectionStart = getSearchCursor(); $tree.find('#searchInput')[0].selectionStart = getSearchCursor();
$tree.find('#searchInput')[0].selectionEnd = getSearchCursor(); $tree.find('#searchInput')[0].selectionEnd = getSearchCursor();
@ -2028,16 +2036,19 @@ define([
var search = APP.Search = {}; var search = APP.Search = {};
var createSearch = function ($container) { var createSearch = function ($container) {
var isInSearch = currentPath[0] === SEARCH; var isInSearch = currentPath[0] === SEARCH;
var $div = $('<div>', {'id': 'searchContainer'}); var $div = $('<div>', {'id': 'searchContainer', 'class': 'unselectable'});
var $input = $('<input>', { var $input = $('<input>', {
id: 'searchInput', id: 'searchInput',
type: 'text', type: 'text',
draggable: false,
tabindex: 1,
placeholder: Messages.fm_searchPlaceholder placeholder: Messages.fm_searchPlaceholder
}).keyup(function (e) { }).keyup(function (e) {
if (search.to) { window.clearTimeout(search.to); } if (search.to) { window.clearTimeout(search.to); }
if ([38, 39, 40, 41].indexOf(e.which) !== -1) { if ([38, 39, 40, 41].indexOf(e.which) !== -1) {
if (!$input.val()) { if (!$input.val()) {
$input.blur(); $input.blur();
$content.focus();
return; return;
} else { } else {
e.stopPropagation(); e.stopPropagation();
@ -2056,6 +2067,7 @@ define([
if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); } if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); }
return; return;
} }
if (APP.mobile()) { return; }
search.to = window.setTimeout(function () { search.to = window.setTimeout(function () {
if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); } if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); }
var newLocation = [SEARCH, $input.val()]; var newLocation = [SEARCH, $input.val()];
@ -2163,7 +2175,7 @@ define([
Cryptpad.getFileSize(el, function (e, bytes) { Cryptpad.getFileSize(el, function (e, bytes) {
if (e) { if (e) {
// there was a problem with the RPC // there was a problem with the RPC
console.error(e); logError(e);
// but we don't want to break the interface. // but we don't want to break the interface.
// continue as if there was no RPC // continue as if there was no RPC
@ -2239,7 +2251,7 @@ define([
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
var el = filesOp.find(paths[0].path); var el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) { getProperties(el, function (e, $prop) {
if (e) { return void console.error(e); } if (e) { return void logError(e); }
Cryptpad.alert('', undefined, true); Cryptpad.alert('', undefined, true);
$('.alertify .msg').html("").append($prop); $('.alertify .msg').html("").append($prop);
}); });
@ -2279,7 +2291,7 @@ define([
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
var el = filesOp.find(paths[0].path); var el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) { getProperties(el, function (e, $prop) {
if (e) { return void console.error(e); } if (e) { return void logError(e); }
Cryptpad.alert('', undefined, true); Cryptpad.alert('', undefined, true);
$('.alertify .msg').html("").append($prop); $('.alertify .msg').html("").append($prop);
}); });
@ -2369,9 +2381,18 @@ define([
module.hideMenu(); module.hideMenu();
}); });
$appContainer.on('mousedown', function (e) { // Chrome considers the double-click means "select all" in the window
$content.on('mousedown', function (e) {
$content.focus();
e.preventDefault();
});
$appContainer.on('mouseup', function (e) {
if (sel.down) { return; }
if (e.which !== 1) { return ; } if (e.which !== 1) { return ; }
removeSelected(e); removeSelected(e);
});
$appContainer.on('click', function (e) {
if (e.which !== 1) { return ; }
removeInput(); removeInput();
module.hideMenu(e); module.hideMenu(e);
hideNewButton(); hideNewButton();
@ -2514,7 +2535,6 @@ define([
setEditable(!bool); setEditable(!bool);
if (!bool && update) { if (!bool && update) {
history.onLeaveHistory(); history.onLeaveHistory();
//init(); //TODO real proxy here
} }
}; };
@ -2667,33 +2687,20 @@ define([
} }
/* add a history button */ /* add a history button */
var histConfig = {}; var histConfig = {
histConfig.onRender = function (val) { onLocal: function () {
if (typeof val === "undefined") { return; } proxy.drive = history.currentObj.drive;
try { },
onRemote: function () {},
setHistory: setHistory,
applyVal: function (val) {
var obj = JSON.parse(val || '{}'); var obj = JSON.parse(val || '{}');
history.currentObj = obj; history.currentObj = obj;
history.onEnterHistory(obj); history.onEnterHistory(obj);
} catch (e) { },
// Probably a parse error $toolbar: APP.$bar,
console.error(e); href: window.location.origin + window.location.pathname + APP.hash
}
};
histConfig.onClose = function () {
// Close button clicked
setHistory(false, true);
};
histConfig.onRevert = function () {
// Revert button clicked
setHistory(false, false);
proxy.drive = history.currentObj.drive;
};
histConfig.onReady = function () {
// Called when the history is loaded and the UI displayed
setHistory(true);
}; };
histConfig.$toolbar = APP.$bar;
histConfig.href = window.location.origin + window.location.pathname + APP.hash;
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$rightside.append($hist); $rightside.append($hist);

@ -2,7 +2,7 @@ define([
'jquery', 'jquery',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/common/toolbar.js', '/common/toolbar2.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/visible.js', '/common/visible.js',
'/common/notify.js', '/common/notify.js',
@ -24,6 +24,8 @@ define([
Cryptpad.addLoadingScreen(); Cryptpad.addLoadingScreen();
var Title;
var myFile; var myFile;
var myDataType; var myDataType;
@ -68,17 +70,13 @@ define([
var uri = ['', 'blob', id.slice(0,2), id].join('/'); var uri = ['', 'blob', id.slice(0,2), id].join('/');
console.log("encrypted blob is now available as %s", uri); console.log("encrypted blob is now available as %s", uri);
// TODO use cryptpad-common utilities var b64Key = Nacl.util.encodeBase64(key);
window.location.hash = [ window.location.hash = Cryptpad.getFileHashFromKeys(id, b64Key);
'',
2,
Cryptpad.hexToBase64(id).replace(/\//g, '-'),
Nacl.util.encodeBase64(key).replace(/\//g, '-'),
''
].join('/');
$form.hide(); $form.hide();
APP.toolbar.addElement(['fileshare'], {});
// check if the uploaded file can be decrypted // check if the uploaded file can be decrypted
var newU8 = FileCrypto.joinChunks(chunks); var newU8 = FileCrypto.joinChunks(chunks);
FileCrypto.decrypt(newU8, key, function (e, res) { FileCrypto.decrypt(newU8, key, function (e, res) {
@ -88,7 +86,8 @@ define([
myDataType = res.metadata.type; myDataType = res.metadata.type;
var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href)); var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href));
APP.updateTitle(title || defaultName); Title.updateTitle(title || defaultName);
APP.toolbar.title.show();
Cryptpad.alert("successfully uploaded: " + title); Cryptpad.alert("successfully uploaded: " + title);
}); });
}); });
@ -133,9 +132,6 @@ define([
uploadMode = true; uploadMode = true;
} }
var parsed = Cryptpad.parsePadUrl(window.location.href);
var defaultName = Cryptpad.getDefaultName(parsed);
var getTitle = function () { var getTitle = function () {
var pad = Cryptpad.getRelativeHref(window.location.href); var pad = Cryptpad.getRelativeHref(window.location.href);
var fo = Cryptpad.getStore().getProxy().fo; var fo = Cryptpad.getStore().getProxy().fo;
@ -143,27 +139,6 @@ define([
return data ? data.title : undefined; return data ? data.title : undefined;
}; };
var updateTitle = APP.updateTitle = function (newTitle) {
Cryptpad.renamePad(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
return;
}
document.title = newTitle;
$bar.find('.' + Toolbar.constants.title).find('span.title').text(data);
$bar.find('.' + Toolbar.constants.title).find('input').val(data);
});
};
var suggestName = function () {
return document.title || getTitle() || '';
};
var renameCb = function (err, title) {
document.title = title;
};
var exportFile = function () { var exportFile = function () {
var suggestion = document.title; var suggestion = document.title;
Cryptpad.prompt(Messages.exportPrompt, Cryptpad.prompt(Messages.exportPrompt,
@ -174,33 +149,33 @@ define([
}); });
}; };
var displayed = ['useradmin', 'newpad', 'limit']; Title = Cryptpad.createTitle({}, function(){}, Cryptpad);
var displayed = ['title', 'useradmin', 'newpad', 'limit'];
if (secret && hexFileName) { if (secret && hexFileName) {
displayed.push('share'); displayed.push('fileshare');
} }
var configTb = { var configTb = {
displayed: displayed, displayed: displayed,
ifrw: ifrw, ifrw: ifrw,
common: Cryptpad, common: Cryptpad,
title: { title: Title.getTitleConfig(),
onRename: renameCb, hideDisplayName: true,
defaultName: defaultName, $container: $bar
suggestName: suggestName
},
share: {
secret: secret,
channel: hexFileName
},
hideDisplayName: true
}; };
Toolbar.create($bar, null, null, null, null, configTb); var toolbar = APP.toolbar = Toolbar.create(configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
Title.setToolbar(toolbar);
if (uploadMode) { toolbar.title.hide(); }
var $rightside = toolbar.$rightside;
var $export = Cryptpad.createButton('export', true, {}, exportFile); var $export = Cryptpad.createButton('export', true, {}, exportFile);
$rightside.append($export); $rightside.append($export);
updateTitle(Cryptpad.initialName || getTitle() || defaultName); Title.updateTitle(Cryptpad.initialName || getTitle() || Title.defaultTitle);
if (!uploadMode) { if (!uploadMode) {
var src = Cryptpad.getBlobPathFromHex(hexFileName); var src = Cryptpad.getBlobPathFromHex(hexFileName);
@ -219,7 +194,7 @@ define([
var title = document.title = data.metadata.name; var title = document.title = data.metadata.name;
myFile = data.content; myFile = data.content;
myDataType = data.metadata.type; myDataType = data.metadata.type;
updateTitle(title || defaultName); Title.updateTitle(title || Title.defaultTitle);
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();
}); });
}); });

@ -57,65 +57,68 @@ define([
}); });
$('button.login').click(function () { $('button.login').click(function () {
Cryptpad.addLoadingScreen(Messages.login_hashing); // setTimeout 100ms to remove the keyboard on mobile devices before the loading screen pops up
// We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password
window.setTimeout(function () { window.setTimeout(function () {
loginReady(function () { Cryptpad.addLoadingScreen(Messages.login_hashing);
var uname = $uname.val(); // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password
var passwd = $passwd.val(); window.setTimeout(function () {
Login.loginOrRegister(uname, passwd, false, function (err, result) { loginReady(function () {
if (!err) { var uname = $uname.val();
var proxy = result.proxy; var passwd = $passwd.val();
Login.loginOrRegister(uname, passwd, false, function (err, result) {
if (!err) {
var proxy = result.proxy;
// successful validation and user already exists // successful validation and user already exists
// set user hash in localStorage and redirect to drive // set user hash in localStorage and redirect to drive
if (!proxy.login_name) { if (!proxy.login_name) {
result.proxy.login_name = result.userName; result.proxy.login_name = result.userName;
} }
proxy.edPrivate = result.edPrivate; proxy.edPrivate = result.edPrivate;
proxy.edPublic = result.edPublic; proxy.edPublic = result.edPublic;
Cryptpad.feedback('LOGIN', true); Cryptpad.feedback('LOGIN', true);
Cryptpad.whenRealtimeSyncs(result.realtime, function() { Cryptpad.whenRealtimeSyncs(result.realtime, function() {
Cryptpad.login(result.userHash, result.userName, function () { Cryptpad.login(result.userHash, result.userName, function () {
if (sessionStorage.redirectTo) { if (sessionStorage.redirectTo) {
var h = sessionStorage.redirectTo; var h = sessionStorage.redirectTo;
var parser = document.createElement('a'); var parser = document.createElement('a');
parser.href = h; parser.href = h;
if (parser.origin === window.location.origin) { if (parser.origin === window.location.origin) {
delete sessionStorage.redirectTo; delete sessionStorage.redirectTo;
window.location.href = h; window.location.href = h;
return; return;
}
} }
} window.location.href = '/drive/';
window.location.href = '/drive/'; });
});
});
return;
}
switch (err) {
case 'NO_SUCH_USER':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_noSuchUser);
});
break;
case 'INVAL_USER':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_invalUser);
}); });
break; return;
case 'INVAL_PASS': }
Cryptpad.removeLoadingScreen(function () { switch (err) {
Cryptpad.alert(Messages.login_invalPass); case 'NO_SUCH_USER':
}); Cryptpad.removeLoadingScreen(function () {
break; Cryptpad.alert(Messages.login_noSuchUser);
default: // UNHANDLED ERROR });
Cryptpad.errorLoadingScreen(Messages.login_unhandledError); break;
} case 'INVAL_USER':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_invalUser);
});
break;
case 'INVAL_PASS':
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_invalPass);
});
break;
default: // UNHANDLED ERROR
Cryptpad.errorLoadingScreen(Messages.login_unhandledError);
}
});
}); });
}); }, 0);
}, 0); }, 100);
}); });
}); });
}); });

@ -499,31 +499,13 @@ define([
} }
/* add a history button */ /* add a history button */
var histConfig = {}; var histConfig = {
histConfig.onRender = function (val) { onLocal: realtimeOptions.onLocal(),
if (typeof val === "undefined") { return; } onRemote: realtimeOptions.onRemote(),
try { setHistory: setHistory,
applyHjson(val || '["BODY",{},[]]'); applyVal: function (val) { applyHjson(val || '["BODY",{},[]]'); },
} catch (e) { $toolbar: $bar
// Probably a parse error
console.error(e);
}
};
histConfig.onClose = function () {
// Close button clicked
setHistory(false, true);
};
histConfig.onRevert = function () {
// Revert button clicked
setHistory(false, false);
realtimeOptions.onLocal();
realtimeOptions.onRemote();
};
histConfig.onReady = function () {
// Called when the history is loaded and the UI displayed
setHistory(true);
}; };
histConfig.$toolbar = $bar;
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$rightside.append($hist); $rightside.append($hist);

@ -101,57 +101,63 @@ define([
function (yes) { function (yes) {
if (!yes) { return; } if (!yes) { return; }
Cryptpad.addLoadingScreen(Messages.login_hashing); // setTimeout 100ms to remove the keyboard on mobile devices before the loading screen pops up
Login.loginOrRegister(uname, passwd, true, function (err, result) { window.setTimeout(function () {
var proxy = result.proxy; Cryptpad.addLoadingScreen(Messages.login_hashing);
// We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password
if (err) { window.setTimeout(function () {
switch (err) { Login.loginOrRegister(uname, passwd, true, function (err, result) {
case 'NO_SUCH_USER': var proxy = result.proxy;
Cryptpad.removeLoadingScreen(function () {
Cryptpad.alert(Messages.login_noSuchUser); if (err) {
}); switch (err) {
break; case 'NO_SUCH_USER':
case 'INVAL_USER': Cryptpad.removeLoadingScreen(function () {
Cryptpad.removeLoadingScreen(function () { Cryptpad.alert(Messages.login_noSuchUser);
Cryptpad.alert(Messages.login_invalUser); });
}); break;
break; case 'INVAL_USER':
case 'INVAL_PASS': Cryptpad.removeLoadingScreen(function () {
Cryptpad.removeLoadingScreen(function () { Cryptpad.alert(Messages.login_invalUser);
Cryptpad.alert(Messages.login_invalPass); });
}); break;
break; case 'INVAL_PASS':
case 'ALREADY_REGISTERED': Cryptpad.removeLoadingScreen(function () {
Cryptpad.removeLoadingScreen(function () { Cryptpad.alert(Messages.login_invalPass);
Cryptpad.confirm(Messages.register_alreadyRegistered, function (yes) { });
if (!yes) { return; } break;
proxy.login_name = uname; case 'ALREADY_REGISTERED':
Cryptpad.removeLoadingScreen(function () {
if (!proxy[Cryptpad.displayNameKey]) { Cryptpad.confirm(Messages.register_alreadyRegistered, function (yes) {
proxy[Cryptpad.displayNameKey] = uname; if (!yes) { return; }
} proxy.login_name = uname;
Cryptpad.eraseTempSessionValues();
logMeIn(result); if (!proxy[Cryptpad.displayNameKey]) {
}); proxy[Cryptpad.displayNameKey] = uname;
}); }
break; Cryptpad.eraseTempSessionValues();
default: // UNHANDLED ERROR logMeIn(result);
Cryptpad.errorLoadingScreen(Messages.login_unhandledError); });
} });
return; break;
} default: // UNHANDLED ERROR
Cryptpad.eraseTempSessionValues(); Cryptpad.errorLoadingScreen(Messages.login_unhandledError);
if (shouldImport) { }
sessionStorage.migrateAnonDrive = 1; return;
} }
Cryptpad.eraseTempSessionValues();
proxy.login_name = uname; if (shouldImport) {
proxy[Cryptpad.displayNameKey] = uname; sessionStorage.migrateAnonDrive = 1;
sessionStorage.createReadme = 1; }
logMeIn(result); proxy.login_name = uname;
}); proxy[Cryptpad.displayNameKey] = uname;
sessionStorage.createReadme = 1;
logMeIn(result);
});
}, 0);
}, 100);
}, { }, {
ok: Messages.register_writtenPassword, ok: Messages.register_writtenPassword,
cancel: Messages.register_cancel, cancel: Messages.register_cancel,

@ -293,34 +293,17 @@ define([
} }
/* add a history button */ /* add a history button */
var histConfig = {}; var histConfig = {
histConfig.onRender = function (val) { onLocal: config.onLocal(),
if (typeof val === "undefined") { return; } onRemote: config.onRemote(),
try { setHistory: setHistory,
var hjson = JSON.parse(val || '{}'); applyVal: function (val) {
var remoteDoc = hjson.content; var remoteDoc = JSON.parse(val || '{}').content;
editor.setValue(remoteDoc || ''); editor.setValue(remoteDoc || '');
editor.save(); editor.save();
} catch (e) { },
// Probably a parse error $toolbar: $bar
console.error(e);
}
};
histConfig.onClose = function () {
// Close button clicked
setHistory(false, true);
};
histConfig.onRevert = function () {
// Revert button clicked
setHistory(false, false);
config.onLocal();
config.onRemote();
};
histConfig.onReady = function () {
// Called when the history is loaded and the UI displayed
setHistory(true);
}; };
histConfig.$toolbar = $bar;
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$rightside.append($hist); $rightside.append($hist);
@ -491,11 +474,11 @@ define([
Slide.onChange(function (o, n, l) { Slide.onChange(function (o, n, l) {
if (n !== null) { if (n !== null) {
document.title = APP.title + ' (' + (++n) + '/' + l + ')'; document.title = Title.title + ' (' + (++n) + '/' + l + ')';
return; return;
} }
console.log("Exiting presentation mode"); console.log("Exiting presentation mode");
document.title = APP.title; document.title = Title.title;
}); });
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();

@ -211,7 +211,10 @@ define([
$(ifrw).focus(); $(ifrw).focus();
change(null, Slide.index); change(null, Slide.index);
if (!isPresentURL()) { if (!isPresentURL()) {
window.location.hash += '/present'; if (window.location.href.slice(-1) !== '/') {
window.location.hash += '/';
}
window.location.hash += 'present';
} }
$pad.contents().find('.cryptpad-present-button').hide(); $pad.contents().find('.cryptpad-present-button').hide();
$pad.contents().find('.cryptpad-source-button').show(); $pad.contents().find('.cryptpad-source-button').show();
@ -220,7 +223,7 @@ define([
$('.top-bar').hide(); $('.top-bar').hide();
return; return;
} }
window.location.hash = window.location.hash.replace(/\/present$/, ''); window.location.hash = window.location.hash.replace(/\/present$/, '/');
change(Slide.index, null); change(Slide.index, null);
$pad.contents().find('.cryptpad-present-button').show(); $pad.contents().find('.cryptpad-present-button').show();
$pad.contents().find('.cryptpad-source-button').hide(); $pad.contents().find('.cryptpad-source-button').hide();

Loading…
Cancel
Save