mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge pull request #1147 from Hexastack/1146-bug---missing-mailservice-usermodule
fix(api): reset mailerService to be optional [HOTFIX]
This commit is contained in:
commit
0e3187c844
@ -12,6 +12,7 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
Injectable,
|
Injectable,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
|
Optional,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ export class InvitationService extends BaseService<
|
|||||||
@Inject(JwtService) private readonly jwtService: JwtService,
|
@Inject(JwtService) private readonly jwtService: JwtService,
|
||||||
protected readonly i18n: I18nService,
|
protected readonly i18n: I18nService,
|
||||||
public readonly languageService: LanguageService,
|
public readonly languageService: LanguageService,
|
||||||
private readonly mailerService: MailerService,
|
@Optional() private readonly mailerService?: MailerService,
|
||||||
) {
|
) {
|
||||||
super(repository);
|
super(repository);
|
||||||
}
|
}
|
||||||
@ -60,28 +61,31 @@ export class InvitationService extends BaseService<
|
|||||||
*/
|
*/
|
||||||
async create(dto: InvitationCreateDto): Promise<Invitation> {
|
async create(dto: InvitationCreateDto): Promise<Invitation> {
|
||||||
const jwt = await this.sign({ ...dto });
|
const jwt = await this.sign({ ...dto });
|
||||||
try {
|
if (this.mailerService) {
|
||||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
try {
|
||||||
await this.mailerService.sendMail({
|
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||||
to: dto.email,
|
await this.mailerService.sendMail({
|
||||||
template: 'invitation.mjml',
|
to: dto.email,
|
||||||
context: {
|
template: 'invitation.mjml',
|
||||||
appName: config.parameters.appName,
|
context: {
|
||||||
appUrl: config.uiBaseUrl,
|
appName: config.parameters.appName,
|
||||||
token: jwt,
|
appUrl: config.uiBaseUrl,
|
||||||
// TODO: Which language should we use?
|
token: jwt,
|
||||||
t: (key: string) => this.i18n.t(key, { lang: defaultLanguage.code }),
|
// TODO: Which language should we use?
|
||||||
},
|
t: (key: string) =>
|
||||||
subject: this.i18n.t('invitation_subject'),
|
this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||||
});
|
},
|
||||||
} catch (e) {
|
subject: this.i18n.t('invitation_subject'),
|
||||||
this.logger.error(
|
});
|
||||||
'Could not send email',
|
} catch (e) {
|
||||||
e.message,
|
this.logger.error(
|
||||||
e.stack,
|
'Could not send email',
|
||||||
'InvitationService',
|
e.message,
|
||||||
);
|
e.stack,
|
||||||
throw new InternalServerErrorException('Could not send email');
|
'InvitationService',
|
||||||
|
);
|
||||||
|
throw new InternalServerErrorException('Could not send email');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const newInvitation = await super.create({ ...dto, token: jwt });
|
const newInvitation = await super.create({ ...dto, token: jwt });
|
||||||
return { ...newInvitation, token: jwt };
|
return { ...newInvitation, token: jwt };
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
Injectable,
|
Injectable,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
|
Optional,
|
||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||||
@ -36,7 +37,7 @@ export class PasswordResetService {
|
|||||||
private readonly userService: UserService,
|
private readonly userService: UserService,
|
||||||
public readonly i18n: I18nService,
|
public readonly i18n: I18nService,
|
||||||
public readonly languageService: LanguageService,
|
public readonly languageService: LanguageService,
|
||||||
private readonly mailerService: MailerService,
|
@Optional() private readonly mailerService?: MailerService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public readonly jwtSignOptions: JwtSignOptions = {
|
public readonly jwtSignOptions: JwtSignOptions = {
|
||||||
@ -59,28 +60,31 @@ export class PasswordResetService {
|
|||||||
}
|
}
|
||||||
const jwt = await this.sign({ ...dto });
|
const jwt = await this.sign({ ...dto });
|
||||||
|
|
||||||
try {
|
if (this.mailerService) {
|
||||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
try {
|
||||||
await this.mailerService.sendMail({
|
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||||
to: dto.email,
|
await this.mailerService.sendMail({
|
||||||
template: 'password_reset.mjml',
|
to: dto.email,
|
||||||
context: {
|
template: 'password_reset.mjml',
|
||||||
appName: config.parameters.appName,
|
context: {
|
||||||
appUrl: config.uiBaseUrl,
|
appName: config.parameters.appName,
|
||||||
token: jwt,
|
appUrl: config.uiBaseUrl,
|
||||||
first_name: user.first_name,
|
token: jwt,
|
||||||
t: (key: string) => this.i18n.t(key, { lang: defaultLanguage.code }),
|
first_name: user.first_name,
|
||||||
},
|
t: (key: string) =>
|
||||||
subject: this.i18n.t('password_reset_subject'),
|
this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||||
});
|
},
|
||||||
} catch (e) {
|
subject: this.i18n.t('password_reset_subject'),
|
||||||
this.logger.error(
|
});
|
||||||
'Could not send email',
|
} catch (e) {
|
||||||
e.message,
|
this.logger.error(
|
||||||
e.stack,
|
'Could not send email',
|
||||||
'InvitationService',
|
e.message,
|
||||||
);
|
e.stack,
|
||||||
throw new InternalServerErrorException('Could not send email');
|
'PasswordResetService',
|
||||||
|
);
|
||||||
|
throw new InternalServerErrorException('Could not send email');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: hash the token before saving it
|
// TODO: hash the token before saving it
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
Injectable,
|
Injectable,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
|
Optional,
|
||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||||
@ -39,7 +40,7 @@ export class ValidateAccountService {
|
|||||||
private logger: LoggerService,
|
private logger: LoggerService,
|
||||||
private readonly i18n: I18nService,
|
private readonly i18n: I18nService,
|
||||||
private readonly languageService: LanguageService,
|
private readonly languageService: LanguageService,
|
||||||
private readonly mailerService: MailerService,
|
@Optional() private readonly mailerService?: MailerService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,28 +77,31 @@ export class ValidateAccountService {
|
|||||||
) {
|
) {
|
||||||
const confirmationToken = await this.sign({ email: dto.email });
|
const confirmationToken = await this.sign({ email: dto.email });
|
||||||
|
|
||||||
try {
|
if (this.mailerService) {
|
||||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
try {
|
||||||
await this.mailerService.sendMail({
|
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||||
to: dto.email,
|
await this.mailerService.sendMail({
|
||||||
template: 'account_confirmation.mjml',
|
to: dto.email,
|
||||||
context: {
|
template: 'account_confirmation.mjml',
|
||||||
appName: config.parameters.appName,
|
context: {
|
||||||
appUrl: config.uiBaseUrl,
|
appName: config.parameters.appName,
|
||||||
token: confirmationToken,
|
appUrl: config.uiBaseUrl,
|
||||||
first_name: dto.first_name,
|
token: confirmationToken,
|
||||||
t: (key: string) => this.i18n.t(key, { lang: defaultLanguage.code }),
|
first_name: dto.first_name,
|
||||||
},
|
t: (key: string) =>
|
||||||
subject: this.i18n.t('account_confirmation_subject'),
|
this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||||
});
|
},
|
||||||
} catch (e) {
|
subject: this.i18n.t('account_confirmation_subject'),
|
||||||
this.logger.error(
|
});
|
||||||
'Could not send email',
|
} catch (e) {
|
||||||
e.message,
|
this.logger.error(
|
||||||
e.stack,
|
'Could not send email',
|
||||||
'ValidateAccount',
|
e.message,
|
||||||
);
|
e.stack,
|
||||||
throw new InternalServerErrorException('Could not send email');
|
'ValidateAccount',
|
||||||
|
);
|
||||||
|
throw new InternalServerErrorException('Could not send email');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user