agregar funciones para enviar correo con nueva contraseña

This commit is contained in:
Eduardo Quiros 2022-08-23 22:27:26 -06:00
parent f065a0418b
commit 4556aaba98
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
2 changed files with 59 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import { User } from './user/user.entity';
@Controller()
export class EmailController {
constructor(private mailService: MailerService) {}
constructor(private mailService: MailerService) { }
@MessagePattern({ cmd: 'sendMail' })
sendMail(@Payload() toEmail: string) {
@ -112,4 +112,37 @@ export class EmailController {
});
return response;
}
@MessagePattern({ cmd: 'emailResetUserPassword' })
async emailResetUserPassword(@Payload() user: any) {
const url = "http://localhost:3000/";
const image = "images/email.png";
const logo = "images/Logo Katoikia.png";
let response = await this.mailService.sendMail({
to: user["email"],
from: "katoikiap4@gmail.com",
subject: 'Restablecer contraseña',
template: 'emailResetUserPassword',
context: {
name: user["name"],
password: user["password"],
date_entry: user["date_entry"],
email: user["email"],
community_name: user['community_name'],
number_house: user['number_house'],
},
attachments: [
{
filename: 'email.png',
path: __dirname + '/mails/images/email.png',
cid: 'image_email'
},
{
filename: 'Logo_Katoikia.png',
path: __dirname + '/mails/images/Logo_Katoikia.png',
cid: 'logoKatoikia'
}],
});
return response;
}
}

View File

@ -73,11 +73,22 @@ export class UsersService {
}
async resetUserPassword(user: UserDocument) {
let passwordEncriptada = Md5.init(user.password);
const password = user.password;
const passwordEncriptada = Md5.init(password);
user.password = passwordEncriptada;
return this.userModel.findOneAndUpdate({ _id: user._id }, { password: passwordEncriptada }, {
this.userModel.findOneAndUpdate({ _id: user._id }, { password: passwordEncriptada }, {
new: true,
});
const pattern = { cmd: 'emailResetUserPassword' };
const payload = {
email: user['email'], password: user['password'],
date_entry: user['date_entry'], community_name: user['community_id']
};
return this.clientNotificationtApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message }))
);
}
async findCommunity(community_id: string) {
@ -306,8 +317,8 @@ export class UsersService {
async removeIdCommunity(community_id: string){
await this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}});
await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": '', "status": '-1'}});
return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": '', "status": '-1'}});
await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": '', "status": '-1'} });
return this.userModel.updateMany({ community_id: community_id, user_type: '4' }, { "$set": { "community_id": '', "status": '-1' } });
}
}