Skip to content

Commit 5c7eb48

Browse files
committed
Add support of allow anonymous config option with correspond modifications
1 parent cf8bae3 commit 5c7eb48

6 files changed

Lines changed: 15 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Environment variables (will overwrite other server configs)
118118
| HMD_PROTOCOL_USESSL | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
119119
| HMD_URL_ADDPORT | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
120120
| HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) |
121+
| HMD_ALLOW_ANONMYOUS | `true` or `false` | set to allow anonmyous usage (default is `true`) |
121122
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
122123
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
123124
| HMD_TWITTER_CONSUMERKEY | no example | Twitter API consumer key |
@@ -153,6 +154,7 @@ Server settings `config.json`
153154
| protocolusessl | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
154155
| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
155156
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) |
157+
| allowanonmyous | `true` or `false` | set to allow anonmyous usage (default is `true`) |
156158
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
157159
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |
158160
| sslcertpath | `./cert/hackmd_io.crt` | ssl cert path (only need when you set usessl) |

lib/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT ===
1919

2020
var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((typeof config.usecdn === 'boolean') ? config.usecdn : true);
2121

22+
var allowanonmyous = process.env.HMD_ALLOW_ANONMYOUS ? (process.env.HMD_ALLOW_ANONMYOUS === 'true') : ((typeof config.allowanonmyous === 'boolean') ? config.allowanonmyous : true);
23+
2224
// db
2325
var db = config.db || {
2426
dialect: 'sqlite',
@@ -125,6 +127,7 @@ module.exports = {
125127
usessl: usessl,
126128
serverurl: getserverurl(),
127129
usecdn: usecdn,
130+
allowanonmyous: allowanonmyous,
128131
db: db,
129132
sslkeypath: path.join(cwd, sslkeypath),
130133
sslcertpath: path.join(cwd, sslcertpath),

lib/realtime.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ function connection(socket) {
763763
var note = notes[noteId];
764764
//Only owner can change permission
765765
if (note.owner && note.owner == socket.request.user.id) {
766+
if (permission == 'freely' && !config.allowanonmyous) return;
766767
note.permission = permission;
767768
models.Note.update({
768769
permission: permission

lib/response.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function showIndex(req, res, next) {
6060
res.render(config.indexpath, {
6161
url: config.serverurl,
6262
useCDN: config.usecdn,
63+
allowAnonmyous: config.allowanonmyous,
6364
facebook: config.facebook,
6465
twitter: config.twitter,
6566
github: config.github,
@@ -92,6 +93,7 @@ function responseHackMD(res, note) {
9293
url: config.serverurl,
9394
title: title,
9495
useCDN: config.usecdn,
96+
allowAnonmyous: config.allowanonmyous,
9597
facebook: config.facebook,
9698
twitter: config.twitter,
9799
github: config.github,
@@ -106,6 +108,8 @@ function newNote(req, res, next) {
106108
var owner = null;
107109
if (req.isAuthenticated()) {
108110
owner = req.user.id;
111+
} else if (!config.allowanonmyous) {
112+
return response.errorForbidden(res);
109113
}
110114
models.Note.create({
111115
ownerId: owner

public/views/body.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<a id="permissionLabel" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
1616
</a>
1717
<ul class="dropdown-menu" aria-labelledby="permissionLabel">
18-
<li class="ui-permission-freely"><a><i class="fa fa-leaf fa-fw"></i> Freely - Anyone can edit</a></li>
18+
<li class="ui-permission-freely"<% if(!allowAnonmyous) { %> style="display: none;"<% } %>><a><i class="fa fa-leaf fa-fw"></i> Freely - Anyone can edit</a></li>
1919
<li class="ui-permission-editable"><a><i class="fa fa-shield fa-fw"></i> Editable - Signed people can edit</a></li>
2020
<li class="ui-permission-locked"><a><i class="fa fa-lock fa-fw"></i> Locked - Only owner can edit</a></li>
2121
<li class="ui-permission-private"><a><i class="fa fa-hand-stop-o fa-fw"></i> Private - Only owner can view &amp; edit</a></li>

public/views/index.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@
6262
<br>
6363
<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>
6464
</span>
65+
<% }%>
66+
<% if((facebook || twitter || github || gitlab || dropbox || google || email) && allowAnonmyous) { %>
6567
<span class="ui-or"><%= __('or') %></span>
6668
<% }%>
69+
<% if(allowAnonmyous) { %>
6770
<span class="ui-signin">
6871
<a href="<%- url %>/new" class="btn btn-lg btn-default" style="min-width: 170px;"><%= __('New guest note') %></a>
6972
<br>
7073
<br>
7174
</span>
75+
<% }%>
7276
<div class="lead row" style="width: 90%; margin: 0 auto;">
7377
<div class="col-md-4 inner">
7478
<a href="<%- url %>/features#share-notes">

0 commit comments

Comments
 (0)