Skip to content

Commit

Permalink
#429 Fix to return existing API key if password has not been changed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Only-bottle authored Dec 6, 2024
1 parent 354bf4c commit a668ef4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
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}"

0 comments on commit a668ef4

Please sign in to comment.