Skip to content

Commit 4bbe035

Browse files
committed
Merge branch 'master' into frontend-next
2 parents a9a38c3 + 1de4242 commit 4bbe035

8 files changed

Lines changed: 95 additions & 59 deletions

File tree

app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ process.on('uncaughtException', function (err) {
626626
process.exit(1);
627627
});
628628

629-
// gracefully exit
630-
process.on('SIGINT', function () {
629+
// install exit handler
630+
function handleTermSignals() {
631631
config.maintenance = true;
632632
// disconnect all socket.io clients
633633
Object.keys(io.sockets.sockets).forEach(function (key) {
@@ -649,4 +649,6 @@ process.on('SIGINT', function () {
649649
});
650650
}
651651
}, 100);
652-
});
652+
}
653+
process.on('SIGINT', handleTermSignals);
654+
process.on('SIGTERM', handleTermSignals);

lib/realtime.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,22 @@ function interruptConnection(socket, note, user) {
363363
connectNextSocket();
364364
}
365365

366+
function checkViewPermission(req, note) {
367+
if (note.permission == 'private') {
368+
if (req.user && req.user.logged_in && req.user.id == note.owner)
369+
return true;
370+
else
371+
return false;
372+
} else if (note.permission == 'limited' || note.permission == 'protected') {
373+
if(req.user && req.user.logged_in)
374+
return true;
375+
else
376+
return false;
377+
} else {
378+
return true;
379+
}
380+
}
381+
366382
var isConnectionBusy = false;
367383
var connectionSocketQueue = [];
368384
var isDisconnectBusy = false;
@@ -373,14 +389,10 @@ function finishConnection(socket, note, user) {
373389
if (!socket || !note || !user) {
374390
return interruptConnection(socket, note, user);
375391
}
376-
//check view permission
377-
if (note.permission == 'limited' || note.permission == 'protected' || note.permission == 'private') {
378-
if (socket.request.user && socket.request.user.logged_in && socket.request.user.id == note.owner) {
379-
//na
380-
} else {
381-
interruptConnection(socket, note, user);
382-
return failConnection(403, 'connection forbidden', socket);
383-
}
392+
// check view permission
393+
if (!checkViewPermission(socket.request, note)) {
394+
interruptConnection(socket, note, user);
395+
return failConnection(403, 'connection forbidden', socket);
384396
}
385397
// update user color to author color
386398
if (note.authors[user.userid]) {
@@ -789,18 +801,14 @@ function connection(socket) {
789801
for (var i = 0, l = note.socks.length; i < l; i++) {
790802
var sock = note.socks[i];
791803
if (typeof sock !== 'undefined' && sock) {
792-
//check view permission
793-
if (permission == 'limited' || permission == 'protected' || permission == 'private') {
794-
if (sock.request.user && sock.request.user.logged_in && sock.request.user.id == note.owner) {
795-
//na
796-
} else {
797-
sock.emit('info', {
798-
code: 403
799-
});
800-
setTimeout(function () {
801-
sock.disconnect(true);
802-
}, 0);
803-
}
804+
// check view permission
805+
if (!checkViewPermission(sock.request, note)) {
806+
sock.emit('info', {
807+
code: 403
808+
});
809+
setTimeout(function () {
810+
sock.disconnect(true);
811+
}, 0);
804812
}
805813
}
806814
}

lib/response.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function responseHackMD(res, note) {
9797
dropbox: config.dropbox,
9898
google: config.google,
9999
ldap: config.ldap,
100-
email: config.email
100+
email: config.email,
101+
allowemailregister: config.allowemailregister
101102
});
102103
}
103104

@@ -126,10 +127,10 @@ function checkViewPermission(req, note) {
126127
else
127128
return true;
128129
} else if (note.permission == 'limited' || note.permission == 'protected') {
129-
if( !req.isAuthenticated() ) {
130+
if(!req.isAuthenticated())
130131
return false;
131-
}
132-
return true;
132+
else
133+
return true;
133134
} else {
134135
return true;
135136
}

public/css/cover.css

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ body {
7878
margin-top: 10px;
7979
margin-bottom: 10px;
8080
}
81+
.masthead-nav {
82+
text-align: left;
83+
max-width: 1000px;
84+
margin: 0 auto;
85+
padding-left: 10px;
86+
padding-right: 10px;
87+
}
8188
.masthead-nav > li {
8289
display: inline-block;
8390
}
@@ -263,9 +270,14 @@ input {
263270
text-decoration: underline;
264271
}
265272
.ui-avatar {
266-
border-radius: 15em;
267-
height: auto;
268-
width: 60px;
273+
display: inline-block;
274+
overflow: hidden;
275+
line-height: 1;
276+
vertical-align: middle;
277+
border-radius: 3px;
278+
}
279+
.ui-avatar.circle {
280+
border-radius: 50%;
269281
}
270282
.ui-history-close {
271283
position: absolute;
@@ -338,6 +350,10 @@ input {
338350
display: inline-block !important;
339351
}
340352

353+
.btn-link, .btn-link:hover, .btn-link:focus, .btn-link:active {
354+
color: white;
355+
}
356+
341357
select {
342358
color: black;
343359
}

public/js/cover.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ $(".masthead-nav li").click(function () {
102102
$(this).addClass("active");
103103
});
104104

105-
$(".ui-home").click(() => {
105+
// prevent empty link change hash
106+
$('a[href="#"]').click(function (e) {
107+
e.preventDefault();
108+
});
109+
110+
$(".ui-home").click(function (e) {
106111
if (!$("#home").is(':visible')) {
107112
$(".section:visible").hide();
108113
$("#home").fadeIn();
@@ -366,7 +371,7 @@ $(".ui-refresh-history").click(() => {
366371
$('.search').val('');
367372
historyList.search();
368373
$('#history-list').slideUp('fast');
369-
$('.pagination').slideUp('fast');
374+
$('.pagination').hide();
370375

371376
resetCheckAuth();
372377
historyList.clear();
@@ -378,7 +383,6 @@ $(".ui-refresh-history").click(() => {
378383
$('.search').val(lastKeyword);
379384
checkHistoryList();
380385
$('#history-list').slideDown('fast');
381-
$('.pagination').slideDown('fast');
382386
});
383387
});
384388

public/js/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,10 @@ ui.toolbar.uploadImage.bind('change', function (e) {
17611761
ui.toc.dropdown.click(function (e) {
17621762
e.stopPropagation();
17631763
});
1764+
// prevent empty link change hash
1765+
$('a[href="#"]').click(function (e) {
1766+
e.preventDefault();
1767+
});
17641768

17651769
//modal actions
17661770
var revisions = [];

public/js/lib/common/login.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let checkAuth = false;
44
let profile = null;
55
let lastLoginState = getLoginState();
66
let lastUserId = getUserId();
7-
let loginStateChangeEvent = null;
7+
var loginStateChangeEvent = null;
88

99
export function setloginStateChangeEvent(func) {
1010
loginStateChangeEvent = func;
@@ -32,9 +32,7 @@ export function setLoginState(bool, id) {
3232

3333
export function checkLoginStateChanged() {
3434
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
35-
if (loginStateChangeEvent) {
36-
loginStateChangeEvent();
37-
}
35+
if (loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100);
3836
return true;
3937
} else {
4038
return false;
@@ -56,8 +54,7 @@ export function clearLoginState() {
5654

5755
export function checkIfAuth(yesCallback, noCallback) {
5856
const cookieLoginState = getLoginState();
59-
if (checkLoginStateChanged())
60-
checkAuth = false;
57+
if (checkLoginStateChanged()) checkAuth = false;
6158
if (!checkAuth || typeof cookieLoginState == 'undefined') {
6259
$.get(`${serverurl}/me`)
6360
.done(data => {

public/views/index.ejs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@
4141
</li>
4242
<li class="ui-history<% if(signin) { %> active<% } %>"><a href="#"><%= __('History') %></a>
4343
</li>
44+
<div class="ui-signin" style="float: right; margin-top: 8px;<% if(signin) { %> display: none;<% } %>">
45+
<% if(allowAnonymous) { %>
46+
<a type="button" href="<%- url %>/new" class="btn btn-sm btn-link"><i class="fa fa-plus"></i> <%= __('New guest note') %></a>
47+
<% } %>
48+
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
49+
<button class="btn btn-sm btn-success ui-signin" data-toggle="modal" data-target=".signin-modal"><%= __('Sign In') %></button>
50+
<% } %>
51+
</div>
52+
<div class="ui-signout" style="float: right; margin-top: 8px;<% if(!signin) { %> display: none;<% } %>">
53+
<a type="button" href="<%- url %>/new" class="btn btn-sm btn-link"><i class="fa fa-plus"></i> <%= __('New note') %></a>
54+
<span class="ui-profile dropdown pull-right">
55+
<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">
56+
<img class="ui-avatar" width="20" height="20"><span class="hidden-xs hidden-sm">&ensp;<span class="ui-name"></span></span>&ensp;<i class="fa fa-caret-down"></i>
57+
</button>
58+
<ul class="dropdown-menu" aria-labelledby="profileLabel">
59+
<li><a href="<%- url %>/logout"><i class="fa fa-sign-out fa-fw"></i> <%= __('Sign Out') %></a></li>
60+
</ul>
61+
</span>
62+
</div>
4463
</ul>
4564
</nav>
4665
</div>
@@ -61,19 +80,15 @@
6180
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
6281
<span class="ui-signin">
6382
<br>
64-
<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>
83+
<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>
6584
</span>
66-
<% }%>
67-
<% if((facebook || twitter || github || gitlab || dropbox || google || email) && allowAnonymous) { %>
6885
<span class="ui-or"><%= __('or') %></span>
69-
<% }%>
70-
<% if(allowAnonymous) { %>
86+
<% } %>
7187
<span class="ui-signin">
72-
<a href="<%- url %>/new" class="btn btn-lg btn-default" style="min-width: 170px;"><%= __('New guest note') %></a>
88+
<a type="button" href="<%- url %>/features" class="btn btn-lg btn-primary" style="min-width: 200px;"><%= __('Explore all features') %></a>
7389
<br>
7490
<br>
7591
</span>
76-
<% }%>
7792
<div class="lead row" style="width: 90%; margin: 0 auto;">
7893
<div class="col-md-4 inner">
7994
<a href="<%- url %>/features#share-notes">
@@ -98,21 +113,10 @@
98113
</div>
99114

100115
<div id="history" class="section"<% if(!signin) { %> style="display:none;"<% } %>>
101-
<% if(facebook || twitter || github || gitlab || dropbox || google || ldap || email) { %>
102-
<div class="ui-signin">
116+
<div class="ui-signin"<% if(signin) { %> style="display:none;"<% } %>>
103117
<p><%= __('Below is the history from browser') %></p>
104118
</div>
105-
<div class="ui-signout" style="display:none;">
106-
<img class="ui-avatar">
107-
<h4 class="ui-welcome"><%= __('Welcome!') %> <span class="ui-name"></span></h4>
108-
<a href="<%- url %>/new" class="btn btn-md btn-default"><%= __('New note') %></a> <%= __('or') %>
109-
<a href="#" class="btn btn-danger ui-logout"><%= __('Sign Out') %></a>
110-
</div>
111-
<% }%>
112-
<h4>
113-
<a type="button" href="<%- url %>/features" class="btn btn-primary"><%= __('Explore all features') %></a>
114-
</h4>
115-
<hr>
119+
<br>
116120
<form class="form-inline">
117121
<div class="form-group" style="vertical-align: bottom;">
118122
<input class="form-control ui-use-tags" placeholder="<%= __('Select tags...') %>" />

0 commit comments

Comments
 (0)