Skip to content

Commit

Permalink
Merge branch 'development-env' into feature/rebranding/web-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
SchadenKai authored Sep 25, 2024
2 parents 93db59f + d57d698 commit 0d276a3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
7 changes: 4 additions & 3 deletions backend/enmedd/auth/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from enmedd.auth.schemas import UserCreate
from enmedd.auth.schemas import UserRole
from enmedd.auth.utils import generate_password_reset_email
from enmedd.auth.utils import generate_user_verification_email
from enmedd.auth.utils import send_reset_password_email
from enmedd.auth.utils import send_user_verification_email
from enmedd.configs.app_configs import AUTH_TYPE
Expand Down Expand Up @@ -180,12 +181,12 @@ async def on_after_request_verify(
self, user: User, token: str, request: Optional[Request] = None
) -> None:
verify_email_domain(user.email)

logger.info(
f"Verification requested for user {user.id}. Verification token: {token}"
)

send_user_verification_email(user.email, token)
link = f"{WEB_DOMAIN}/auth/verify-email?token={token}"
subject, body = generate_user_verification_email(user.full_name, link)
send_user_verification_email(user.email, subject, body)


async def get_user_manager(
Expand Down
65 changes: 45 additions & 20 deletions backend/enmedd/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from enmedd.configs.app_configs import SMTP_PORT
from enmedd.configs.app_configs import SMTP_SERVER
from enmedd.configs.app_configs import SMTP_USER
from enmedd.configs.app_configs import WEB_DOMAIN


def generate_password_reset_email(email: str, reset_url: str):
Expand All @@ -26,34 +25,60 @@ def generate_password_reset_email(email: str, reset_url: str):
If you did not request a password reset, please ignore this email or contact support if you have concerns.
Best regards,
AI Platform Team
The AI Platform Team
"""

return subject, body


def generate_user_verification_email(full_name: str, verify_url: str):
subject = "Password Reset Request"

body = f"""
Hi {full_name},
Thank you for signing up!
To complete your registration, please verify your email address by clicking the link below
{verify_url}
If you did not request this email, please ignore it.
Best regards,
The AI Platform Team
"""

return subject, body


def send_user_verification_email(
user_email: str,
token: str,
mail_from: str = EMAIL_FROM,
to_email: str, subject: str, body: str, mail_from: str = EMAIL_FROM
) -> None:
msg = MIMEMultipart()
msg["Subject"] = "Email Verification"
msg["To"] = user_email
if mail_from:
msg["From"] = mail_from

link = f"{WEB_DOMAIN}/auth/verify-email?token={token}"
# Email configuration
sender_email = SMTP_USER
sender_password = SMTP_PASS
smtp_server = SMTP_SERVER
smtp_port = SMTP_PORT

body = MIMEText(f"Click the following link to verify your email address: {link}")
msg.attach(body)
# Create MIME message
message = MIMEMultipart()
message["To"] = to_email
message["Subject"] = subject
if mail_from:
message["From"] = mail_from
message.attach(MIMEText(body, "plain"))

with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as s:
s.starttls()
# If credentials fails with gmail, check (You need an app password, not just the basic email password)
# https://support.google.com/accounts/answer/185833?sjid=8512343437447396151-NA
s.login(SMTP_USER, SMTP_PASS)
s.send_message(msg)
try:
print(
f"SMTP SERVER: {smtp_server} PORT: {smtp_port} EMAIL: {sender_email} PASSWORD: {sender_password}"
)
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(sender_email, sender_password)
server.send_message(message)
print(f"Email verification sent to {to_email}")
except Exception as e:
print(f"Failed to send password reset email: {str(e)}")


def send_reset_password_email(
Expand Down
2 changes: 1 addition & 1 deletion backend/enmedd/dynamic_configs/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def store(self, key: str, val: JSON_ro, encrypt: bool = False) -> None:
) # type: ignore
session.query(KVStore).filter_by(key=key).delete() # just in case
session.add(obj)
session.commit()
session.commit()

def load(self, key: str) -> JSON_ro:
with self.get_session() as session:
Expand Down
7 changes: 7 additions & 0 deletions web/src/app/auth/signup/SignupForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export function SignupForms({ shouldVerify }: { shouldVerify?: boolean }) {
});
return;
}
setIsLoading(false);
console.log(shouldVerify);
if (shouldVerify) {
router.push("/auth/waiting-on-verification");
} else {
router.push("/");
}
}}
>
{({ isSubmitting, values }) => (
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/globalSidebar/GlobalSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const GlobalSidebar = ({ openSidebar, user }: GlobalSidebarProps) => {
delayDuration={0}
>
{workspaces?.workspace_name
? workspaces?.workspace_name
? workspaces.workspace_name
: "enMedD AI"}
</CustomTooltip>
</div>
Expand Down

0 comments on commit 0d276a3

Please sign in to comment.