mirror of
https://github.com/lorsanstand/Aether.git
synced 2026-06-19 12:05:16 +03:00
add frontend and change password
This commit is contained in:
@@ -26,6 +26,31 @@ class EmailService:
|
||||
company_name=settings.COMPANY_NAME
|
||||
)
|
||||
|
||||
EmailClient.send_email(to=email, subject=subject, html=html, body=body)
|
||||
log.info("Verify email sent to %s", email, extra={"email": email})
|
||||
except Exception as e:
|
||||
log.error("Failed to send email to %s", email, extra={"email": email})
|
||||
raise e
|
||||
|
||||
|
||||
@classmethod
|
||||
def send_reset_password_email(cls, email: str, username: str, url: str):
|
||||
log.debug("Sending email to %s", email, extra={"email": email})
|
||||
try:
|
||||
subject = "Подтверждение эл. почты"
|
||||
html = EmailClient.render(
|
||||
template_path="reset_password.html",
|
||||
username=username,
|
||||
url=url,
|
||||
company_name=settings.COMPANY_NAME
|
||||
)
|
||||
body = EmailClient.render(
|
||||
template_path="confirm_email.txt",
|
||||
username=username,
|
||||
url=url,
|
||||
company_name=settings.COMPANY_NAME
|
||||
)
|
||||
|
||||
EmailClient.send_email(to=email, subject=subject, html=html, body=body)
|
||||
log.info("Verify email sent to %s", email, extra={"email": email})
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
import logging
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
from app.core.redis import get_redis
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class TokenStorage:
|
||||
PREFIX: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
async def save_token(cls, token: uuid.UUID, user_id: int, ttl: int):
|
||||
redis_client = await get_redis()
|
||||
|
||||
await redis_client.setex(f"{cls.PREFIX}:{token}", ttl, user_id)
|
||||
|
||||
log.info("Save new %s token from redis", cls.PREFIX, extra={"user_id": user_id, "token": token})
|
||||
|
||||
@classmethod
|
||||
async def getdel_token(cls, token: uuid.UUID) -> int:
|
||||
redis_client = await get_redis()
|
||||
log.debug("User_id fetched from %s token", cls.PREFIX, extra={"token": token})
|
||||
return await redis_client.getdel(f"{cls.PREFIX}:{token}")
|
||||
|
||||
|
||||
class RefreshTokenStorage:
|
||||
PREFIX: str = "refresh"
|
||||
@@ -53,20 +71,9 @@ class RefreshTokenStorage:
|
||||
|
||||
|
||||
|
||||
class EmailTokenStorage:
|
||||
PREFIX: str = "email"
|
||||
|
||||
@classmethod
|
||||
async def save_token(cls, token: uuid.UUID, user_id: int, ttl: int):
|
||||
redis_client = await get_redis()
|
||||
|
||||
await redis_client.setex(f"{cls.PREFIX}:{token}", ttl, user_id)
|
||||
|
||||
log.info("Save new refresh token from redis", extra={"user_id": user_id, "token": token})
|
||||
class EmailTokenStorage(TokenStorage):
|
||||
PREFIX = "email"
|
||||
|
||||
|
||||
@classmethod
|
||||
async def getdel_token(cls, token: uuid.UUID) -> int:
|
||||
redis_client = await get_redis()
|
||||
log.debug("User_id fetched from email token", extra={"token": token})
|
||||
return await redis_client.getdel(f"{cls.PREFIX}:{token}")
|
||||
class ChangePasswordTokenStorage(TokenStorage):
|
||||
PREFIX = "changepassword"
|
||||
Reference in New Issue
Block a user