38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
const helperPath = '../../helper';
|
|
const gmail = require(`${helperPath}/gmail`);
|
|
const encriptar = require(`${helperPath}/encriptar`);
|
|
const validar = require(`${helperPath}/validar`);
|
|
const Usuario = require('../../db/tablas/Usuario');
|
|
|
|
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 creó correctamente tu cuenta, ingresa a tu correo @pcpuma para consultar tu contraseña para este servicio.',
|
|
}));
|
|
};
|
|
|
|
module.exports = crear;
|