Guest User

Untitled

a guest
Apr 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const checkName = (req, res, next) => {
  2. if (!req.query.nome || !req.query.nome.trim().length) {
  3. res.redirect('/');
  4. } else {
  5. next();
  6. }
  7. };
  8.  
  9. app.get('/', (req, res) => {
  10. res.render('main');
  11. });
  12.  
  13. app.post('/check', (req, res) => {
  14. if (!req.body.dataNascimento || !req.body.nome) {
  15. res.redirect('/');
  16. }
  17.  
  18. const data = moment(req.body.dataNascimento, 'DD/MM/YYYY');
  19. const idade = moment().diff(data, 'years');
  20.  
  21. if (idade >= 18) {
  22. res.redirect(`/major?nome=${req.body.nome}`)
  23. } else {
  24. res.redirect(`/minor?nome=${req.body.nome}`)
  25. }
  26. });
  27.  
  28. app.get('/minor', checkName, (req, res) => {
  29. res.render('minor', { nome: req.query.nome });
  30. });
  31.  
  32. app.get('/major', checkName, (req, res) => {
  33. res.render('major', { nome: req.query.nome });
  34. });
  35.  
  36. app.listen(3000);
Add Comment
Please, Sign In to add comment