Guest User

Untitled

a guest
Apr 30th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. //LES ROUTES DES SESSIONS SONT TOUT EN BAS//
  2.  
  3.  
  4. const express = require('express');
  5. const router = express.Router();
  6. const nodemailer = require("nodemailer");
  7. const app = express()
  8. const smtpTransport = nodemailer.createTransport({
  9. service: "Gmail",
  10. auth: {
  11. user: "XXX",
  12. pass: "XXX"
  13. }
  14. });
  15.  
  16.  
  17. /* GET home page. */
  18. router.get('/', function(req, res, next) {
  19. res.render('index', { title: 'Express' });
  20. });
  21.  
  22. /* GET form page. */
  23. router.get('/forms-:numeroForm(\\d+)', function(req, res, next) {
  24. res.render('index', { title: req.params.numeroForm});
  25. console.log(req.params.numeroForm)
  26. console.log(req.query.level);
  27. });
  28.  
  29. /* POST form page. */
  30. router.post('/forms-:numeroForm(\\d+)', function(req, res, next) {
  31. res.render('index', { title: req.body.username});
  32. console.log(req.body.username);
  33. });
  34.  
  35.  
  36. /* GET superMiddleware page with a Middleware */
  37. router.get('/superMiddleware', function(req, res, next) {
  38. console.log('hello middleware !!!!!!! Welcome in my code !!!!!');
  39. next();
  40. }, function (req, res, next) {
  41. res.render('index', { title: 'Hello the world!!!!!'});
  42. });
  43.  
  44. /* GET ASKCOOKIES. */
  45. router.get('/askForCookiesRecipe', function(req, res, next) {
  46.  
  47. smtpTransport.sendMail({
  48. from: "XXX <XXX>", // Expediteur
  49. to: "XXX", // Destinataires
  50. subject: "Hello grandma, I need a favor", // Sujet
  51. text: "Hello grandma, hope you are well. I need your cookies recipe. Thank you grandma, see you soon.", // plaintext body
  52. html: "<b>Hello grandma, hope you are well. I need your cookies recipe. Thank you grandma, see you soon.</b>" // html body
  53. }, (error, response) => {
  54. if(error){
  55. console.log(error);
  56. }else{
  57. console.log("Message sent: " + response.message);
  58. }
  59. })
  60. });
  61.  
  62. //**************ROUTE SESSION*****************//
  63.  
  64. router.get('/session-in', function(req, res, next) {
  65. req.session.song = 'Be bop a lula'
  66. res.end()
  67. })
  68.  
  69. router.get('/session-out', function(req, res, next) {
  70. res.setHeader('Content-Type', 'text/html')
  71. res.write('<p>' + req.session.song + '</p>')
  72. req.session.destroy(function(err) {
  73. })
  74. res.end()
  75. })
  76.  
  77. module.exports = router;
Add Comment
Please, Sign In to add comment