Skip to content

Commit

Permalink
Adding new config option that disables registration (#57)
Browse files Browse the repository at this point in the history
* Added new config option (in production sample) that disables registration. Also fixed a url on the main page

* Update index.ejs
  • Loading branch information
ryanrdetzel authored and marziman committed Apr 5, 2017
1 parent c36ee46 commit 81c258f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app.js
Expand Up @@ -40,6 +40,8 @@ if (config.gcm) {
var gcmXmpp = require('./gcm-xmpp');
}

var registration_enabled = ("registration_enabled" in config) ? config.registration_enabled : true;

module.exports.config = config;

// Setup all routes
Expand Down Expand Up @@ -324,6 +326,7 @@ app.configure(function () {
res.locals.terms = config.legal.terms;
res.locals.policy = config.legal.policy;
}
res.locals.registration_enabled = registration_enabled;
next();
});
app.use(function (req, res, next) {
Expand Down
3 changes: 2 additions & 1 deletion config-production.json
Expand Up @@ -49,5 +49,6 @@
"legal": {
"terms" : "",
"policy": ""
}
},
"registration_enabled": false
}
8 changes: 7 additions & 1 deletion routes/account.js
Expand Up @@ -321,7 +321,13 @@ exports.registerpostvalidate = form(
);

exports.registerpost = function(req, res) {
if (!req.form.isValid) {
var registration_enabled = ("registration_enabled" in app.config) ? app.config.registration_enabled : true;

if (!registration_enabled) {
req.flash('error', "Registration is currently disabled.");
res.render('login', { title: "Login / Sign up", user: req.user,
errormessages:req.flash('error'), infomessages:req.flash('info') });
} else if (!req.form.isValid) {
res.render('login', { title: "Login / Sign up", user: req.user,
errormessages:req.flash('error'), infomessages:req.flash('info') });
} else {
Expand Down
7 changes: 5 additions & 2 deletions views/index.ejs
Expand Up @@ -20,10 +20,11 @@
<h3>Registered users, please log in.</h3>
<div class="divider"><span></span></div>
</div>
<% if (registration_enabled) { %>
<div class="span4">
<h3>If you are a new user, please register.</h3>
<div class="divider"><span></span></div>
</div>
</div> <% } %>
</div>
<div class="row">
<div class="span2"></div>
Expand All @@ -41,6 +42,7 @@
<div id="message"></div>
</div>
<div class="span4">
<% if (registration_enabled) { %>
<% if (terms && policy) { %>
<form method="post" action="/register" id="contactform">
<input type="hidden" name="_csrf" value="<%= token %>" class="form-control">
Expand Down Expand Up @@ -72,6 +74,7 @@
<button name="submit" type="submit" class="btn" id="submit">Register</button>
</form>
<% } %>
<% } %>
<div id="message"></div>
</div>
</div>
Expand Down Expand Up @@ -122,4 +125,4 @@
</section>
<% } %>
</div>
<%- include footer.ejs %>
<%- include footer.ejs %>
4 changes: 4 additions & 0 deletions views/login.ejs
Expand Up @@ -19,10 +19,12 @@
<h3>Registered users, please log in.</h3>
<div class="divider"><span></span></div>
</div>
<% if (registration_enabled) {%>
<div class="span4">
<h3>If you are a new user, please register.</h3>
<div class="divider"><span></span></div>
</div>
<% } %>
</div>
<div class="row">
<div class="span2"></div>
Expand All @@ -40,6 +42,7 @@
<div id="message"></div>
</div>
<div class="span4">
<% if (registration_enabled) {%>
<% if (terms && policy) { %>
<form method="post" action="/register" id="contactform">
<input type="hidden" name="_csrf" value="<%= token %>" class="form-control">
Expand Down Expand Up @@ -71,6 +74,7 @@
<button name="submit" type="submit" class="btn" id="submit">Register</button>
</form>
<% } %>
<% } %>
<div id="message"></div>
</div>
</div>
Expand Down

0 comments on commit 81c258f

Please sign in to comment.