From 187797a5874e8deb2066da39c2faf2b6fcf4fcd4 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Sat, 18 Mar 2017 15:40:03 -0400 Subject: [PATCH] #49 Fixed flash messages --- config/routes/auth.js | 4 ++++ config/routes/index.js | 2 +- server.js | 30 ++++++++++++++----------- static/css/base.css | 21 +++++++++++++++++ static/css/bootstrap.css | 1 - views/templates/base.html | 7 ------ views/templates/header.html | 45 ++++++++++++++++++++++++------------- 7 files changed, 73 insertions(+), 37 deletions(-) diff --git a/config/routes/auth.js b/config/routes/auth.js index 72fd4f6..1d1c587 100644 --- a/config/routes/auth.js +++ b/config/routes/auth.js @@ -3,14 +3,17 @@ const router = require('express').Router(), passport = require('passport'); +// Routes router.get('/login', function(req,res){ res.redirect('/auth/google'); }); router.get('/logout', function(req,res){ req.logout(); // Needs to clear cookies? + req.flash('success', 'You have been logged out. '); res.redirect('/'); }); +// Web app auth router.get('/auth/google', passport.authenticate('google', { scope: [ 'https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/plus.profile.emails.read' @@ -22,6 +25,7 @@ router.get('/auth/google/callback', passport.authenticate('google', { successFlash: true } )); +// Android auth router.get('/auth/google/idtoken', passport.authenticate('google-id-token'), function (req,res) { if (!req.user) { res.sendStatus(401); } else { res.send(req.user); } diff --git a/config/routes/index.js b/config/routes/index.js index 8648731..2f57ccb 100644 --- a/config/routes/index.js +++ b/config/routes/index.js @@ -7,7 +7,7 @@ const slug = require('slug'), router = require('express').Router(); // Index -router.get('/', function(req,res,next){ +router.get('/', function(req,res,next) { res.render('index.html'); }); diff --git a/server.js b/server.js index 5bd0ea0..19cc182 100755 --- a/server.js +++ b/server.js @@ -64,18 +64,24 @@ const /* Routes */ { - // Default locals - app.get('*', function(req,res,next){ + // Static files (keep this before setting default locals) + app.use('/static', express.static(__dirname+'/static')); - // User account - res.locals.user = req.user; - - // Flash messages - res.locals.successes = req.flash('success'); - res.locals.dangers = req.flash('danger'); - res.locals.warnings = req.flash('warning'); - - next(); + // Set default locals (keep this after static files) + app.get('/*', function(req,res,next){ + // console.log(`Setting local variables for request to ${req.path}.`); + + // User account + res.locals.user = req.user; + // console.log(`User set as ${res.locals.user}. `); + + // 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 @@ -91,8 +97,6 @@ const // Admin app.use('/admin', require('./config/routes/admin.js')); - // Static files - app.use('/static', express.static(__dirname+'/static')); } /* Errors */ { diff --git a/static/css/base.css b/static/css/base.css index e06b8c5..e436145 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -64,9 +64,20 @@ input[type="checkbox"] { display: inline-block; } .help-block {margin-top:-20px;} + .alert { 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) { text-align: center; } @@ -78,6 +89,7 @@ input[type="checkbox"] { color: inherit; text-decoration: none; } + input:focus, textarea:focus { outline: 0; } @@ -99,6 +111,15 @@ h3 { font-size: 28px; } h4 { font-size: 20px; } .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 { color: #fbc93d; diff --git a/static/css/bootstrap.css b/static/css/bootstrap.css index 8875db2..ddad873 100644 --- a/static/css/bootstrap.css +++ b/static/css/bootstrap.css @@ -4337,7 +4337,6 @@ a.label:focus, a.label:hover { .alert { padding: 15px; border: 1px solid transparent; - border-radius: .25rem; } .alert > p, diff --git a/views/templates/base.html b/views/templates/base.html index f42d6ab..3e8f4ee 100644 --- a/views/templates/base.html +++ b/views/templates/base.html @@ -39,13 +39,6 @@ - - {% if not noHeader %}{% include 'templates/header.html' %}{% endif %} {% block main %}Loading... {% endblock %} {% if not noFooter %}{% include 'templates/footer.html' %}{% endif %} diff --git a/views/templates/header.html b/views/templates/header.html index c89238d..5de9750 100644 --- a/views/templates/header.html +++ b/views/templates/header.html @@ -1,12 +1,18 @@ -
+
+ + + +
+ + +
- - - -{% if error %} -
- ERROR: {{error|safe}} - + +