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