#49 Fixed flash messages

master
Keith Irwin 2017-03-18 15:40:03 -04:00
parent d652c3ba15
commit 187797a587
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
7 changed files with 73 additions and 37 deletions

View File

@ -3,14 +3,17 @@
const router = require('express').Router(), const router = require('express').Router(),
passport = require('passport'); passport = require('passport');
// Routes
router.get('/login', function(req,res){ router.get('/login', function(req,res){
res.redirect('/auth/google'); res.redirect('/auth/google');
}); });
router.get('/logout', function(req,res){ router.get('/logout', function(req,res){
req.logout(); // Needs to clear cookies? req.logout(); // Needs to clear cookies?
req.flash('success', 'You have been logged out. ');
res.redirect('/'); res.redirect('/');
}); });
// Web app auth
router.get('/auth/google', passport.authenticate('google', { scope: [ router.get('/auth/google', passport.authenticate('google', { scope: [
'https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.profile.emails.read' 'https://www.googleapis.com/auth/plus.profile.emails.read'
@ -22,6 +25,7 @@ router.get('/auth/google/callback', passport.authenticate('google', {
successFlash: true successFlash: true
} )); } ));
// Android auth
router.get('/auth/google/idtoken', passport.authenticate('google-id-token'), function (req,res) { router.get('/auth/google/idtoken', passport.authenticate('google-id-token'), function (req,res) {
if (!req.user) { res.sendStatus(401); } if (!req.user) { res.sendStatus(401); }
else { res.send(req.user); } else { res.send(req.user); }

View File

@ -7,7 +7,7 @@ const slug = require('slug'),
router = require('express').Router(); router = require('express').Router();
// Index // Index
router.get('/', function(req,res,next){ router.get('/', function(req,res,next) {
res.render('index.html'); res.render('index.html');
}); });

View File

@ -64,18 +64,24 @@ const
/* Routes */ { /* Routes */ {
// Default locals // Static files (keep this before setting default locals)
app.get('*', function(req,res,next){ app.use('/static', express.static(__dirname+'/static'));
// User account // Set default locals (keep this after static files)
res.locals.user = req.user; app.get('/*', function(req,res,next){
// console.log(`Setting local variables for request to ${req.path}.`);
// Flash messages
res.locals.successes = req.flash('success'); // User account
res.locals.dangers = req.flash('danger'); res.locals.user = req.user;
res.locals.warnings = req.flash('warning'); // console.log(`User set as ${res.locals.user}. `);
next(); // Flash messages
res.locals.successes = req.flash('success');
res.locals.dangers = req.flash('danger');
res.locals.warnings = req.flash('warning');
// console.log(`Flash messages set as:\nSuccesses: ${res.locals.successes}\nWarnings: ${res.locals.warnings}\nDangers: ${res.locals.dangers}`);
next();
}); });
// Main routes // Main routes
@ -91,8 +97,6 @@ const
// Admin // Admin
app.use('/admin', require('./config/routes/admin.js')); app.use('/admin', require('./config/routes/admin.js'));
// Static files
app.use('/static', express.static(__dirname+'/static'));
} }
/* Errors */ { /* Errors */ {

View File

@ -64,9 +64,20 @@ input[type="checkbox"] {
display: inline-block; display: inline-block;
} }
.help-block {margin-top:-20px;} .help-block {margin-top:-20px;}
.alert { .alert {
z-index:10; z-index:10;
} }
.alert-header {
position: relative;
top: 58px;
} .alert-header.alert-danger {
z-index: 103;
} .alert-header.alert-warning {
z-index: 102;
} .alert-header.alert-success {
z-index: 101;
}
.alert:not(.alert-dismissible) { .alert:not(.alert-dismissible) {
text-align: center; text-align: center;
} }
@ -78,6 +89,7 @@ input[type="checkbox"] {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
} }
input:focus, textarea:focus { input:focus, textarea:focus {
outline: 0; outline: 0;
} }
@ -99,6 +111,15 @@ h3 { font-size: 28px; }
h4 { font-size: 20px; } h4 { font-size: 20px; }
.red { color: #fb6e3d; } .red { color: #fb6e3d; }
.shadow {
-moz-box-shadow: .18vw .18vw .36vw #000;
-webkit-box-shadow: .18vw .18vw .36vw #000;
box-shadow: .18vw .18vw .36vw #000;
} .shadow:active {
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
a { a {
color: #fbc93d; color: #fbc93d;

View File

@ -4337,7 +4337,6 @@ a.label:focus, a.label:hover {
.alert { .alert {
padding: 15px; padding: 15px;
border: 1px solid transparent; border: 1px solid transparent;
border-radius: .25rem;
} }
.alert > p, .alert > p,

View File

@ -39,13 +39,6 @@
</head> </head>
<body> <body>
<noscript>
<div class='header alert alert-danger alert-dismissible'>
<strong>Uh-oh!</strong> You don't have javascript enabled! This page won't load correctly without it. You should really enable it, because many websites won't work properly. Ask your grandchildren if you need help.
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
</div>
</noscript>
{% if not noHeader %}{% include 'templates/header.html' %}{% endif %} {% if not noHeader %}{% include 'templates/header.html' %}{% endif %}
{% block main %}Loading... {% endblock %} {% block main %}Loading... {% endblock %}
{% if not noFooter %}{% include 'templates/footer.html' %}{% endif %} {% if not noFooter %}{% include 'templates/footer.html' %}{% endif %}

View File

@ -1,12 +1,18 @@
<script src="/static/js/header.js"></script> <script src="/static/js/header.js"></script>
<header> <header class='shadow'>
<!-- Logo -->
<a href="/"><span class='logo'><img class='icon' src="/static/img/style/logo-28.png" alt="+">Tracman</span></a> <a href="/"><span class='logo'><img class='icon' src="/static/img/style/logo-28.png" alt="+">Tracman</span></a>
<!-- Hamburger -->
<div class='hamburger hamburger--slider' aria-label="Menu" aria-controls="navigation"> <div class='hamburger hamburger--slider' aria-label="Menu" aria-controls="navigation">
<div class='hamburger-box'> <div class='hamburger-box'>
<div class='hamburger-inner'></div> <div class='hamburger-inner'></div>
</div> </div>
</div> </div>
<!-- Navigation -->
<nav id='navigation'> <nav id='navigation'>
<ul> <ul>
{% if user %} {% if user %}
@ -23,22 +29,31 @@
{% endif %} {% endif %}
</ul> </ul>
</nav> </nav>
</header> </header>
<!-- Sitewide notificaton --> <!-- Flash messages -->
<!--<div class='header alert alert-warning alert-dismissible'> <noscript>
<strong>Whoops!</strong> Tracman down right now. It will be fixed in a few days. <div class='alert alert-header alert-danger alert-dismissible shadow'>
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a> <strong>Uh-oh!</strong> You don't have javascript enabled! This page won't load correctly without it. You should really enable it, because many websites won't work properly. Ask your grandchildren if you need help.
</div>--> <a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
{% if error %}
<div class='header alert alert-danger alert-dismissible'>
<strong><i class="fa fa-exclamation-circle"></i> ERROR:</strong> {{error|safe}}
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
</div> </div>
{% elif success %} </noscript>
<div class='header alert alert-success alert-dismissible'> {% for danger in dangers %}
<div class='alert alert-header alert-danger alert-dismissible shadow'>
<strong><i class="fa fa-exclamation-circle"></i> ERROR:</strong> {{ danger | safe }}
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
</div>
{% endfor %}
{% for warning in warnings %}
<div class='alert alert-header alert-warning alert-dismissible shadow'>
<strong><i class="fa fa-exclamation-circle"></i> Whoops!</strong> {{ warning | safe }}
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
</div>
{% endfor %}
{% for success in successes %}
<div class='alert alert-header alert-success alert-dismissible shadow'>
<strong><i class="fa fa-check-circle"></i> Success!</strong> {{ success | safe }} <strong><i class="fa fa-check-circle"></i> Success!</strong> {{ success | safe }}
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a> <a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
</div> </div>
{% endif %} {% endfor %}