Beispiel #1
0
async def post_user(payload: UserIn) -> int:
    user = User(full_name=payload.full_name,
                email=payload.email,
                phone=payload.phone,
                tasks=[])
    await user.save(
    )  # how does this function work? -> creates/Updates the current model object
    return user.id
Beispiel #2
0
async def post_task(payload: TaskIn) -> int:
    task = User(name=payload.name,
                description=payload.description,
                rank=payload.rank,
                completed=payload.completed,
                completion_time=payload.completion_time,
                user_id=payload.user_id)
    await task.save()
    return task.id
def _create_user(first_name: str, last_name: str) -> User:
    user = User()
    user.first_name = first_name
    user.last_name = last_name
    user.username = f"{first_name}_{last_name}"
    user.email = f"{first_name}_{last_name}@southwestern.edu"
    user.profile_url = f"https://cdn.google.com/{first_name}_{last_name}.png"
    return user
Beispiel #4
0
async def post_user(payload: UserAuth) -> int:
    print(payload.full_name)
    user = User(full_name=payload.full_name,
                email=payload.email,
                phone=payload.phone,
                username=payload.username,
                disabled=payload.disabled,
                hashed_password=get_password_hash(payload.password))
    await user.save()
    return user.id
Beispiel #5
0
async def create_user(payload: dict) -> User_Pydantic:
    user = User(
        username=payload['username'],
        email=payload['email'],
        password_hash=payload['password'],
        major=payload['major'],
        first_name=payload['first_name'],
        last_name=payload['last_name'],
        m_number=payload['m_number'],
    )
    await user.save()
    return user
Beispiel #6
0
async def put_user_id(
        user_in: UserIn_Pydnatic,
        user_id: int,
        current_superuser: User = Depends(find_current_superuser),
):
    update_dict = user_in.dict(exclude_unset=True)
    del update_dict["categories_ids"]
    await User.filter(id=user_id).update(**update_dict)
    user = await User.filter(id=user_id).prefetch_related("creds").first()
    await user.update_calendar()
    await user.categories.clear()
    categories = await Category.filter(id__in=user_in.categories_ids).all()
    await user.categories.add(*categories)
    return await User_Pydnatic.from_queryset_single(User.get(id=user_id))
Beispiel #7
0
async def get_or_create_user(flow: google_auth_oauthlib.flow.Flow, info,
                             Authorize: AuthJWT) -> UserCreate:
    google_creds = flow.credentials

    user = await User.get_or_none(email=info["email"]).first()

    if user is None:
        user = User()
        user.username = info["email"].split("@")[0]
        user.first_name = info["given_name"]
        user.last_name = info["family_name"]
        user.email = info["email"]

    user.profile_url = info["picture"]
    await user.save()
    creds, bo = await Credentials.get_or_create(user=user)
    creds.json_field = google_creds.to_json()
    await creds.save()

    return UserCreate(
        user=await User_Pydnatic.from_tortoise_orm(user),
        access_token=Authorize.create_access_token(subject=user.email),
        refresh_token=Authorize.create_refresh_token(subject=user.email),
    )
Beispiel #8
0
async def get_user_id(user_id: int,
                      current_user: User = Depends(find_current_user)):
    return await User_Pydnatic.from_queryset_single(User.get(id=user_id))
Beispiel #9
0
async def patch_current_user(user_update: NormalUserUpdate,
                             current_user: User = Depends(find_current_user)):
    await User.get(id=current_user.id
                   ).update(**user_update.dict(exclude_unset=True))
    return await User_Pydnatic.from_queryset_single(
        User.get(id=current_user.id))