Fixed unauthorized /admin error

master
Keith Irwin 2017-05-08 14:00:51 -04:00
parent 9b082538c2
commit 3e2180e90f
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
3 changed files with 4 additions and 3 deletions

View File

@ -29,7 +29,7 @@ module.exports = {
// Ensure administrator
ensureAdmin: (req,res,next)=>{
if (req.user.isAdmin){ return next(); }
if (req.isAuthenticated() && req.user.isAdmin){ return next(); }
else {
let err = new Error("Unauthorized");
err.status = 401;

View File

@ -131,7 +131,7 @@ const
// Production handlers
if (env.mode!=='development') {
app.use( (err,req,res,next)=>{
if (err.status!==404){ console.error(`${err.stack}`); }
if (err.status!==404&&err.status!==401){ console.error(`${err.stack}`); }
if (res.headersSent) { return next(err); }
res.status(err.status||500);
res.render('error', {

View File

@ -1,11 +1,12 @@
{% extends 'templates/base.html' %}
{% block title %}{{super()}} | {% if code %}{{code}} {% endif %}Error{% endblock %}
{% block title %}{{super()}} | {% if code %}{{code}}{% endif %}{% if message %}: {{message}}{% else %} Error{% endif%}{% endblock %}
{% block main %}
<section class='container'>
{% if message %}<h2>❌️ {{message}}</h2>{% endif %}
{% if stack %}<p>{{stack}}</p>{% else %}
{% if code == '404' %}<p>This page does not exist. Maybe you followed a dead link here. </p>
{% elif code == '401' %}<p>You aren't allowed in here. Shoo. </p>
{% else %}<p>Would you please <a href="https://github.com/Tracman-org/Server/issues/new">report this error</a>? </p>{% endif %}
{% if code %}<img style="width:100%" src="https://http.cat/{{code}}.jpg">{% endif %}{% endif %}
</section>