linea api cambiar password
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correos = require('../../helper/correos');
|
||||
const encriptar = require('../../helper/encriptar');
|
||||
const validar = require('../../helper/validar');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const newPasswordAlumno = async (body) => {
|
||||
let idServicio = await validar.validarId(body.idServicio);
|
||||
let pasword = encriptar.generarPassword();
|
||||
let idUsuario;
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
include: [{ model: Usuario }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este Servicio Social.');
|
||||
if (res.Usuario.idTipoUsuario != 3)
|
||||
throw new Error('Este usuario no es de tipo alumno.');
|
||||
|
||||
let correo = correos.preRegistro(pasword, res.Usuario.nombre);
|
||||
|
||||
idUsuario = res.idUsuario;
|
||||
return gmail(correo.subject, res.correo, correo.msj);
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.update(
|
||||
{ pasword: encriptar.encriptar(pasword) },
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message: 'Se envio un correo con una contraseña nueva al alumno.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = newPasswordAlumno;
|
||||
@@ -0,0 +1,33 @@
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correos = require('../../helper/correos');
|
||||
const encriptar = require('../../helper/encriptar');
|
||||
const validar = require('../../helper/validar');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const newPasswordResponsable = async (body) => {
|
||||
let idUsuario = await validar.validarId(body.idUsuario);
|
||||
let pasword = encriptar.generarPassword();
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este Usuario.');
|
||||
if (res.Usuario.idTipoUsuario != 2)
|
||||
throw new Error('Este usuario no es de tipo alumno.');
|
||||
|
||||
let correo = correos.enviarSec(pasword, res.correo, res.nombre);
|
||||
return gmail(correo.subject, res.correo, correo.msj);
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.update(
|
||||
{ pasword: encriptar.encriptar(pasword) },
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message: 'Se envio un correo con una contraseña nueva al responsable.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = newPasswordResponsable;
|
||||
Reference in New Issue
Block a user