daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 223 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const nodemailer = require("nodemailer");
  2. const express = require("express");
  3. const router = express.Router();
  4.  
  5. /* GET home page. */
  6. router.get("/", (req, res, next) => {
  7.   res.render("index", { title: "Express" });
  8. });
  9.  
  10. router.get("/forms-:id(\\d+)", (req, res, next) => {
  11.   console.log(`GET`, `ID ${req.params.id}`, `QUERY: ${req.query.level}`);
  12.   console.log();
  13.   res.end();
  14. });
  15.  
  16. router.post("/forms-:id(\\d+)", (req, res, next) => {
  17.   console.log(`POST`, `ID ${req.params.id}`, `POST: ${req.body.user}`);
  18.   res.end();
  19. });
  20.  
  21. // middlewares
  22. router.get(
  23.   "/superMiddleware",
  24.   (req, res, next) => {
  25.     console.log("Hello Middleware");
  26.     next();
  27.   },
  28.   (req, res, next) => {
  29.     res.send("hello word");
  30.   }
  31. );
  32.  
  33. router.get("/coucou-pug", (req, res, next) => {
  34.   res.render("coucou", { sayHello: "Hello buddy" });
  35. });
  36.  
  37. // Sessions
  38. router.get("/session-in", (req, res, next) => {
  39.   req.session.song = "be bop a lula";
  40.   res.send("Saving variable in session");
  41. });
  42.  
  43. router.get("/session-out", (req, res, next) => {
  44.   res.send(`Variable : ${req.session.song}`);
  45. });
  46.  
  47. router.get("/askForCookiesRecipe", (req, res) => {
  48.   const transport = nodemailer.createTransport({
  49.     host: "smtp.mailtrap.io",
  50.     port: 2525,
  51.     auth: {
  52.       user: "****",
  53.       pass: "****",
  54.     }
  55.   });
  56.  
  57.   transport.verify(function(error, success) {
  58.     if (error) {
  59.       console.log(error);
  60.     } else {
  61.       console.log("Le serveur est prêt à envoyer des emails.");
  62.     }
  63.   });
  64.  
  65.   transport.sendMail(
  66.     {
  67.       from: "Yann <yann@wild.com>", // Expediteur
  68.       to: "supergrandma@yopmail.com", // Destinataires
  69.       subject: "Coucou Mamie !", // Sujet
  70.       text:
  71.         "Comment vas tu ? Serai-t-il possible d'avoir ta super recette de cookies ?", // plaintext body
  72.       html:
  73.         "<b>Comment vas tu ? Serai-t-il possible d'avoir ta super recette de cookies ?</b>" // html body
  74.     },
  75.     (error, response) => {
  76.       if (error) {
  77.         console.log(error);
  78.       } else {
  79.         console.log("Message envoyé");
  80.       }
  81.     }
  82.   );
  83.   res.end();
  84. });
  85.  
  86. module.exports = router;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top