Skip to content

Sourcery Starbot ⭐ refactored rohitkumar93/full-stack-fastapi-postgresql #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/full-stack-fastapi-postgresql master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -39 to +41
with open(Path(settings.EMAIL_TEMPLATES_DIR) / "test_email.html") as f:
template_str = f.read()
template_str = Path(
Path(settings.EMAIL_TEMPLATES_DIR) / "test_email.html"
).read_text()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function send_test_email refactored with the following changes:

  • Simplify basic file reads with pathlib (path-read)

Comment on lines -52 to +55
with open(Path(settings.EMAIL_TEMPLATES_DIR) / "reset_password.html") as f:
template_str = f.read()
template_str = Path(
Path(settings.EMAIL_TEMPLATES_DIR) / "reset_password.html"
).read_text()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function send_reset_password_email refactored with the following changes:

  • Simplify basic file reads with pathlib (path-read)

Comment on lines -73 to +77
with open(Path(settings.EMAIL_TEMPLATES_DIR) / "new_account.html") as f:
template_str = f.read()
template_str = Path(
Path(settings.EMAIL_TEMPLATES_DIR) / "new_account.html"
).read_text()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function send_new_account_email refactored with the following changes:

  • Simplify basic file reads with pathlib (path-read)

Comment on lines -95 to -98
encoded_jwt = jwt.encode(
{"exp": exp, "nbf": now, "sub": email}, settings.SECRET_KEY, algorithm="HS256",
return jwt.encode(
{"exp": exp, "nbf": now, "sub": email},
settings.SECRET_KEY,
algorithm="HS256",
)
return encoded_jwt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generate_password_reset_token refactored with the following changes:

Comment on lines -40 to -43
user = crud.user.get(db, id=token_data.sub)
if not user:
if user := crud.user.get(db, id=token_data.sub):
return user
else:
raise HTTPException(status_code=404, detail="User not found")
return user
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_current_user refactored with the following changes:

encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
return jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_access_token refactored with the following changes:

Comment on lines -41 to -46
user = self.get_by_email(db, email=email)
if not user:
return None
if not verify_password(password, user.hashed_password):
if user := self.get_by_email(db, email=email):
return user if verify_password(password, user.hashed_password) else None
else:
return None
return user
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CRUDUser.authenticate refactored with the following changes:

headers = {"Authorization": f"Bearer {auth_token}"}
return headers
return {"Authorization": f"Bearer {auth_token}"}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function user_authentication_headers refactored with the following changes:

Comment on lines -42 to +47
user = crud.user.get_by_email(db, email=email)
if not user:
user_in_create = UserCreate(username=email, email=email, password=password)
user = crud.user.create(db, obj_in=user_in_create)
else:
if user := crud.user.get_by_email(db, email=email):
user_in_update = UserUpdate(password=password)
user = crud.user.update(db, db_obj=user, obj_in=user_in_update)

else:
user_in_create = UserCreate(username=email, email=email, password=password)
user = crud.user.create(db, obj_in=user_in_create)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function authentication_token_from_email refactored with the following changes:

headers = {"Authorization": f"Bearer {a_token}"}
return headers
return {"Authorization": f"Bearer {a_token}"}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_superuser_token_headers refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant