From d108c54d81c2e17c8cd51f0a5109f4c73494f3da Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 14 Oct 2023 22:45:12 +0200 Subject: [PATCH] send mail wip --- app/dependencies/mail.py | 3 ++- app/routers/users.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/dependencies/mail.py b/app/dependencies/mail.py index 9750c9e..dca8e78 100644 --- a/app/dependencies/mail.py +++ b/app/dependencies/mail.py @@ -1,4 +1,5 @@ from fastapi_mail import ConnectionConfig +from pathlib import Path import os conf = ConnectionConfig( @@ -9,5 +10,5 @@ conf = ConnectionConfig( MAIL_SERVER = "your mail server", MAIL_STARTTLS = True, MAIL_SSL_TLS = False, - TEMPLATE_FOLDER = Path(__file__).parent / 'templates', + TEMPLATE_FOLDER = Path(__file__).parents[1] / 'templates', ) diff --git a/app/routers/users.py b/app/routers/users.py index 265d4b9..22c3a06 100644 --- a/app/routers/users.py +++ b/app/routers/users.py @@ -1,5 +1,5 @@ from fastapi import APIRouter, Depends, HTTPException, status -from ..dependencies import users_token, permissions_checker, database +from ..dependencies import users_token, permissions_checker, database, mail from ..models import users from typing import Annotated from bson import ObjectId @@ -111,7 +111,8 @@ async def read_users_me(userSingle: users.UserCreate | None = None): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail="Body request is empty" - ) + ) + fm = FastMail(mail.conf) user_repository = users.UserRepository(database=database.database) current_user = users.User(username=userSingle.username, password=user_token.get_password_hash(userSingle.password)) user_repository.save(current_user)