2015-12-29 19:43:06 +00:00
|
|
|
export function ifNoUserRedirectTo(url, message, type = 'errors') {
|
2015-06-20 18:43:12 +00:00
|
|
|
return function(req, res, next) {
|
2015-10-06 07:13:51 +00:00
|
|
|
const { path } = req;
|
2015-06-20 18:43:12 +00:00
|
|
|
if (req.user) {
|
|
|
|
return next();
|
|
|
|
}
|
2015-10-06 07:13:51 +00:00
|
|
|
|
2015-12-29 19:43:06 +00:00
|
|
|
req.flash(type, {
|
2016-05-13 04:28:29 +00:00
|
|
|
msg: message || `You must be signed in to access ${path}`
|
2015-10-06 07:13:51 +00:00
|
|
|
});
|
|
|
|
|
2015-06-20 18:43:12 +00:00
|
|
|
return res.redirect(url);
|
|
|
|
};
|
2015-10-02 18:47:36 +00:00
|
|
|
}
|
2015-06-20 18:43:12 +00:00
|
|
|
|
2015-10-02 18:47:36 +00:00
|
|
|
export function ifNoUserSend(sendThis) {
|
2015-06-22 23:43:31 +00:00
|
|
|
return function(req, res, next) {
|
|
|
|
if (req.user) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return res.status(200).send(sendThis);
|
|
|
|
};
|
2015-10-02 18:47:36 +00:00
|
|
|
}
|
2015-08-19 02:48:42 +00:00
|
|
|
|
2015-10-02 18:47:36 +00:00
|
|
|
export function ifNoUser401(req, res, next) {
|
2015-08-19 02:48:42 +00:00
|
|
|
if (req.user) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return res.status(401).end();
|
2015-10-02 18:47:36 +00:00
|
|
|
}
|
2016-05-07 12:16:39 +00:00
|
|
|
|
|
|
|
export function flashIfNotVerified(req, res, next) {
|
2016-06-03 06:39:23 +00:00
|
|
|
return next();
|
|
|
|
/*
|
|
|
|
// disabled until authorized required bug is fixed
|
|
|
|
const user = req.user;
|
|
|
|
if (!user) {
|
2016-05-07 12:16:39 +00:00
|
|
|
return next();
|
2016-06-03 06:39:23 +00:00
|
|
|
}
|
|
|
|
const email = req.user.email;
|
|
|
|
const emailVerified = req.user.emailVerified;
|
|
|
|
if (!email || !emailVerified) {
|
|
|
|
req.flash('info', {
|
|
|
|
msg: 'Please verify your email address ' +
|
|
|
|
'<a href="/update-email">here</a>.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
*/
|
2016-05-07 12:16:39 +00:00
|
|
|
}
|