diff --git a/app.js b/app.js index 7b5e619..ba0b67d 100644 --- a/app.js +++ b/app.js @@ -626,8 +626,8 @@ process.on('uncaughtException', function (err) { process.exit(1); }); -// gracefully exit -process.on('SIGINT', function () { +// install exit handler +function handleTermSignals() { config.maintenance = true; // disconnect all socket.io clients Object.keys(io.sockets.sockets).forEach(function (key) { @@ -649,4 +649,6 @@ process.on('SIGINT', function () { }); } }, 100); -}); +} +process.on('SIGINT', handleTermSignals); +process.on('SIGTERM', handleTermSignals); diff --git a/lib/realtime.js b/lib/realtime.js index 0f2a668..fadea4f 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -363,6 +363,22 @@ function interruptConnection(socket, note, user) { connectNextSocket(); } +function checkViewPermission(req, note) { + if (note.permission == 'private') { + if (req.user && req.user.logged_in && req.user.id == note.owner) + return true; + else + return false; + } else if (note.permission == 'limited' || note.permission == 'protected') { + if(req.user && req.user.logged_in) + return true; + else + return false; + } else { + return true; + } +} + var isConnectionBusy = false; var connectionSocketQueue = []; var isDisconnectBusy = false; @@ -373,14 +389,10 @@ function finishConnection(socket, note, user) { if (!socket || !note || !user) { return interruptConnection(socket, note, user); } - //check view permission - if (note.permission == 'limited' || note.permission == 'protected' || note.permission == 'private') { - if (socket.request.user && socket.request.user.logged_in && socket.request.user.id == note.owner) { - //na - } else { - interruptConnection(socket, note, user); - return failConnection(403, 'connection forbidden', socket); - } + // check view permission + if (!checkViewPermission(socket.request, note)) { + interruptConnection(socket, note, user); + return failConnection(403, 'connection forbidden', socket); } // update user color to author color if (note.authors[user.userid]) { @@ -789,18 +801,14 @@ function connection(socket) { for (var i = 0, l = note.socks.length; i < l; i++) { var sock = note.socks[i]; if (typeof sock !== 'undefined' && sock) { - //check view permission - if (permission == 'limited' || permission == 'protected' || permission == 'private') { - if (sock.request.user && sock.request.user.logged_in && sock.request.user.id == note.owner) { - //na - } else { - sock.emit('info', { - code: 403 - }); - setTimeout(function () { - sock.disconnect(true); - }, 0); - } + // check view permission + if (!checkViewPermission(sock.request, note)) { + sock.emit('info', { + code: 403 + }); + setTimeout(function () { + sock.disconnect(true); + }, 0); } } } diff --git a/lib/response.js b/lib/response.js index 9014a0a..585d1d5 100755 --- a/lib/response.js +++ b/lib/response.js @@ -97,7 +97,8 @@ function responseHackMD(res, note) { dropbox: config.dropbox, google: config.google, ldap: config.ldap, - email: config.email + email: config.email, + allowemailregister: config.allowemailregister }); } @@ -126,10 +127,10 @@ function checkViewPermission(req, note) { else return true; } else if (note.permission == 'limited' || note.permission == 'protected') { - if( !req.isAuthenticated() ) { + if(!req.isAuthenticated()) return false; - } - return true; + else + return true; } else { return true; } diff --git a/public/css/cover.css b/public/css/cover.css index dcf7321..a1527bf 100644 --- a/public/css/cover.css +++ b/public/css/cover.css @@ -78,6 +78,13 @@ body { margin-top: 10px; margin-bottom: 10px; } +.masthead-nav { + text-align: left; + max-width: 1000px; + margin: 0 auto; + padding-left: 10px; + padding-right: 10px; +} .masthead-nav > li { display: inline-block; } @@ -263,9 +270,14 @@ input { text-decoration: underline; } .ui-avatar { - border-radius: 15em; - height: auto; - width: 60px; + display: inline-block; + overflow: hidden; + line-height: 1; + vertical-align: middle; + border-radius: 3px; +} +.ui-avatar.circle { + border-radius: 50%; } .ui-history-close { position: absolute; @@ -338,6 +350,10 @@ input { display: inline-block !important; } +.btn-link, .btn-link:hover, .btn-link:focus, .btn-link:active { + color: white; +} + select { color: black; } diff --git a/public/js/cover.js b/public/js/cover.js index a3ed778..79b168d 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -102,7 +102,12 @@ $(".masthead-nav li").click(function () { $(this).addClass("active"); }); -$(".ui-home").click(() => { +// prevent empty link change hash +$('a[href="#"]').click(function (e) { + e.preventDefault(); +}); + +$(".ui-home").click(function (e) { if (!$("#home").is(':visible')) { $(".section:visible").hide(); $("#home").fadeIn(); @@ -366,7 +371,7 @@ $(".ui-refresh-history").click(() => { $('.search').val(''); historyList.search(); $('#history-list').slideUp('fast'); - $('.pagination').slideUp('fast'); + $('.pagination').hide(); resetCheckAuth(); historyList.clear(); @@ -378,7 +383,6 @@ $(".ui-refresh-history").click(() => { $('.search').val(lastKeyword); checkHistoryList(); $('#history-list').slideDown('fast'); - $('.pagination').slideDown('fast'); }); }); diff --git a/public/js/index.js b/public/js/index.js index a7e69e8..8e3bc56 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1761,6 +1761,10 @@ ui.toolbar.uploadImage.bind('change', function (e) { ui.toc.dropdown.click(function (e) { e.stopPropagation(); }); +// prevent empty link change hash +$('a[href="#"]').click(function (e) { + e.preventDefault(); +}); //modal actions var revisions = []; diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js index f1a03c7..58fa55c 100644 --- a/public/js/lib/common/login.js +++ b/public/js/lib/common/login.js @@ -4,7 +4,7 @@ let checkAuth = false; let profile = null; let lastLoginState = getLoginState(); let lastUserId = getUserId(); -let loginStateChangeEvent = null; +var loginStateChangeEvent = null; export function setloginStateChangeEvent(func) { loginStateChangeEvent = func; @@ -32,9 +32,7 @@ export function setLoginState(bool, id) { export function checkLoginStateChanged() { if (getLoginState() != lastLoginState || getUserId() != lastUserId) { - if (loginStateChangeEvent) { - loginStateChangeEvent(); - } + if (loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100); return true; } else { return false; @@ -56,8 +54,7 @@ export function clearLoginState() { export function checkIfAuth(yesCallback, noCallback) { const cookieLoginState = getLoginState(); - if (checkLoginStateChanged()) - checkAuth = false; + if (checkLoginStateChanged()) checkAuth = false; if (!checkAuth || typeof cookieLoginState == 'undefined') { $.get(`${serverurl}/me`) .done(data => { diff --git a/public/views/index.ejs b/public/views/index.ejs index b1a1feb..d258857 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -41,6 +41,25 @@
  • <%= __('History') %>
  • +
    + <% if(allowAnonymous) { %> + <%= __('New guest note') %> + <% } %> + <% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %> + + <% } %> +
    +
    + <%= __('New note') %> + + + + +
    @@ -61,19 +80,15 @@ <% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
    - <%= __('Sign In') %> + <%= __('Sign In') %>
    - <% }%> - <% if((facebook || twitter || github || gitlab || dropbox || google || email) && allowAnonymous) { %> <%= __('or') %> - <% }%> - <% if(allowAnonymous) { %> + <% } %> - <%= __('New guest note') %> + <%= __('Explore all features') %>

    - <% }%>
    @@ -98,21 +113,10 @@
    style="display:none;"<% } %>> - <% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %> -