Skip to content

Commit

Permalink
Remove rotas não utilizadas
Browse files Browse the repository at this point in the history
  • Loading branch information
nYCSTs committed Dec 4, 2023
1 parent 624e39b commit 54acfe3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
30 changes: 12 additions & 18 deletions src/controller/authController.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,18 @@ async def login(data: authSchema.UserLogin, db: Session = Depends(get_db)):

@auth.post("/login/social")
async def login_social(user: authSchema.UserSocial, db: Session = Depends(get_db)):

existing_user = userRepository.get_user_by_email(db, user.email)
if existing_user is None:
new_user = userRepository.create_user_social(db, user.name, user.email)
access_token = security.create_access_token(data={"id": new_user.id, "email": new_user.email, "role": new_user.role})
return JSONResponse(
status_code=200,
content={
"access_token": access_token,
"token_type": "bearer",
"is_new_user": True,
"user_id": new_user.id
}
)
else:
access_token = security.create_access_token(data={"id": existing_user.id, "email": existing_user.email, "role": existing_user.role})
refresh_token = security.create_refresh_token(data={ "id": existing_user.id })
return JSONResponse(status_code=200, content={"access_token": access_token, "refresh_token": refresh_token, "token_type": "bearer", "is_new_user": False})
existing_user = userRepository.get_user_by_email(db, user.email)

if existing_user is None:
new_user = userRepository.create_user_social(db, user.name, user.email)
access_token = security.create_access_token(data={"id": new_user.id, "email": new_user.email, "role": new_user.role})

return JSONResponse(status_code=200, content={ "access_token": access_token, "token_type": "bearer", "is_new_user": True, "user_id": new_user.id })
else:
access_token = security.create_access_token(data={"id": existing_user.id, "email": existing_user.email, "role": existing_user.role})
refresh_token = security.create_refresh_token(data={ "id": existing_user.id })

return JSONResponse(status_code=200, content={ "access_token": access_token, "refresh_token": refresh_token, "token_type": "bearer", "is_new_user": False })

@auth.post("/refresh", response_model=authSchema.RefreshTokenResponse)
def refresh_token(token: dict = Depends(security.verify_token)):
Expand Down
21 changes: 0 additions & 21 deletions src/repository/userRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,6 @@ def create_user_social(db: Session, name, email):
db.refresh(db_user)
return db_user

async def get_or_create_user(email: str, name: str, db: Session):

user = userRepository.get_user_by_email(db, email)

if user is None:
user = userRepository.create_by_login(db, name=name, email=email)

return user

def create_by_login(db: Session, name, email):

db_user = userModel.User(
name=name,
email=email
)
db.add(db_user)
db.commit()
db.refresh(db_user)
return db_user


def update_user(db: Session, db_user: userSchema.User, user: userSchema.UserUpdate):
user_data = user.dict(exclude_unset=True)
for key, value in user_data.items():
Expand Down

0 comments on commit 54acfe3

Please sign in to comment.