mirror of
https://gitlab.com/akasroua/covot
synced 2025-12-24 16:11:55 +01:00
Fix user search query
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import Query
|
||||
|
||||
from database import SessionLocal, engine, models
|
||||
from database.models import User
|
||||
@@ -7,12 +6,14 @@ from database.models import User
|
||||
db = SessionLocal()
|
||||
|
||||
|
||||
def search_database(id) -> Query:
|
||||
def search_database(id) -> User:
|
||||
"""
|
||||
Returns the user associated with the id argument
|
||||
"""
|
||||
return db.query(User).filter(
|
||||
or_(User.correo_institucional == id, User.numero_de_documento == id)
|
||||
return (
|
||||
db.query(User)
|
||||
.filter(or_(User.correo_institucional == id, User.numero_de_documento == id))
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
@@ -37,7 +38,7 @@ def create_database(data) -> None:
|
||||
insert_data(data)
|
||||
|
||||
|
||||
def save_attribute(attribute, data) -> None:
|
||||
def save_attribute(id, attribute, data) -> None:
|
||||
"""
|
||||
Updates the attribute value with the content of data
|
||||
"""
|
||||
@@ -45,6 +46,7 @@ def save_attribute(attribute, data) -> None:
|
||||
db.query(User).filter(
|
||||
or_(User.correo_institucional == id, User.numero_de_documento == id)
|
||||
).update({key: data})
|
||||
db.commit()
|
||||
|
||||
|
||||
def verify_code(id, code) -> bool:
|
||||
@@ -52,7 +54,7 @@ def verify_code(id, code) -> bool:
|
||||
Verifies that two-factor authentification code matches the database record
|
||||
"""
|
||||
db_record = search_database(id=id)
|
||||
valid_code = code == db_record
|
||||
valid_code = code == db_record.codigo
|
||||
if valid_code:
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user