Skip to content

Node.js based forum software built for the modern web

closes #679

Baris Soner Usaklif68f02d34657
diff --git a/public/templates/admin/settings.tpl b/public/templates/admin/settings.tpl
index 5d022cf19c..66343f3acb 100644
--- a/public/templates/admin/settings.tpl
+++ b/public/templates/admin/settings.tpl
@@ -77,6 +77,11 @@
<form>
<h3>User Settings</h3>
<div class="alert alert-warning">
+ <div class="checkbox">
+ <label>
+ <input type="checkbox" data-field="allowRegistration" checked> <strong>Allow registration</strong>
+ </label>
+ </div>
<strong>Minimum Username Length</strong><br />
<input type="text" class="form-control" value="2" data-field="minimumUsernameLength"><br />
<strong>Maximum Username Length</strong><br />
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 6a3418a63b..dc9d851adb 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -112,9 +112,11 @@
</ul>
<ul id="logged-out-menu" class="nav navbar-nav navbar-right">
+ <!-- IF allowRegistration -->
<li class="visible-lg visible-md visible-sm">
<a href="/register">[[global:register]]</a>
</li>
+ <!-- ENDIF allowRegistration -->
<li class="visible-lg visible-md visible-sm">
<a href="/login">[[global:login]]</a>
</li>
diff --git a/src/routes/api.js b/src/routes/api.js
index fe6589140e..c8a36b16af 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -37,6 +37,7 @@ var path = require('path'),
config.maximumSignatureLength = meta.config.maximumSignatureLength;
config.useOutgoingLinksPage = meta.config.useOutgoingLinksPage;
config.allowGuestPosting = meta.config.allowGuestPosting;
+ config.allowRegistration = meta.config.allowRegistration || '1';
config.emailSetup = !!meta.config['email:from'];
res.json(200, config);
diff --git a/src/routes/authentication.js b/src/routes/authentication.js
index 759f8f20de..c731c9952f 100644
--- a/src/routes/authentication.js
+++ b/src/routes/authentication.js
@@ -193,6 +193,10 @@
});
app.post('/register', function(req, res) {
+ if(parseInt(meta.config.allowRegistration, 10) === 0) {
+ return res.send(403);
+ }
+
user.create(req.body.username, req.body.password, req.body.email, function(err, uid) {
if (err === null && uid) {
req.login({
diff --git a/src/webserver.js b/src/webserver.js
index 86559848a9..f3ecce7ac4 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -98,7 +98,8 @@ var path = require('path'),
link_tags: linkTags,
clientScripts: clientScripts,
navigation: custom_header.navigation,
- 'cache-buster': meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : ''
+ 'cache-buster': meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '',
+ allowRegistration: parseInt(meta.config.allowRegistration, 10) === 1
};
var uid = '0';
@@ -389,6 +390,8 @@ var path = require('path'),
res.redirect('/user/' + userslug);
});
return;
+ } else if(route === 'register' && parseInt(meta.config.allowRegistration, 10) === 0) {
+ return res.redirect('/403');
} else if (loginRequired.indexOf(route) !== -1 && !req.user) {
return res.redirect('/403');
}