Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def probe(
data: List[str] = Body(..., example=['111', '222']),
amount: int = Body(..., gt=5, example=10),
) -> List[int]:
del data, amount
return [1, 2, 3]
def probe(
data: List[str] = Body(..., example=['111', '222']),
amount: int = Body(..., gt=5, example=10),
) -> List[int]:
del data, amount
return [1, 2, 3]
async def register(
user_create: UserInCreate = Body(..., embed=True, alias="user"),
users_repo: UsersRepository = Depends(get_repository(UsersRepository)),
) -> UserInResponse:
if await check_username_is_taken(users_repo, user_create.username):
raise HTTPException(
status_code=HTTP_400_BAD_REQUEST, detail=strings.USERNAME_TAKEN
)
if await check_email_is_taken(users_repo, user_create.email):
raise HTTPException(
status_code=HTTP_400_BAD_REQUEST, detail=strings.EMAIL_TAKEN
)
user = await users_repo.create_user(**user_create.dict())
token = jwt.create_access_token_for_user(user, str(config.SECRET_KEY))
return UserInResponse(
async def update_current_user(
user: UserInUpdate = Body(..., embed=True),
current_user: User = Depends(get_current_user_authorizer()),
db: DataBase = Depends(get_database),
):
async with db.pool.acquire() as conn:
if user.username == current_user.username:
user.username = None
if user.email == current_user.email:
user.email = None
await check_free_username_and_email(conn, user.username, user.email)
async with conn.transaction():
dbuser = await update_user(conn, current_user.username, user)
return UserInResponse(user=User(**dbuser.dict(), token=current_user.token))
async def get_autocomplete(
query: QueryParams = Depends(QueryParams), extra: ExtraParams = Body(ExtraParams())
):
async def get_intentions():
if query.lang not in nlu_allowed_languages:
return None
if not query.nlu and not autocomplete_nlu_shadow_enabled:
return None
focus = None
if query.lon and query.lat:
focus = Point(query.lon, query.lat)
return await nlu_client.get_intentions(text=query.q, lang=query.lang, focus=focus)
autocomplete_response, intentions = await asyncio.gather(
bragi_client.autocomplete(query, extra), get_intentions()
def parse(content: str = Body(..., embed=True)):
parser = Song(content)
return {"html_content": parser.html}
def reset_password(token: str = Body(...), new_password: str = Body(...), db: Session = Depends(get_db)):
"""
Reset password
"""
email = verify_password_reset_token(token)
if not email:
raise HTTPException(status_code=400, detail="Invalid token")
user = crud.user.get_by_email(db, email=email)
if not user:
raise HTTPException(
status_code=404,
detail="The user with this username does not exist in the system.",
)
elif not crud.user.is_active(user):
raise HTTPException(status_code=400, detail="Inactive user")
hashed_password = get_password_hash(new_password)
user.hashed_password = hashed_password
def update_user_me(
*,
db: Session = Depends(get_db),
password: str = Body(None),
full_name: str = Body(None),
email: EmailStr = Body(None),
current_user: DBUser = Depends(get_current_active_user),
):
"""
Update own user.
"""
current_user_data = jsonable_encoder(current_user)
user_in = UserUpdate(**current_user_data)
if password is not None:
user_in.password = password
if full_name is not None:
user_in.full_name = full_name
if email is not None:
user_in.email = email
user = crud.user.update(db, user=current_user, user_in=user_in)
return user
async def update_current_user(
user_update: UserInUpdate = Body(..., embed=True, alias="user"),
current_user: User = Depends(get_current_user_authorizer()),
users_repo: UsersRepository = Depends(get_repository(UsersRepository)),
) -> UserInResponse:
if user_update.username and user_update.username != current_user.username:
if await check_username_is_taken(users_repo, user_update.username):
raise HTTPException(
status_code=HTTP_400_BAD_REQUEST, detail=strings.USERNAME_TAKEN
)
if user_update.email and user_update.email != current_user.email:
if await check_email_is_taken(users_repo, user_update.email):
raise HTTPException(
status_code=HTTP_400_BAD_REQUEST, detail=strings.EMAIL_TAKEN
)
user = await users_repo.update_user(user=current_user, **user_update.dict())
async def login(
user_login: UserInLogin = Body(..., embed=True, alias="user"),
users_repo: UsersRepository = Depends(get_repository(UsersRepository)),
) -> UserInResponse:
wrong_login_error = HTTPException(
status_code=HTTP_400_BAD_REQUEST, detail=strings.INCORRECT_LOGIN_INPUT
)
try:
user = await users_repo.get_user_by_email(email=user_login.email)
except EntityDoesNotExist as existence_error:
raise wrong_login_error from existence_error
if not user.check_password(user_login.password):
raise wrong_login_error
token = jwt.create_access_token_for_user(user, str(config.SECRET_KEY))
return UserInResponse(