Skip to content

Commit

Permalink
Add server smtp module and switch auth
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Nov 6, 2024
1 parent 67e8a06 commit e34724d
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 309 deletions.
10 changes: 6 additions & 4 deletions edb/lib/cfg.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ CREATE TYPE cfg::SMTPProviderConfig EXTENDING cfg::EmailProviderConfig {
CREATE ANNOTATION std::description :=
"Password for login after connected to SMTP server.";
};
CREATE REQUIRED PROPERTY security -> ext::auth::SMTPSecurity {
SET default := ext::auth::SMTPSecurity.STARTTLSOrPlainText;
CREATE REQUIRED PROPERTY security -> cfg::SMTPSecurity {
SET default := cfg::SMTPSecurity.STARTTLSOrPlainText;
CREATE ANNOTATION std::description :=
"Security mode of the connection to SMTP server. \
By default, initiate a STARTTLS upgrade if supported by the \
Expand Down Expand Up @@ -224,11 +224,13 @@ ALTER TYPE cfg::AbstractConfig {
};

CREATE MULTI LINK email_providers -> cfg::EmailProviderConfig {
CREATE ANNOTATION cfg::system := 'true';
CREATE ANNOTATION std::description :=
'The list of email providers that can be used to send emails.';
};

CREATE PROPERTY current_email_provider_name -> std::str {
CREATE ANNOTATION cfg::system := 'true';
CREATE ANNOTATION std::description :=
'The name of the current email provider.';
};

CREATE PROPERTY allow_dml_in_functions -> std::bool {
Expand Down
28 changes: 8 additions & 20 deletions edb/server/protocol/auth_ext/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import random

from typing import Any, Coroutine
from edb.server import tenant
from edb.server import tenant, smtp

from . import util, ui, smtp
from . import util, ui


async def send_password_reset_email(
Expand All @@ -15,7 +15,6 @@ async def send_password_reset_email(
reset_url: str,
test_mode: bool,
) -> None:
from_addr = util.get_config(db, "ext::auth::SMTPConfig::sender")
app_details_config = util.get_app_details_config(db)
if app_details_config is None:
email_args = {}
Expand All @@ -27,16 +26,13 @@ async def send_password_reset_email(
brand_color=app_details_config.brand_color,
)
msg = ui.render_password_reset_email(
from_addr=from_addr,
to_addr=to_addr,
reset_url=reset_url,
**email_args,
)
coro = smtp.send_email(
db,
smtp_provider = smtp.SMTP(db)
coro = smtp_provider.send(
msg,
sender=from_addr,
recipients=to_addr,
test_mode=test_mode,
)
await _protected_send(coro, tenant)
Expand All @@ -51,7 +47,6 @@ async def send_verification_email(
provider: str,
test_mode: bool,
) -> None:
from_addr = util.get_config(db, "ext::auth::SMTPConfig::sender")
app_details_config = util.get_app_details_config(db)
verification_token_params = urllib.parse.urlencode(
{
Expand All @@ -71,16 +66,13 @@ async def send_verification_email(
brand_color=app_details_config.brand_color,
)
msg = ui.render_verification_email(
from_addr=from_addr,
to_addr=to_addr,
verify_url=verify_url,
**email_args,
)
coro = smtp.send_email(
db,
smtp_provider = smtp.SMTP(db)
coro = smtp_provider.send(
msg,
sender=from_addr,
recipients=to_addr,
test_mode=test_mode,
)
await _protected_send(coro, tenant)
Expand All @@ -93,7 +85,6 @@ async def send_magic_link_email(
link: str,
test_mode: bool,
) -> None:
from_addr = util.get_config(db, "ext::auth::SMTPConfig::sender")
app_details_config = util.get_app_details_config(db)
if app_details_config is None:
email_args = {}
Expand All @@ -105,16 +96,13 @@ async def send_magic_link_email(
brand_color=app_details_config.brand_color,
)
msg = ui.render_magic_link_email(
from_addr=from_addr,
to_addr=to_addr,
link=link,
**email_args,
)
coro = smtp.send_email(
db,
smtp_provider = smtp.SMTP(db)
coro = smtp_provider.send(
msg,
sender=from_addr,
recipients=to_addr,
test_mode=test_mode,
)
await _protected_send(coro, tenant)
Expand Down
199 changes: 0 additions & 199 deletions edb/server/protocol/auth_ext/smtp.py

This file was deleted.

Loading

0 comments on commit e34724d

Please sign in to comment.