Fix commit redirect for non signed user.
Now users will be directed to sign in page and on sign in will have pledge completed
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { Observable } from 'rx';
|
||||
import uuid from 'node-uuid';
|
||||
import moment from 'moment';
|
||||
import dedent from 'dedent';
|
||||
import debugFactory from 'debug';
|
||||
|
||||
import { saveUser, observeMethod } from '../../server/utils/rx';
|
||||
@ -91,9 +92,10 @@ module.exports = function(User) {
|
||||
}
|
||||
|
||||
req.flash('error', {
|
||||
msg:
|
||||
`The ${req.body.email} email address is already associated with an account.
|
||||
Try signing in with it here instead.`
|
||||
msg: dedent`
|
||||
The ${req.body.email} email address is already associated with an account.
|
||||
Try signing in with it here instead.
|
||||
`
|
||||
});
|
||||
|
||||
return res.redirect('/email-signin');
|
||||
@ -171,10 +173,14 @@ module.exports = function(User) {
|
||||
}
|
||||
|
||||
return req.logIn({ id: accessToken.userId.toString() }, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (err) { return next(err); }
|
||||
|
||||
debug('user logged in');
|
||||
|
||||
if (req.session && req.session.returnTo) {
|
||||
return res.redirect(req.session.returnTo);
|
||||
}
|
||||
|
||||
req.flash('success', { msg: 'Success! You are logged in.' });
|
||||
return res.redirect('/');
|
||||
});
|
||||
|
@ -22,11 +22,16 @@ import {
|
||||
ifNoUserRedirectTo
|
||||
} from '../utils/middleware';
|
||||
|
||||
const sendNonUserToFront = ifNoUserRedirectTo('/');
|
||||
const sendNonUserToSignIn = ifNoUserRedirectTo(
|
||||
'/login',
|
||||
'You must be signed in to commit to a non-profit'
|
||||
);
|
||||
|
||||
const sendNonUserToCommit = ifNoUserRedirectTo(
|
||||
'/commit',
|
||||
'Must be signed in to update commit'
|
||||
'You must be signed in to update commit'
|
||||
);
|
||||
|
||||
const debug = debugFactory('freecc:commit');
|
||||
|
||||
function findNonprofit(name) {
|
||||
@ -52,7 +57,7 @@ export default function commit(app) {
|
||||
|
||||
router.get(
|
||||
'/commit/pledge',
|
||||
sendNonUserToFront,
|
||||
sendNonUserToSignIn,
|
||||
pledge
|
||||
);
|
||||
|
||||
|
@ -16,7 +16,8 @@ const pathsWhiteList = [
|
||||
'news',
|
||||
'challenges',
|
||||
'map',
|
||||
'news'
|
||||
'news',
|
||||
'commit'
|
||||
];
|
||||
|
||||
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
|
||||
@ -35,7 +36,7 @@ export default function addReturnToUrl() {
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
req.session.returnTo = req.path;
|
||||
req.session.returnTo = req.originalUrl;
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user