Migrate email provider (from Brevo to generic SMTP) (#67)
This means we now need to have the text and HTML content set in the code, which is arguably better. In order to avoid allowing legacy Brevo API Key support, this will also introduce breaking changes and will be released as v2.0.0. I took the opportunity to remove a few deprecated things (like legacy ENV-based config), upgrade PostgreSQL, and pin a specific version in `docker-compose.yml`, since I don't plan to do breaking releases anytime soon, and upgrading PostgreSQL should be fine from now on if the version is pinned. If you were using Brevo with an API Key, they support SMTP as well, just update your config. If you were using ENV-based config, check `bewcloud.config.sample.ts`to create your `bewcloud.config.ts`. If you need help upgrading you PostgreSQL container, I've written a simple guide [step-by-step guide](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).
This commit is contained in:
@@ -4,7 +4,7 @@ import { generateHash, validateEmail } from '/lib/utils/misc.ts';
|
||||
import { createSessionResponse, PASSWORD_SALT } from '/lib/auth.ts';
|
||||
import { FormField, generateFieldHtml, getFormDataField } from '/lib/form-utils.tsx';
|
||||
import { UserModel, VerificationCodeModel } from '/lib/models/user.ts';
|
||||
import { sendVerifyEmailEmail } from '/lib/providers/brevo.ts';
|
||||
import { EmailModel } from '/lib/models/email.ts';
|
||||
import { FreshContextState } from '/lib/types.ts';
|
||||
import { AppConfig } from '/lib/config.ts';
|
||||
import { isMultiFactorAuthEnabledForUser } from '/lib/utils/multi-factor-auth.ts';
|
||||
@@ -123,7 +123,7 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
if (!code) {
|
||||
const verificationCode = await VerificationCodeModel.create(user, user.email, 'email');
|
||||
|
||||
await sendVerifyEmailEmail(user.email, verificationCode);
|
||||
await EmailModel.sendVerificationEmail(user.email, verificationCode);
|
||||
|
||||
throw new Error('Email not verified. New code sent to verify your email.');
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { PASSWORD_SALT } from '/lib/auth.ts';
|
||||
import { UserModel, VerificationCodeModel } from '/lib/models/user.ts';
|
||||
import { convertFormDataToObject, generateHash, validateEmail } from '/lib/utils/misc.ts';
|
||||
import { getFormDataField } from '/lib/form-utils.tsx';
|
||||
import { sendVerifyEmailEmail } from '/lib/providers/brevo.ts';
|
||||
import { EmailModel } from '/lib/models/email.ts';
|
||||
import { AppConfig } from '/lib/config.ts';
|
||||
import Settings, { Action, actionWords } from '/islands/Settings.tsx';
|
||||
|
||||
@@ -93,7 +93,7 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
if (action === 'change-email' && (await AppConfig.isEmailVerificationEnabled())) {
|
||||
const verificationCode = await VerificationCodeModel.create(user, email, 'email');
|
||||
|
||||
await sendVerifyEmailEmail(email, verificationCode);
|
||||
await EmailModel.sendVerificationEmail(email, verificationCode);
|
||||
|
||||
successTitle = 'Verify your email!';
|
||||
successMessage = 'You have received a code in your new email. Use it to verify it here.';
|
||||
|
||||
@@ -4,7 +4,7 @@ import { generateHash, validateEmail } from '/lib/utils/misc.ts';
|
||||
import { PASSWORD_SALT } from '/lib/auth.ts';
|
||||
import { FormField, generateFieldHtml, getFormDataField } from '/lib/form-utils.tsx';
|
||||
import { UserModel, VerificationCodeModel } from '/lib/models/user.ts';
|
||||
import { sendVerifyEmailEmail } from '/lib/providers/brevo.ts';
|
||||
import { EmailModel } from '/lib/models/email.ts';
|
||||
import { AppConfig } from '/lib/config.ts';
|
||||
import { FreshContextState } from '/lib/types.ts';
|
||||
import { OidcModel } from '/lib/models/oidc.ts';
|
||||
@@ -96,7 +96,7 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
if (isEmailVerificationEnabled) {
|
||||
const verificationCode = await VerificationCodeModel.create(user, user.email, 'email');
|
||||
|
||||
await sendVerifyEmailEmail(user.email, verificationCode);
|
||||
await EmailModel.sendVerificationEmail(user.email, verificationCode);
|
||||
}
|
||||
|
||||
return new Response('Signup successful', {
|
||||
|
||||
Reference in New Issue
Block a user