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,6 +61,7 @@ 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 });
|
||||||
|
if (this.mailerService) {
|
||||||
try {
|
try {
|
||||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||||
await this.mailerService.sendMail({
|
await this.mailerService.sendMail({
|
||||||
@ -70,7 +72,8 @@ export class InvitationService extends BaseService<
|
|||||||
appUrl: config.uiBaseUrl,
|
appUrl: config.uiBaseUrl,
|
||||||
token: jwt,
|
token: jwt,
|
||||||
// TODO: Which language should we use?
|
// 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'),
|
subject: this.i18n.t('invitation_subject'),
|
||||||
});
|
});
|
||||||
@ -83,6 +86,7 @@ export class InvitationService extends BaseService<
|
|||||||
);
|
);
|
||||||
throw new InternalServerErrorException('Could not send email');
|
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,6 +60,7 @@ export class PasswordResetService {
|
|||||||
}
|
}
|
||||||
const jwt = await this.sign({ ...dto });
|
const jwt = await this.sign({ ...dto });
|
||||||
|
|
||||||
|
if (this.mailerService) {
|
||||||
try {
|
try {
|
||||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||||
await this.mailerService.sendMail({
|
await this.mailerService.sendMail({
|
||||||
@ -69,7 +71,8 @@ export class PasswordResetService {
|
|||||||
appUrl: config.uiBaseUrl,
|
appUrl: config.uiBaseUrl,
|
||||||
token: jwt,
|
token: jwt,
|
||||||
first_name: user.first_name,
|
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'),
|
subject: this.i18n.t('password_reset_subject'),
|
||||||
});
|
});
|
||||||
@ -78,10 +81,11 @@ export class PasswordResetService {
|
|||||||
'Could not send email',
|
'Could not send email',
|
||||||
e.message,
|
e.message,
|
||||||
e.stack,
|
e.stack,
|
||||||
'InvitationService',
|
'PasswordResetService',
|
||||||
);
|
);
|
||||||
throw new InternalServerErrorException('Could not send email');
|
throw new InternalServerErrorException('Could not send email');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: hash the token before saving it
|
// TODO: hash the token before saving it
|
||||||
await this.userService.updateOne({ email: dto.email }, { resetToken: jwt });
|
await this.userService.updateOne({ email: dto.email }, { resetToken: jwt });
|
||||||
|
@ -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,6 +77,7 @@ export class ValidateAccountService {
|
|||||||
) {
|
) {
|
||||||
const confirmationToken = await this.sign({ email: dto.email });
|
const confirmationToken = await this.sign({ email: dto.email });
|
||||||
|
|
||||||
|
if (this.mailerService) {
|
||||||
try {
|
try {
|
||||||
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
const defaultLanguage = await this.languageService.getDefaultLanguage();
|
||||||
await this.mailerService.sendMail({
|
await this.mailerService.sendMail({
|
||||||
@ -86,7 +88,8 @@ export class ValidateAccountService {
|
|||||||
appUrl: config.uiBaseUrl,
|
appUrl: config.uiBaseUrl,
|
||||||
token: confirmationToken,
|
token: confirmationToken,
|
||||||
first_name: dto.first_name,
|
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'),
|
subject: this.i18n.t('account_confirmation_subject'),
|
||||||
});
|
});
|
||||||
@ -100,6 +103,7 @@ export class ValidateAccountService {
|
|||||||
throw new InternalServerErrorException('Could not send email');
|
throw new InternalServerErrorException('Could not send email');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirms a user's account by validating the provided confirmation token.
|
* Confirms a user's account by validating the provided confirmation token.
|
||||||
|
Loading…
Reference in New Issue
Block a user