示例#1
0
def create_user(db: Session, user: UserCreate):
    user.password = get_password_hash(user.password)
    db_user = models.User(**user.dict())
    db.add(db_user)
    db.commit()
    db.refresh(db_user)
    return db_user
示例#2
0
async def register_user(user: schemas.UserCreate,
                        db: Session = Depends(get_db)):
    user.is_admin = False
    db_user = get_user_by_username(db, username=user.username)
    if db_user:
        raise HTTPException(status_code=400,
                            detail="Username already registered")
    # zero out cash amount for self-registered user
    user.cash = 0.0
    db_user = create_user(db=db, user=user)
    create_cash(db=db, amount=user.cash, userID=db_user.id)
    return db_user
示例#3
0
async def register_admin(user: schemas.UserCreate,
                         db: Session = Depends(get_db)):
    user.is_admin = True
    db_admin = get_admin(db)
    if db_admin:
        raise HTTPException(status_code=400, detail="Admin already registered")
    db_user = get_user_by_username(db, username=user.username)
    if db_user:
        raise HTTPException(status_code=400,
                            detail="Username already registered")
    db_user = create_user(db=db, user=user)
    return db_user
示例#4
0
def create_user(db: Session, user: schemas.UserCreate):
    if get_user_by_username(db, user.username) is not None:
        logging.info("user %s exists" % user.username)
        return None
    if user.groupname is None:
        logging.info("groupname not specified, use default")
        user.groupname = "default"
    elif get_group_by_groupname(db, user.groupname) is None:
        logging.warning("group %s undefined, use default" % user.groupname)
        user.groupname = "default"
    hashed = get_password_hash(user.password)
    db_user = models.User(username=user.username,
                          password=hashed,
                          firstname=user.firstname,
                          lastname=user.lastname,
                          groupname=user.groupname,
                          is_admin=user.is_admin)
    db.add(db_user)
    db.commit()
    db.refresh(db_user)
    return db_user
示例#5
0
 def mutate(
     root,
     info,
     username,
     password,
     fullname,
 ):
     hashed_password = bcrypt.hashpw(password.encode('utf-8'),
                                     bcrypt.gensalt())
     user = UserInfoSchema(username=username,
                           password=hashed_password,
                           fullname=fullname)
     ok = True
     db_user = crud.get_user_by_username(db, username=username)
     if db_user:
         raise GraphQLError("Username already registered")
     user_info = UserCreate(username=username,
                            password=password,
                            fullname=fullname)
     crud.create_user(db, user_info)
     return CreateUser(user=user, ok=ok)
示例#6
0
def create_user(db: Session, user: schemas.UserCreate):
    db_user = models.User(**user.dict())
    db.add(db_user)
    db.commit()
    db.refresh(db_user)
    return db_user
示例#7
0
def create_user(repo: Repository, user: schemas.UserCreate) -> models.User:
    user.password = crypto.hash_password(user.password)
    user_model = convert_to_model(user)
    return repo.add(user_model)
示例#8
0
async def create_user(user: schemas.UserCreate):
    fake_hashed_password = user.password + "notreallyhashed"
    db_user = users.insert().values(email=user.email,
                                    hashed_password=fake_hashed_password)
    user_id = await database.execute(db_user)
    return schemas.User(**user.dict(), id=user_id)