async def change_user_password( old_password: str, current_password: str, user: User = Depends(get_current_active_user)) -> User: if not verify_password(old_password, user.password): return Http400("Incorrect password") user.password = current_password user.save() return user
async def set_staff_user(id: int, active: bool) -> User: await User.filter(id=id).update(is_superuser=active) return await model.from_queryset_single(User.get(id=id))
async def update(id: int, user: UserUpdateSchema): await User.filter(id=id).update(**user.dict(exclude_unset=True)) return await model.from_queryset_single(User.get(id=id))
async def reset_user_password(id: int, password: str) -> User: await User.filter(id=id).update(password=hash_password(password)) return await model.from_queryset_single(User.get(id=id))
async def get(id: int = None): if (id is not None): return await model.from_queryset_single(User.get(id=id)) return await model.from_queryset(User.all())