mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 06:47:02 +08:00
@@ -37,7 +37,6 @@ import { CurrentUser, Session } from './session';
|
||||
interface PreflightResponse {
|
||||
registered: boolean;
|
||||
hasPassword: boolean;
|
||||
magicLink: boolean;
|
||||
}
|
||||
|
||||
interface SignInCredential {
|
||||
@@ -91,20 +90,16 @@ export class AuthController {
|
||||
|
||||
const user = await this.models.user.getUserByEmail(params.email);
|
||||
|
||||
const magicLinkAvailable = this.config.mailer.enabled;
|
||||
|
||||
if (!user) {
|
||||
return {
|
||||
registered: false,
|
||||
hasPassword: false,
|
||||
magicLink: magicLinkAvailable,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
registered: user.registered,
|
||||
hasPassword: !!user.password,
|
||||
magicLink: magicLinkAvailable,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import { defineModuleConfig } from '../../base';
|
||||
declare global {
|
||||
interface AppConfigSchema {
|
||||
mailer: {
|
||||
enabled: boolean;
|
||||
SMTP: {
|
||||
host: string;
|
||||
port: number;
|
||||
@@ -17,10 +16,6 @@ declare global {
|
||||
}
|
||||
|
||||
defineModuleConfig('mailer', {
|
||||
enabled: {
|
||||
desc: 'Whether enabled mail service.',
|
||||
default: false,
|
||||
},
|
||||
'SMTP.host': {
|
||||
desc: 'Host of the email server (e.g. smtp.gmail.com)',
|
||||
default: '',
|
||||
@@ -49,6 +44,6 @@ defineModuleConfig('mailer', {
|
||||
'SMTP.ignoreTLS': {
|
||||
desc: "Whether ignore email server's TSL certification verification. Enable it for self-signed certificates.",
|
||||
default: false,
|
||||
env: 'MAILER_IGNORE_TLS',
|
||||
env: ['MAILER_IGNORE_TLS', 'boolean'],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { JobQueue } from '../../base';
|
||||
import { EmailServiceNotConfigured, JobQueue } from '../../base';
|
||||
import { MailSender } from './sender';
|
||||
|
||||
@Injectable()
|
||||
export class Mailer {
|
||||
constructor(private readonly queue: JobQueue) {}
|
||||
constructor(
|
||||
private readonly queue: JobQueue,
|
||||
private readonly sender: MailSender
|
||||
) {}
|
||||
|
||||
get enabled() {
|
||||
// @ts-expect-error internal api
|
||||
return this.sender.smtp !== null;
|
||||
}
|
||||
|
||||
async send(command: Jobs['notification.sendMail']) {
|
||||
if (!this.enabled) {
|
||||
throw new EmailServiceNotConfigured();
|
||||
}
|
||||
|
||||
try {
|
||||
await this.queue.add('notification.sendMail', command);
|
||||
return true;
|
||||
|
||||
@@ -56,13 +56,7 @@ export class MailSender {
|
||||
}
|
||||
|
||||
private setup() {
|
||||
const { SMTP, enabled } = this.config.mailer;
|
||||
|
||||
if (!enabled) {
|
||||
this.smtp = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const { SMTP } = this.config.mailer;
|
||||
const opts = configToSMTPOptions(SMTP);
|
||||
|
||||
if (SMTP.host) {
|
||||
@@ -83,6 +77,7 @@ export class MailSender {
|
||||
});
|
||||
} else {
|
||||
this.logger.warn('Mailer SMTP transport is not configured.');
|
||||
this.smtp = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user