Skip to content

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

Open
SourceryAI wants to merge 1 commit intorohitkumar93:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored rohitkumar93/full-stack-fastapi-postgresql#1
SourceryAI wants to merge 1 commit intorohitkumar93:masterfrom
SourceryAI:master

Conversation

@SourceryAI
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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:

to_encode = {"exp": expire, "sub": str(subject)}
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
Copy Markdown
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
Copy Markdown
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:

auth_token = response["access_token"]
headers = {"Authorization": f"Bearer {auth_token}"}
return headers
return {"Authorization": f"Bearer {auth_token}"}
Copy link
Copy Markdown
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
Copy Markdown
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:

a_token = tokens["access_token"]
headers = {"Authorization": f"Bearer {a_token}"}
return headers
return {"Authorization": f"Bearer {a_token}"}
Copy link
Copy Markdown
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