-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/c3' into nicolas
- Loading branch information
Showing
16 changed files
with
146 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ package-lock.json | |
.vscode | ||
.personal | ||
/storage/img/* | ||
!/storage/img/user.webp | ||
!/storage/img/user.webp | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,18 @@ import * as express from "express"; | |
import * as bcrypt from "bcrypt"; | ||
import multer from "multer"; | ||
import path from "path" | ||
const storage = multer.diskStorage({ | ||
destination: function (req, file, cb) { | ||
cb(null, './storage/img') | ||
}, | ||
filename: function (req, file, cb) { | ||
cb(null, "imagenPerfil-" + req.session.usuario.DNI+".jpg") | ||
}, | ||
|
||
}) | ||
var upload = multer({storage:storage, | ||
import nodemailer from "nodemailer"; | ||
|
||
const upload = multer({ | ||
storage:multer.diskStorage({ | ||
destination: function (req, file, cb) { | ||
cb(null, './storage/img') | ||
}, | ||
filename: function (req, file, cb) { | ||
cb(null, "imagenPerfil-" + req.session.usuario.DNI+".jpg") | ||
}, | ||
|
||
}), | ||
fileFilter: function(req, file, cb){ | ||
const allowedExtensions = ['.jpg', '.png']; // Add more extensions as needed | ||
const fileExtension = path.extname(file.originalname).toLowerCase(); | ||
|
@@ -20,7 +22,8 @@ var upload = multer({storage:storage, | |
} else { | ||
cb(null, false); // Reject the file | ||
} | ||
}}) | ||
} | ||
}) | ||
const router = express.Router(); | ||
import { | ||
Usuario, | ||
|
@@ -64,6 +67,8 @@ Parametro.findAll().then((ps) => { | |
}); | ||
}); | ||
|
||
// TODO Refactor: Separar este archivo de más de 2k líneas de código en diferentes archivos segpun la entidad accedida. Ejemplo: https://github.com/c3r38r170/tp-fullstack/blob/master/backend/rutas/todas.js | ||
|
||
// sesiones | ||
|
||
router.post("/sesion", function (req, res) { | ||
|
@@ -327,11 +332,31 @@ router.post("/usuario/:DNI/contrasenia", function (req, res) { | |
res.status(404).send("DNI inexistente"); | ||
return; | ||
} | ||
|
||
let contraseniaNueva = generarContrasenia(); | ||
usu.contrasenia = contraseniaNueva; | ||
|
||
//TODO Feature: mandar mail | ||
usu.save().then(res.status(200).send("DNI encontrado, correo enviado")); | ||
Promise.all([ | ||
nodemailer | ||
.createTransport({ | ||
host: process.env.CORREO_HOST, | ||
port: process.env.CORREO_PORT, | ||
secure: true, // Use `true` for port 465, `false` for all other ports | ||
auth: { | ||
user: process.env.CORREO_USER, | ||
pass: process.env.CORREO_PASS, | ||
}, | ||
}) | ||
.sendMail({ | ||
from: '"UTN FAQ - Recuperación de contraseña" <[email protected]>', // sender address | ||
to: usu.correo, // list of receivers | ||
subject: "UTN FAQ - Recuperación de contraseña", // Subject line | ||
text: `¡Saludos, ${usu.nombre}! Tu contraseña temporal es "${contraseniaNueva}" (sin comillas).`, // plain text body | ||
html: `<big>¡Saludos, ${usu.nombre}!</big><br/><p>Se ha reestablecido tu contraseña, tu nueva contraseña temporal es:</p><pre>${contraseniaNueva}}</pre><p>No olvides cambiarla por otra / personalizarla cuando entres.</p><p><a href=${process.env.DIRECCION}>¡Te esperamos!</a></p>`, // html body | ||
}) | ||
,usu.save() | ||
]) | ||
.then(res.status(200).send("Se ha reestablecido la contraseña. Revise su correo electrónico para poder acceder.")); | ||
}); | ||
}); | ||
|
||
|
@@ -474,13 +499,14 @@ router.patch("/usuario", upload.single("image"), function (req, res) { | |
} | ||
Usuario.findByPk(req.session.usuario.DNI) | ||
.then((usuario) => { | ||
if(bcrypt.compare(req.body.contraseniaAnterior, usuario.contrasenia)){ | ||
usuario.contrasenia = req.body.contraseniaNueva; | ||
usuario.save(); | ||
res.status(200).send("Datos actualizados exitosamente"); | ||
if(!bcrypt.compare(req.body.contraseniaAnterior, usuario.contrasenia)){ | ||
res.status(401).send("Contraseña anterior no válida") | ||
return; | ||
} | ||
res.status(402).send("Contraseña anterior no válida") | ||
|
||
usuario.contrasenia = req.body.contraseniaNueva; | ||
usuario.save(); | ||
res.status(200).send("Datos actualizados exitosamente"); | ||
}) | ||
.catch((err) => { | ||
res.status(500).send(err); | ||
|
@@ -1393,9 +1419,8 @@ router.get("/categorias", async (req, res) => { | |
try { | ||
let categorias; | ||
// TODO Refactor: raw? nest? | ||
console.log(req.query); | ||
if(!!+req.query.etiquetas){ | ||
categorias=await Categoria.findAll({include:/* Etiqueta */{model:Etiqueta, as:'etiquetas'}}) | ||
categorias=await Categoria.findAll({include:{model:Etiqueta, as:'etiquetas'}}) | ||
}else{ | ||
categorias = await Categoria.findAll(); | ||
} | ||
|
@@ -1781,7 +1806,7 @@ router.get('/notificacion', function(req,res){ | |
|
||
router.patch("/notificacion", function (req, res) { | ||
if (!req.session.usuario) { | ||
res.status(402).send(); | ||
res.status(401).send(); | ||
return; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,6 @@ class Pagina { | |
<script>${Object.entries(this.globales) | ||
.map(([k, v]) => `var ${k} = ${JSON.stringify(v)}`) | ||
.join(";")}</script> | ||
<!-- <script src="https://unpkg.com/@c3r38r170/[email protected]" type="module"></script> --> | ||
<script src="/main.js" type=module></script> | ||
<link rel="stylesheet" href="/main.css"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.