Merge branch 'master' into frontend-next
This commit is contained in:
commit
4bbe035beb
8 changed files with 95 additions and 59 deletions
8
app.js
8
app.js
|
@ -626,8 +626,8 @@ process.on('uncaughtException', function (err) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// gracefully exit
|
// install exit handler
|
||||||
process.on('SIGINT', function () {
|
function handleTermSignals() {
|
||||||
config.maintenance = true;
|
config.maintenance = true;
|
||||||
// disconnect all socket.io clients
|
// disconnect all socket.io clients
|
||||||
Object.keys(io.sockets.sockets).forEach(function (key) {
|
Object.keys(io.sockets.sockets).forEach(function (key) {
|
||||||
|
@ -649,4 +649,6 @@ process.on('SIGINT', function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
}
|
||||||
|
process.on('SIGINT', handleTermSignals);
|
||||||
|
process.on('SIGTERM', handleTermSignals);
|
||||||
|
|
|
@ -363,6 +363,22 @@ function interruptConnection(socket, note, user) {
|
||||||
connectNextSocket();
|
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 isConnectionBusy = false;
|
||||||
var connectionSocketQueue = [];
|
var connectionSocketQueue = [];
|
||||||
var isDisconnectBusy = false;
|
var isDisconnectBusy = false;
|
||||||
|
@ -373,15 +389,11 @@ function finishConnection(socket, note, user) {
|
||||||
if (!socket || !note || !user) {
|
if (!socket || !note || !user) {
|
||||||
return interruptConnection(socket, note, user);
|
return interruptConnection(socket, note, user);
|
||||||
}
|
}
|
||||||
//check view permission
|
// check view permission
|
||||||
if (note.permission == 'limited' || note.permission == 'protected' || note.permission == 'private') {
|
if (!checkViewPermission(socket.request, note)) {
|
||||||
if (socket.request.user && socket.request.user.logged_in && socket.request.user.id == note.owner) {
|
|
||||||
//na
|
|
||||||
} else {
|
|
||||||
interruptConnection(socket, note, user);
|
interruptConnection(socket, note, user);
|
||||||
return failConnection(403, 'connection forbidden', socket);
|
return failConnection(403, 'connection forbidden', socket);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// update user color to author color
|
// update user color to author color
|
||||||
if (note.authors[user.userid]) {
|
if (note.authors[user.userid]) {
|
||||||
user.color = users[socket.id].color = note.authors[user.userid].color;
|
user.color = users[socket.id].color = note.authors[user.userid].color;
|
||||||
|
@ -789,11 +801,8 @@ function connection(socket) {
|
||||||
for (var i = 0, l = note.socks.length; i < l; i++) {
|
for (var i = 0, l = note.socks.length; i < l; i++) {
|
||||||
var sock = note.socks[i];
|
var sock = note.socks[i];
|
||||||
if (typeof sock !== 'undefined' && sock) {
|
if (typeof sock !== 'undefined' && sock) {
|
||||||
//check view permission
|
// check view permission
|
||||||
if (permission == 'limited' || permission == 'protected' || permission == 'private') {
|
if (!checkViewPermission(sock.request, note)) {
|
||||||
if (sock.request.user && sock.request.user.logged_in && sock.request.user.id == note.owner) {
|
|
||||||
//na
|
|
||||||
} else {
|
|
||||||
sock.emit('info', {
|
sock.emit('info', {
|
||||||
code: 403
|
code: 403
|
||||||
});
|
});
|
||||||
|
@ -803,7 +812,6 @@ function connection(socket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
return logger.error('update note permission failed: ' + err);
|
return logger.error('update note permission failed: ' + err);
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,7 +97,8 @@ function responseHackMD(res, note) {
|
||||||
dropbox: config.dropbox,
|
dropbox: config.dropbox,
|
||||||
google: config.google,
|
google: config.google,
|
||||||
ldap: config.ldap,
|
ldap: config.ldap,
|
||||||
email: config.email
|
email: config.email,
|
||||||
|
allowemailregister: config.allowemailregister
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,9 +127,9 @@ function checkViewPermission(req, note) {
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
} else if (note.permission == 'limited' || note.permission == 'protected') {
|
} else if (note.permission == 'limited' || note.permission == 'protected') {
|
||||||
if( !req.isAuthenticated() ) {
|
if(!req.isAuthenticated())
|
||||||
return false;
|
return false;
|
||||||
}
|
else
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -78,6 +78,13 @@ body {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
.masthead-nav {
|
||||||
|
text-align: left;
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding-left: 10px;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
.masthead-nav > li {
|
.masthead-nav > li {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
@ -263,9 +270,14 @@ input {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
.ui-avatar {
|
.ui-avatar {
|
||||||
border-radius: 15em;
|
display: inline-block;
|
||||||
height: auto;
|
overflow: hidden;
|
||||||
width: 60px;
|
line-height: 1;
|
||||||
|
vertical-align: middle;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
.ui-avatar.circle {
|
||||||
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
.ui-history-close {
|
.ui-history-close {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -338,6 +350,10 @@ input {
|
||||||
display: inline-block !important;
|
display: inline-block !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-link, .btn-link:hover, .btn-link:focus, .btn-link:active {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,12 @@ $(".masthead-nav li").click(function () {
|
||||||
$(this).addClass("active");
|
$(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')) {
|
if (!$("#home").is(':visible')) {
|
||||||
$(".section:visible").hide();
|
$(".section:visible").hide();
|
||||||
$("#home").fadeIn();
|
$("#home").fadeIn();
|
||||||
|
@ -366,7 +371,7 @@ $(".ui-refresh-history").click(() => {
|
||||||
$('.search').val('');
|
$('.search').val('');
|
||||||
historyList.search();
|
historyList.search();
|
||||||
$('#history-list').slideUp('fast');
|
$('#history-list').slideUp('fast');
|
||||||
$('.pagination').slideUp('fast');
|
$('.pagination').hide();
|
||||||
|
|
||||||
resetCheckAuth();
|
resetCheckAuth();
|
||||||
historyList.clear();
|
historyList.clear();
|
||||||
|
@ -378,7 +383,6 @@ $(".ui-refresh-history").click(() => {
|
||||||
$('.search').val(lastKeyword);
|
$('.search').val(lastKeyword);
|
||||||
checkHistoryList();
|
checkHistoryList();
|
||||||
$('#history-list').slideDown('fast');
|
$('#history-list').slideDown('fast');
|
||||||
$('.pagination').slideDown('fast');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1761,6 +1761,10 @@ ui.toolbar.uploadImage.bind('change', function (e) {
|
||||||
ui.toc.dropdown.click(function (e) {
|
ui.toc.dropdown.click(function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
// prevent empty link change hash
|
||||||
|
$('a[href="#"]').click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
//modal actions
|
//modal actions
|
||||||
var revisions = [];
|
var revisions = [];
|
||||||
|
|
|
@ -4,7 +4,7 @@ let checkAuth = false;
|
||||||
let profile = null;
|
let profile = null;
|
||||||
let lastLoginState = getLoginState();
|
let lastLoginState = getLoginState();
|
||||||
let lastUserId = getUserId();
|
let lastUserId = getUserId();
|
||||||
let loginStateChangeEvent = null;
|
var loginStateChangeEvent = null;
|
||||||
|
|
||||||
export function setloginStateChangeEvent(func) {
|
export function setloginStateChangeEvent(func) {
|
||||||
loginStateChangeEvent = func;
|
loginStateChangeEvent = func;
|
||||||
|
@ -32,9 +32,7 @@ export function setLoginState(bool, id) {
|
||||||
|
|
||||||
export function checkLoginStateChanged() {
|
export function checkLoginStateChanged() {
|
||||||
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
||||||
if (loginStateChangeEvent) {
|
if (loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100);
|
||||||
loginStateChangeEvent();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -56,8 +54,7 @@ export function clearLoginState() {
|
||||||
|
|
||||||
export function checkIfAuth(yesCallback, noCallback) {
|
export function checkIfAuth(yesCallback, noCallback) {
|
||||||
const cookieLoginState = getLoginState();
|
const cookieLoginState = getLoginState();
|
||||||
if (checkLoginStateChanged())
|
if (checkLoginStateChanged()) checkAuth = false;
|
||||||
checkAuth = false;
|
|
||||||
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
||||||
$.get(`${serverurl}/me`)
|
$.get(`${serverurl}/me`)
|
||||||
.done(data => {
|
.done(data => {
|
||||||
|
|
|
@ -41,6 +41,25 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="ui-history<% if(signin) { %> active<% } %>"><a href="#"><%= __('History') %></a>
|
<li class="ui-history<% if(signin) { %> active<% } %>"><a href="#"><%= __('History') %></a>
|
||||||
</li>
|
</li>
|
||||||
|
<div class="ui-signin" style="float: right; margin-top: 8px;<% if(signin) { %> display: none;<% } %>">
|
||||||
|
<% if(allowAnonymous) { %>
|
||||||
|
<a type="button" href="<%- url %>/new" class="btn btn-sm btn-link"><i class="fa fa-plus"></i> <%= __('New guest note') %></a>
|
||||||
|
<% } %>
|
||||||
|
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
|
||||||
|
<button class="btn btn-sm btn-success ui-signin" data-toggle="modal" data-target=".signin-modal"><%= __('Sign In') %></button>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
<div class="ui-signout" style="float: right; margin-top: 8px;<% if(!signin) { %> display: none;<% } %>">
|
||||||
|
<a type="button" href="<%- url %>/new" class="btn btn-sm btn-link"><i class="fa fa-plus"></i> <%= __('New note') %></a>
|
||||||
|
<span class="ui-profile dropdown pull-right">
|
||||||
|
<button id="profileLabel" class="btn btn-sm btn-link ui-profile-label" style="padding-right: 0;" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<img class="ui-avatar" width="20" height="20"><span class="hidden-xs hidden-sm"> <span class="ui-name"></span></span> <i class="fa fa-caret-down"></i>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="profileLabel">
|
||||||
|
<li><a href="<%- url %>/logout"><i class="fa fa-sign-out fa-fw"></i> <%= __('Sign Out') %></a></li>
|
||||||
|
</ul>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
@ -61,19 +80,15 @@
|
||||||
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
|
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
|
||||||
<span class="ui-signin">
|
<span class="ui-signin">
|
||||||
<br>
|
<br>
|
||||||
<a type="button" class="btn btn-lg btn-success ui-signin" data-toggle="modal" data-target=".signin-modal" style="min-width: 170px;"><%= __('Sign In') %></a>
|
<a type="button" class="btn btn-lg btn-success ui-signin" data-toggle="modal" data-target=".signin-modal" style="min-width: 200px;"><%= __('Sign In') %></a>
|
||||||
</span>
|
</span>
|
||||||
<% }%>
|
|
||||||
<% if((facebook || twitter || github || gitlab || dropbox || google || email) && allowAnonymous) { %>
|
|
||||||
<span class="ui-or"><%= __('or') %></span>
|
<span class="ui-or"><%= __('or') %></span>
|
||||||
<% }%>
|
<% } %>
|
||||||
<% if(allowAnonymous) { %>
|
|
||||||
<span class="ui-signin">
|
<span class="ui-signin">
|
||||||
<a href="<%- url %>/new" class="btn btn-lg btn-default" style="min-width: 170px;"><%= __('New guest note') %></a>
|
<a type="button" href="<%- url %>/features" class="btn btn-lg btn-primary" style="min-width: 200px;"><%= __('Explore all features') %></a>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
</span>
|
</span>
|
||||||
<% }%>
|
|
||||||
<div class="lead row" style="width: 90%; margin: 0 auto;">
|
<div class="lead row" style="width: 90%; margin: 0 auto;">
|
||||||
<div class="col-md-4 inner">
|
<div class="col-md-4 inner">
|
||||||
<a href="<%- url %>/features#share-notes">
|
<a href="<%- url %>/features#share-notes">
|
||||||
|
@ -98,21 +113,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="history" class="section"<% if(!signin) { %> style="display:none;"<% } %>>
|
<div id="history" class="section"<% if(!signin) { %> style="display:none;"<% } %>>
|
||||||
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
|
<div class="ui-signin"<% if(signin) { %> style="display:none;"<% } %>>
|
||||||
<div class="ui-signin">
|
|
||||||
<p><%= __('Below is the history from browser') %></p>
|
<p><%= __('Below is the history from browser') %></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui-signout" style="display:none;">
|
<br>
|
||||||
<img class="ui-avatar">
|
|
||||||
<h4 class="ui-welcome"><%= __('Welcome!') %> <span class="ui-name"></span></h4>
|
|
||||||
<a href="<%- url %>/new" class="btn btn-md btn-default"><%= __('New note') %></a> <%= __('or') %>
|
|
||||||
<a href="#" class="btn btn-danger ui-logout"><%= __('Sign Out') %></a>
|
|
||||||
</div>
|
|
||||||
<% }%>
|
|
||||||
<h4>
|
|
||||||
<a type="button" href="<%- url %>/features" class="btn btn-primary"><%= __('Explore all features') %></a>
|
|
||||||
</h4>
|
|
||||||
<hr>
|
|
||||||
<form class="form-inline">
|
<form class="form-inline">
|
||||||
<div class="form-group" style="vertical-align: bottom;">
|
<div class="form-group" style="vertical-align: bottom;">
|
||||||
<input class="form-control ui-use-tags" placeholder="<%= __('Select tags...') %>" />
|
<input class="form-control ui-use-tags" placeholder="<%= __('Select tags...') %>" />
|
||||||
|
|
Loading…
Reference in a new issue