#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(),
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); }

View File

@ -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');
});

View File

@ -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 */ {

View File

@ -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;

View File

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

View File

@ -39,13 +39,6 @@
</head>
<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 %}
{% block main %}Loading... {% endblock %}
{% if not noFooter %}{% include 'templates/footer.html' %}{% endif %}

View File

@ -1,12 +1,18 @@
<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>
<!-- Hamburger -->
<div class='hamburger hamburger--slider' aria-label="Menu" aria-controls="navigation">
<div class='hamburger-box'>
<div class='hamburger-inner'></div>
</div>
</div>
<!-- Navigation -->
<nav id='navigation'>
<ul>
{% if user %}
@ -23,22 +29,31 @@
{% endif %}
</ul>
</nav>
</header>
<!-- Sitewide notificaton -->
<!--<div class='header alert alert-warning alert-dismissible'>
<strong>Whoops!</strong> Tracman down right now. It will be fixed in a few days.
<a href="#" class='close' data-dismiss="alert" aria-label="close"><i class='fa fa-times'></i></a>
</div>-->
{% 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>
<!-- Flash messages -->
<noscript>
<div class='alert alert-header alert-danger alert-dismissible shadow'>
<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>
{% elif success %}
<div class='header alert alert-success alert-dismissible'>
</noscript>
{% 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 }}
<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>
{% endif %}
{% endfor %}