list crear
This commit is contained in:
@@ -3,6 +3,34 @@ const encriptar = require('../../helper/encriptar');
|
||||
const validar = require('../../helper/validar');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const crear = async (body) => {};
|
||||
const crear = async (body) => {
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const telefono = validar.validarNumero(body.telefono, false, 15);
|
||||
const password = encriptar.generarPassword();
|
||||
let correo = '@pcpuma.acatlan.unam.mx';
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
if (res.password) throw new Error('Este usuario ya fue registrado.');
|
||||
if (!res.activo) throw new Error('Este usuario no esta activo.');
|
||||
correo = res.usuario + correo;
|
||||
return Usuario.update(
|
||||
{
|
||||
password: encriptar.encriptar(password),
|
||||
telefono,
|
||||
},
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
// return gmail('Contraseña',correo,"")
|
||||
return gmail('Contraseña', 'lemuelhelonmarquezrosas@gmail.com', password);
|
||||
})
|
||||
.then((res) => ({
|
||||
message:
|
||||
'Se creo correctamente tu cuenta. Ingresa a tu correo Pc Puma. Te debe llegar un correo con tu contraseña.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = crear;
|
||||
|
||||
@@ -53,6 +53,7 @@ const escolares = async (body) => {
|
||||
delete res.dataValues.telefono;
|
||||
delete res.dataValues.multa;
|
||||
delete res.dataValues.idTipoUsuario;
|
||||
delete res.dataValues.idCarrera;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { Op } = require('sequelize');
|
||||
const encriptar = require('../../helper/encriptar');
|
||||
const validar = require('../../helper/validar');
|
||||
const { crearTokenUsuario } = require('../../middleware/autentificacion');
|
||||
@@ -14,11 +15,11 @@ const login = async (body) => {
|
||||
);
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { usuario },
|
||||
where: { usuario, password: { [Op.ne]: null } },
|
||||
include: [{ model: TipoUsuario }],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
// if (!res.activo) throw new Error('Este usuario no esta activo.');
|
||||
if (!res.activo) throw new Error('Este usuario fue desactivado.');
|
||||
if (encriptar.comparar(password, res.password)) {
|
||||
delete res.dataValues.password;
|
||||
return {
|
||||
|
||||
@@ -63,6 +63,7 @@ Usuario.belongsTo(Carrera, {
|
||||
foreignKey: {
|
||||
name: 'idCarrera',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/usuario';
|
||||
const controllerPath = '../controller/Usuario';
|
||||
const cargaMasivaPosgrados = require(`${controllerPath}/cargaMasivaPosgrados`);
|
||||
const crear = require(`${controllerPath}/crear`);
|
||||
const escolares = require(`${controllerPath}/escolares`);
|
||||
const login = require(`${controllerPath}/login`);
|
||||
const usuario = require(`${controllerPath}/usuario`);
|
||||
@@ -31,6 +32,16 @@ app.post(
|
||||
}
|
||||
);
|
||||
|
||||
app.post(`${route}/crear`, (req, res) => {
|
||||
return crear(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
.then((data) => {
|
||||
|
||||
Reference in New Issue
Block a user