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,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Optional,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||
|
||||
@ -40,7 +41,7 @@ export class InvitationService extends BaseService<
|
||||
@Inject(JwtService) private readonly jwtService: JwtService,
|
||||
protected readonly i18n: I18nService,
|
||||
public readonly languageService: LanguageService,
|
||||
private readonly mailerService: MailerService,
|
||||
@Optional() private readonly mailerService?: MailerService,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
@ -60,6 +61,7 @@ export class InvitationService extends BaseService<
|
||||
*/
|
||||
async create(dto: InvitationCreateDto): Promise<Invitation> {
|
||||
const jwt = await this.sign({ ...dto });
|
||||
if (this.mailerService) {
|
||||
try {
|
||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||
await this.mailerService.sendMail({
|
||||
@ -70,7 +72,8 @@ export class InvitationService extends BaseService<
|
||||
appUrl: config.uiBaseUrl,
|
||||
token: jwt,
|
||||
// TODO: Which language should we use?
|
||||
t: (key: string) => this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||
t: (key: string) =>
|
||||
this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||
},
|
||||
subject: this.i18n.t('invitation_subject'),
|
||||
});
|
||||
@ -83,6 +86,7 @@ export class InvitationService extends BaseService<
|
||||
);
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
}
|
||||
}
|
||||
const newInvitation = await super.create({ ...dto, token: jwt });
|
||||
return { ...newInvitation, token: jwt };
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
Optional,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||
@ -36,7 +37,7 @@ export class PasswordResetService {
|
||||
private readonly userService: UserService,
|
||||
public readonly i18n: I18nService,
|
||||
public readonly languageService: LanguageService,
|
||||
private readonly mailerService: MailerService,
|
||||
@Optional() private readonly mailerService?: MailerService,
|
||||
) {}
|
||||
|
||||
public readonly jwtSignOptions: JwtSignOptions = {
|
||||
@ -59,6 +60,7 @@ export class PasswordResetService {
|
||||
}
|
||||
const jwt = await this.sign({ ...dto });
|
||||
|
||||
if (this.mailerService) {
|
||||
try {
|
||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||
await this.mailerService.sendMail({
|
||||
@ -69,7 +71,8 @@ export class PasswordResetService {
|
||||
appUrl: config.uiBaseUrl,
|
||||
token: jwt,
|
||||
first_name: user.first_name,
|
||||
t: (key: string) => this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||
t: (key: string) =>
|
||||
this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||
},
|
||||
subject: this.i18n.t('password_reset_subject'),
|
||||
});
|
||||
@ -78,10 +81,11 @@ export class PasswordResetService {
|
||||
'Could not send email',
|
||||
e.message,
|
||||
e.stack,
|
||||
'InvitationService',
|
||||
'PasswordResetService',
|
||||
);
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: hash the token before saving it
|
||||
await this.userService.updateOne({ email: dto.email }, { resetToken: jwt });
|
||||
|
@ -12,6 +12,7 @@ import {
|
||||
Inject,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Optional,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
|
||||
@ -39,7 +40,7 @@ export class ValidateAccountService {
|
||||
private logger: LoggerService,
|
||||
private readonly i18n: I18nService,
|
||||
private readonly languageService: LanguageService,
|
||||
private readonly mailerService: MailerService,
|
||||
@Optional() private readonly mailerService?: MailerService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@ -76,6 +77,7 @@ export class ValidateAccountService {
|
||||
) {
|
||||
const confirmationToken = await this.sign({ email: dto.email });
|
||||
|
||||
if (this.mailerService) {
|
||||
try {
|
||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||
await this.mailerService.sendMail({
|
||||
@ -86,7 +88,8 @@ export class ValidateAccountService {
|
||||
appUrl: config.uiBaseUrl,
|
||||
token: confirmationToken,
|
||||
first_name: dto.first_name,
|
||||
t: (key: string) => this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||
t: (key: string) =>
|
||||
this.i18n.t(key, { lang: defaultLanguage.code }),
|
||||
},
|
||||
subject: this.i18n.t('account_confirmation_subject'),
|
||||
});
|
||||
@ -100,6 +103,7 @@ export class ValidateAccountService {
|
||||
throw new InternalServerErrorException('Could not send email');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms a user's account by validating the provided confirmation token.
|
||||
|
Loading…
Reference in New Issue
Block a user