E-commerce

Mongo DB

Express.js

React.js

Node.js

Bootstrap

JW Token

Nginx

MP Checkout Pro

jQuery

Nodemailer

HTML

CSS

JavaScript


E-commerce

This was my very first project, for my family business, having the advantage of understanding the business model, I was able to model it entirely to my preference.
It took me over 4 months and I learned a lot.
In this case I used MERN stack and a few libraries which helpeded me to handle mailing suscriptions, checkouts, mongo database and also security.

The backend is not online but it is on my github repository and it's fully functional, so feel free to take a look for yourself or use it for personal purpose.

->link to frontend here. mongo

Password reset code:

app.post("/backend/forgot-password", async (req, res) => {
  try {
    const { username } = req.body;

    // Find the user based on the provided username or email
    const user = await User.findOne({ username });

    if (!user) {
      return res.status(404).json({ mensaje: "Usuario no encontrado" });
    }

    const token = jwt.sign({ userId: user._id }, process.env.JWT_SECRET, {
      expiresIn: "1h",
    });

    const source = fs.readFileSync(
      "./mail-templates/forgot-password.html",
      "utf-8"
    );

    const template = handlebars.compile(source);

    const replacements = {
      username: username,
      resetLink: `http://www.peludos.com/reset-password/${token}`,
    };

    const htmlToSend = template(replacements);

    const transporter = nodemailer.createTransport({
      service: "Gmail",
      auth: {
        user: "peludos@gmail.com",
        pass: process.env.NODE_MAILER,
      },
    });

    const mailOptions = {
      from: "peludos..@gmail.com",
      to: user.username,
      subject: "Recuperar contraseña",
      html: htmlToSend,
    };

    transporter.sendMail(mailOptions, (error, info) => {
      if (error) {
        console.log(error);
        return res
          .status(500)
          .json({ mensaje: "Error al enviar el correo electrónico" });
      }
      console.log("Email sent: " + info.response);
      res.json({ mensaje: "Correo electrónico enviado con éxito" });
    });
  } catch (error) {
    console.error(error);
    res.status(500).json({ mensaje: "Error en el servidor" });
  }
});

app.post("/backend/reset-password/:token", async (req, res) => {
  try {
    const { token } = req.params;
    const { password } = req.body;

    // Verify the token
    const decodedToken = jwt.verify(token, process.env.JWT_SECRET);
    const user = await User.findById(decodedToken.userId);

    if (!user) {
      return res.status(404).json({ mensaje: "Usuario no encontrado" });
    }

    // Set the new password for the user
    await user.setPassword(password);
    await user.save();

    res.json({ mensaje: "Contraseña cambiada exitosamente" });
  } catch (error) {
    if (error.name === "TokenExpiredError") {
      return res.status(400).json({ mensaje: "El token ha expirado" });
    }
    console.error(error);
    res.status(500).json({ mensaje: "Error en el servidor" });
  }
});

app.get("/backend/reset-password/:token", (req, res) => {
  const { token } = req.params;
  res.render("reset-password-page", { token });
});