Add redirect to user page on submit

This commit is contained in:
Berkeley Martinez
2015-10-06 00:13:51 -07:00
parent d1c0276f4e
commit bc6a9c6db2
5 changed files with 79 additions and 12 deletions

View File

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