Skip to content
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

#429 Fix to return existing API key if password has not been changed #430

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app/services/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sqlalchemy.orm import Session

from app.api.v1.schemas.user import ApiKeyPayload, CreditInfo, DetailData, UserPayload
from app.utils import generate_id
from netspresso.netspresso import NetsPresso
from netspresso.utils.db.generate_uuid import generate_uuid
from netspresso.utils.db.models.user import User
from netspresso.utils.db.repositories.user import user_repository

Expand All @@ -19,17 +19,15 @@ def create_user(self, db: Session, email: str, password: str, api_key: str):
return user

def generate_api_key(self, db: Session, email: str, password: str) -> ApiKeyPayload:
generated_id = generate_id(entity="user")
generated_id = generate_uuid(entity="user")

user = user_repository.get_by_email(db=db, email=email)

if user:
if user.password != password:
user.password = password
user.api_key = generated_id
elif user.api_key != generated_id:
user.api_key = generated_id
user = user_repository.save(db=db, model=user)
user = user_repository.save(db=db, model=user)
else:
user = self.create_user(
db=db,
Expand Down
2 changes: 1 addition & 1 deletion app/utils.py → netspresso/utils/db/generate_uuid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nanoid import generate


def generate_id(entity: str, size: int = 10) -> str:
def generate_uuid(entity: str, size: int = 10) -> str:
nano_id = generate(size=size)
return f"{entity}_{nano_id}"
Loading