36 lines
837 B
Python
36 lines
837 B
Python
from sqlalchemy.orm import Session
|
|
from passlib.context import CryptContext
|
|
|
|
from . import models, schemas
|
|
|
|
|
|
def get_user(db: Session, name: str):
|
|
return (db
|
|
.query(models.User)
|
|
.filter(models.User.name == name).first())
|
|
|
|
|
|
def create_user(
|
|
db: Session,
|
|
user: schemas.UserCreate,
|
|
crypt_context: CryptContext
|
|
):
|
|
db_user = models.User(
|
|
name=user.name,
|
|
password=crypt_context.hash(user.password),
|
|
)
|
|
db.add(db_user)
|
|
db.commit()
|
|
db.refresh(db_user)
|
|
return db_user
|
|
|
|
|
|
def add_user_capability(db: Session, user_name: str, capability: str):
|
|
db_user_capability = models.UserCapability(
|
|
user_name=user_name,
|
|
capability=capability,
|
|
)
|
|
db.add(db_user_capability)
|
|
db.commit()
|
|
db.refresh(db_user_capability)
|
|
return db_user_capability
|