Add redirect to user page on submit
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
import dedent from 'dedent';
|
||||
import {
|
||||
ifNoUserRedirectTo
|
||||
} from '../utils/middleware';
|
||||
|
||||
const sendNonUserToFront = ifNoUserRedirectTo('/');
|
||||
|
||||
export default function commit(app) {
|
||||
const router = app.loopback.Router();
|
||||
router.get(
|
||||
'/commit',
|
||||
commitToNonprofit
|
||||
);
|
||||
router.get(
|
||||
'/commit/pledge',
|
||||
sendNonUserToFront,
|
||||
pledge
|
||||
);
|
||||
|
||||
app.use(router);
|
||||
|
||||
@@ -12,4 +24,23 @@ export default function commit(app) {
|
||||
title: 'Commit to a nonprofit. Commit to your goal.'
|
||||
});
|
||||
}
|
||||
|
||||
function pledge(req, res) {
|
||||
const { user } = req;
|
||||
const {
|
||||
nonprofit = 'girl develop it',
|
||||
amount = '5',
|
||||
goal = 'front end certification'
|
||||
} = req.query;
|
||||
|
||||
req.flash('success', {
|
||||
msg: dedent`
|
||||
Congratulations, you have commit to giving ${nonprofit} ${amount}
|
||||
dollars a month until you have reached your goal
|
||||
of completing your ${goal}
|
||||
`
|
||||
});
|
||||
|
||||
res.redirect('/' + user.username);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user