Files
pcpuma_acatlan_api/server/controller/Usuario/crear.js
T

38 lines
1.3 KiB
JavaScript
Raw Normal View History

const helperPath = '../../helper';
const gmail = require(`${helperPath}/gmail`);
const encriptar = require(`${helperPath}/encriptar`);
const validar = require(`${helperPath}/validar`);
2021-04-27 23:11:09 -05:00
const Usuario = require('../../db/tablas/Usuario');
2021-05-20 13:50:31 -05:00
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:
2021-09-17 16:57:38 -05:00
'Se creó correctamente tu cuenta, ingresa a tu correo @pcpuma para consultar tu contraseña para este servicio.',
2021-05-20 13:50:31 -05:00
}));
};
2021-04-27 23:11:09 -05:00
2021-04-28 00:21:24 -05:00
module.exports = crear;