added functional groups api + started pictures
This commit is contained in:
@ -10,9 +10,10 @@ from jwt.exceptions import InvalidTokenError
|
||||
# from passlib.context import CryptContext
|
||||
from psycopg2._psycopg import connection
|
||||
|
||||
import db.groups
|
||||
import db.users
|
||||
import settings.startup_settings as startup_settings
|
||||
from api.models import TokenData, User
|
||||
from api.models import Group, TokenData, User
|
||||
from db.internal import get_db_connection
|
||||
|
||||
# pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
@ -38,9 +39,13 @@ def authenticate_user(
|
||||
username: str,
|
||||
user_password: str
|
||||
):
|
||||
db_user_password = db.users.get_user_password(conn, username)
|
||||
if not user_password:
|
||||
return False
|
||||
|
||||
db_user_password = db.users.get_user_password(conn, username)
|
||||
if db_user_password is None:
|
||||
return False
|
||||
|
||||
if not verify_password(user_password, db_user_password):
|
||||
return False
|
||||
return True
|
||||
@ -64,7 +69,7 @@ async def get_current_user(
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
headers={"WWW-Authenticate": "Bearer"}
|
||||
)
|
||||
|
||||
try:
|
||||
@ -90,3 +95,19 @@ async def get_current_user(
|
||||
)
|
||||
|
||||
return user
|
||||
|
||||
def get_group_by_name(
|
||||
conn: connection,
|
||||
groupname: str
|
||||
):
|
||||
group_exception = HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No such group"
|
||||
)
|
||||
group = Group()
|
||||
group_data = db.groups.get_group(conn, groupname)
|
||||
if group_data is None:
|
||||
raise group_exception
|
||||
|
||||
group.fill(group_data)
|
||||
return group
|
||||
|
||||
Reference in New Issue
Block a user