Initial commit - Migrated to Dev environment
This commit is contained in:
0
backend/app/core/__init__.py
Executable file
0
backend/app/core/__init__.py
Executable file
BIN
backend/app/core/__pycache__/__init__.cpython-312.pyc
Executable file
BIN
backend/app/core/__pycache__/__init__.cpython-312.pyc
Executable file
Binary file not shown.
BIN
backend/app/core/__pycache__/config.cpython-312.pyc
Executable file
BIN
backend/app/core/__pycache__/config.cpython-312.pyc
Executable file
Binary file not shown.
BIN
backend/app/core/__pycache__/security.cpython-312.pyc
Executable file
BIN
backend/app/core/__pycache__/security.cpython-312.pyc
Executable file
Binary file not shown.
53
backend/app/core/config.py
Executable file
53
backend/app/core/config.py
Executable file
@@ -0,0 +1,53 @@
|
||||
from typing import Optional
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from pydantic import computed_field
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# --- General ---
|
||||
PROJECT_NAME: str = "Traffic Ecosystem SuperApp"
|
||||
VERSION: str = "2.0.0"
|
||||
API_V1_STR: str = "/api/v1"
|
||||
DEBUG: bool = False
|
||||
|
||||
# --- Security / JWT ---
|
||||
SECRET_KEY: str
|
||||
ALGORITHM: str = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60
|
||||
|
||||
# --- Password policy (TEST -> laza, PROD -> szigorú) ---
|
||||
PASSWORD_MIN_LENGTH: int = 4 # TESZT: 4, ÉLES: 10-12
|
||||
|
||||
# --- Database ---
|
||||
DATABASE_URL: str # már nálad compose-ban meg van adva
|
||||
|
||||
# --- Redis ---
|
||||
REDIS_URL: str = "redis://service_finder_redis:6379/0"
|
||||
|
||||
# --- Email sending ---
|
||||
# auto = ha van SENDGRID_API_KEY -> sendgrid api, különben smtp
|
||||
EMAIL_PROVIDER: str = "auto" # auto | sendgrid | smtp | disabled
|
||||
|
||||
EMAILS_FROM_EMAIL: str = "info@profibot.hu"
|
||||
EMAILS_FROM_NAME: str = "Profibot"
|
||||
|
||||
# SendGrid API
|
||||
SENDGRID_API_KEY: Optional[str] = None
|
||||
|
||||
# SMTP fallback (pl. Gmail App Password vagy más szolgáltató)
|
||||
SMTP_HOST: Optional[str] = None
|
||||
SMTP_PORT: int = 587
|
||||
SMTP_USER: Optional[str] = None
|
||||
SMTP_PASSWORD: Optional[str] = None
|
||||
SMTP_USE_TLS: bool = True
|
||||
|
||||
# Frontend base URL a linkekhez (később NPM/domain)
|
||||
FRONTEND_BASE_URL: str = "http://192.168.100.43:3000"
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=True,
|
||||
extra="ignore"
|
||||
)
|
||||
|
||||
settings = Settings()
|
||||
10
backend/app/core/email.py
Executable file
10
backend/app/core/email.py
Executable file
@@ -0,0 +1,10 @@
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def send_verification_email(email_to: str, token: str, first_name: str):
|
||||
logger.info(f"MOCK EMAIL -> Címzett: {email_to}, Token: {token}")
|
||||
return True
|
||||
|
||||
async def send_new_account_email(email_to: str, username: str, password: str):
|
||||
logger.info(f"MOCK EMAIL -> Új fiók: {username}")
|
||||
return True
|
||||
18
backend/app/core/email.py.bak
Executable file
18
backend/app/core/email.py.bak
Executable file
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
from sendgrid import SendGridAPIClient
|
||||
from sendgrid.helpers.mail import Mail
|
||||
|
||||
def send_verification_email(to_email: str, token: str):
|
||||
message = Mail(
|
||||
from_email='noreply@servicefinder.pro', # Ezt majd igazítsd a SendGrid verified senderhez
|
||||
to_emails=to_email,
|
||||
subject='Service Finder - Regisztráció megerősítése',
|
||||
html_content=f'<h3>Üdvözöljük a Service Finderben!</h3><p>A regisztráció befejezéséhez kattintson az alábbi linkre:</p><p><a href="https://servicefinder.pro/verify?token={token}">Megerősítem a regisztrációmat</a></p>'
|
||||
)
|
||||
try:
|
||||
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
|
||||
response = sg.send(message)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Email hiba: {e}")
|
||||
return False
|
||||
33
backend/app/core/security.py
Executable file
33
backend/app/core/security.py
Executable file
@@ -0,0 +1,33 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
import bcrypt
|
||||
from jose import jwt, JWTError
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
# --- JELSZÓ ---
|
||||
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
||||
try:
|
||||
if not hashed_password:
|
||||
return False
|
||||
return bcrypt.checkpw(
|
||||
plain_password.encode("utf-8"),
|
||||
hashed_password.encode("utf-8"),
|
||||
)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def get_password_hash(password: str) -> str:
|
||||
salt = bcrypt.gensalt()
|
||||
return bcrypt.hashpw(password.encode("utf-8"), salt).decode("utf-8")
|
||||
|
||||
# --- JWT ---
|
||||
def create_access_token(data: Dict[str, Any], expires_delta: Optional[timedelta] = None) -> str:
|
||||
to_encode = dict(data)
|
||||
expire = datetime.now(timezone.utc) + (expires_delta or timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES))
|
||||
to_encode.update({"exp": expire})
|
||||
return jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
|
||||
|
||||
def decode_token(token: str) -> Dict[str, Any]:
|
||||
return jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
||||
Reference in New Issue
Block a user