add mailaccount endpoint
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
2026-05-18 22:01:20 +02:00
parent 71724ac800
commit f9f4a70a79
4 changed files with 66 additions and 5 deletions
+8 -3
View File
@@ -1,12 +1,16 @@
from datetime import timedelta
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer, SecurityScopes
from fastapi.security import OAuth2PasswordRequestForm
from pydantic import BaseModel
from typing import Annotated
from src.core.config import settings
from src.core.log_conf import logger
from src.core.security import authenticate_user_by_email, authenticate_user_by_username, create_access_token
from src.core.security import (
authenticate_user_by_email,
authenticate_user_by_username,
create_access_token,
)
from src.schema.admin import Token
login_router = APIRouter()
@@ -25,7 +29,7 @@ class LoginRequest(BaseModel):
status_code=status.HTTP_200_OK,
)
def login(request: LoginRequest) -> Token:
logger.info(f"login with {request.email}")
logger.info("login with %s", request.email)
user = authenticate_user_by_email(str(request.email), str(request.password))
scopes = ["admin", "read"]
if not user:
@@ -41,6 +45,7 @@ def login(request: LoginRequest) -> Token:
)
return Token(access_token=access_token, token_type="bearer")
@login_router.post("/token", tags=["login"], summary="Login for access token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
@@ -0,0 +1,23 @@
from typing import List
from fastapi import APIRouter
from src.db.models.admin import MailAccount
from src.db.session import SessionDep
from src.schema.admin import MailAccountResponse, to_response
router = APIRouter()
@router.get("/mailaccounts", response_model=List[MailAccountResponse])
def get_all_mailaccounts(db: SessionDep) -> List[MailAccountResponse]:
"""
return all MailAccounts as JSON.
"""
results: List[MailAccountResponse] = []
players = db.query(MailAccount).all()
for player in players:
response = to_response(player)
results.append(response)
return results
+34
View File
@@ -1,7 +1,10 @@
from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel
from src.db.models.admin import MailAccount
class Token(BaseModel):
access_token: str
@@ -20,8 +23,39 @@ class ProfileModel(BaseModel):
last_name: str
active: bool
class HealthCheck(BaseModel):
"""
Health check model
"""
status: str = "ok"
class MailAccountResponse(BaseModel):
id: str
created_date: datetime
last_modified_date: datetime
version: int
host: str
port: int
protocol: str
user_name: str
password: str
start_tls: bool
def to_response(account: MailAccount) -> MailAccountResponse:
response: MailAccountResponse = MailAccountResponse(
id=account.id,
created_date=account.created_date,
last_modified_date=account.last_modified_date,
version=account.version,
host=account.host,
port=account.port,
protocol=account.protocol,
user_name=account.user_name,
password=account.password,
start_tls=account.start_tls,
)
return response
+1 -2
View File
@@ -1,12 +1,11 @@
from pydantic import BaseModel
from src.db.models.admin import Profile
class ProfileResponse(BaseModel):
id: str
user_name: str
class ProfileModel(BaseModel):
user_name: str
first_name: str