mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge remote-tracking branch 'upstream/main' into 40-issue-prevent-users-from-deleting-their-own-roles
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Inject,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Optional,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
@@ -32,7 +33,7 @@ export class InvitationService extends BaseService<Invitation> {
|
||||
@Inject(InvitationRepository)
|
||||
readonly repository: InvitationRepository,
|
||||
@Inject(JwtService) private readonly jwtService: JwtService,
|
||||
private readonly mailerService: MailerService,
|
||||
@Optional() private readonly mailerService: MailerService | undefined,
|
||||
private logger: LoggerService,
|
||||
protected readonly i18n: ExtendedI18nService,
|
||||
) {
|
||||
@@ -54,24 +55,28 @@ export class InvitationService extends BaseService<Invitation> {
|
||||
*/
|
||||
async create(dto: InvitationCreateDto): Promise<Invitation> {
|
||||
const jwt = await this.sign(dto);
|
||||
try {
|
||||
await this.mailerService.sendMail({
|
||||
to: dto.email,
|
||||
template: 'invitation.mjml',
|
||||
context: {
|
||||
token: jwt,
|
||||
// TODO: Which language should we use?
|
||||
t: (key: string) => this.i18n.t(key),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error(
|
||||
'Could not send email',
|
||||
e.message,
|
||||
e.stack,
|
||||
'InvitationService',
|
||||
);
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
if (this.mailerService) {
|
||||
try {
|
||||
await this.mailerService.sendMail({
|
||||
to: dto.email,
|
||||
template: 'invitation.mjml',
|
||||
context: {
|
||||
token: jwt,
|
||||
// TODO: Which language should we use?
|
||||
t: (key: string) =>
|
||||
this.i18n.t(key, { lang: config.chatbot.lang.default }),
|
||||
},
|
||||
subject: this.i18n.t('invitation_subject'),
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error(
|
||||
'Could not send email',
|
||||
e.message,
|
||||
e.stack,
|
||||
'InvitationService',
|
||||
);
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
}
|
||||
}
|
||||
const newInvitation = await super.create({ ...dto, token: jwt });
|
||||
return { ...newInvitation, token: jwt };
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
Optional,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||
@@ -30,7 +31,7 @@ import { UserRequestResetDto, UserResetPasswordDto } from '../dto/user.dto';
|
||||
export class PasswordResetService {
|
||||
constructor(
|
||||
@Inject(JwtService) private readonly jwtService: JwtService,
|
||||
private readonly mailerService: MailerService,
|
||||
@Optional() private readonly mailerService: MailerService | undefined,
|
||||
private logger: LoggerService,
|
||||
private readonly userService: UserService,
|
||||
public readonly i18n: ExtendedI18nService,
|
||||
@@ -55,24 +56,29 @@ export class PasswordResetService {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
const jwt = await this.sign(dto);
|
||||
try {
|
||||
await this.mailerService.sendMail({
|
||||
to: dto.email,
|
||||
template: 'password_reset.mjml',
|
||||
context: {
|
||||
token: jwt,
|
||||
first_name: user.first_name,
|
||||
t: (key: string) => this.i18n.t(key),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error(
|
||||
'Could not send email',
|
||||
e.message,
|
||||
e.stack,
|
||||
'InvitationService',
|
||||
);
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
|
||||
if (this.mailerService) {
|
||||
try {
|
||||
await this.mailerService.sendMail({
|
||||
to: dto.email,
|
||||
template: 'password_reset.mjml',
|
||||
context: {
|
||||
token: jwt,
|
||||
first_name: user.first_name,
|
||||
t: (key: string) =>
|
||||
this.i18n.t(key, { lang: config.chatbot.lang.default }),
|
||||
},
|
||||
subject: this.i18n.t('password_reset_subject'),
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error(
|
||||
'Could not send email',
|
||||
e.message,
|
||||
e.stack,
|
||||
'InvitationService',
|
||||
);
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: hash the token before saving it
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Inject,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Optional,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||
@@ -33,7 +34,7 @@ export class ValidateAccountService {
|
||||
constructor(
|
||||
@Inject(JwtService) private readonly jwtService: JwtService,
|
||||
private readonly userService: UserService,
|
||||
private readonly mailerService: MailerService,
|
||||
@Optional() private readonly mailerService: MailerService | undefined,
|
||||
private readonly i18n: ExtendedI18nService,
|
||||
) {}
|
||||
|
||||
@@ -71,16 +72,19 @@ export class ValidateAccountService {
|
||||
) {
|
||||
const confirmationToken = await this.sign({ email: dto.email });
|
||||
|
||||
await this.mailerService.sendMail({
|
||||
to: dto.email,
|
||||
template: 'account_confirmation.mjml',
|
||||
context: {
|
||||
token: confirmationToken,
|
||||
first_name: dto.first_name,
|
||||
t: (key: string) => this.i18n.t(key),
|
||||
},
|
||||
subject: 'Account confirmation Email',
|
||||
});
|
||||
if (this.mailerService) {
|
||||
await this.mailerService.sendMail({
|
||||
to: dto.email,
|
||||
template: 'account_confirmation.mjml',
|
||||
context: {
|
||||
token: confirmationToken,
|
||||
first_name: dto.first_name,
|
||||
t: (key: string) =>
|
||||
this.i18n.t(key, { lang: config.chatbot.lang.default }),
|
||||
},
|
||||
subject: this.i18n.t('account_confirmation_subject'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user