Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
55 changes: 30 additions & 25 deletions src/impl/LleidaHacker/router_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

# from services.mail import send_registration_confirmation_email
from generated_src.lleida_hack_mail_api_client.models.mail_create import MailCreate
from src.error.AuthenticationException import AuthenticationException
from src.impl.LleidaHacker.schema import LleidaHackerCreate
from src.impl.LleidaHacker.schema import LleidaHackerGet
from src.impl.LleidaHacker.schema import LleidaHackerGetAll
from src.impl.LleidaHacker.schema import LleidaHackerUpdate
from src.impl.LleidaHacker.service import LleidaHackerService
from src.impl.Mail.client import MailClient
from src.impl.Mail.internall_templates import InternalTemplate
from src.utils.UserType import UserType
from src.utils.JWTBearer import JWTBearer
from src.utils.Token import AccesToken, BaseToken, RefreshToken, VerificationToken

Expand All @@ -22,31 +24,34 @@
lleidahacker_service = LleidaHackerService()
mail_client = MailClient()

#@router.post("/signup")
#def signup(payload: LleidaHackerCreate):
# new_lleidahacker = lleidahacker_service.add_lleidahacker(payload)
# access_token = AccesToken(new_lleidahacker).user_set()
# refresh_token = RefreshToken(new_lleidahacker).user_set()
# verification_token = VerificationToken(new_lleidahacker).user_set()
#
# mail = mail_client.create_mail(
# MailCreate(
# template_id=mail_client.get_internall_template_id(
# InternalTemplate.USER_CREATED
# ),
# receiver_id=str(new_lleidahacker.id),
# receiver_mail=new_lleidahacker.email,
# subject="Your User Hacker was created",
# fields=f"{new_lleidahacker.name},{verification_token}",
# )
# )
# mail_client.send_mail_by_id(mail.id)
# return {
# "success": True,
# "user_id": new_lleidahacker.id,
# "access_token": access_token,
# "refresh_token": refresh_token,
# }
@router.post("/signup")
def signup(payload: LleidaHackerCreate, token: BaseToken = Depends(JWTBearer())):
if not token.check([UserType.LLEIDAHACKER]):
raise AuthenticationException("Not authorized")

Comment on lines +28 to +31
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The signup endpoint should not require authentication. Requiring a JWT token to create a new user account creates a chicken-and-egg problem where users cannot sign up without already being authenticated. This breaks the typical user registration flow.

Suggested change
def signup(payload: LleidaHackerCreate, token: BaseToken = Depends(JWTBearer())):
if not token.check([UserType.LLEIDAHACKER]):
raise AuthenticationException("Not authorized")
def signup(payload: LleidaHackerCreate):

Copilot uses AI. Check for mistakes.
new_lleidahacker = lleidahacker_service.add_lleidahacker(payload)
access_token = AccesToken(new_lleidahacker).user_set()
refresh_token = RefreshToken(new_lleidahacker).user_set()
verification_token = VerificationToken(new_lleidahacker).user_set()

mail = mail_client.create_mail(
MailCreate(
template_id=mail_client.get_internall_template_id(
InternalTemplate.USER_CREATED
),
receiver_id=str(new_lleidahacker.id),
receiver_mail=new_lleidahacker.email,
subject="Your User Hacker was created",
fields=f"{new_lleidahacker.name},{verification_token}",
)
)
mail_client.send_mail_by_id(mail.id)
return {
"success": True,
"user_id": new_lleidahacker.id,
"access_token": access_token,
"refresh_token": refresh_token,
}


@router.get("/all", response_model=List[LleidaHackerGet])
Expand Down
2 changes: 1 addition & 1 deletion src/impl/LleidaHacker/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def add_lleidahacker(self, payload: LleidaHackerCreate):
**payload.model_dump(exclude={"config"}), code=generate_user_code()
)
new_lleidahacker.password = get_password_hash(payload.password)
new_lleidahacker.active = True
new_lleidahacker.active = False # IMPORTANT DO NOT ACTIVATE USER AUTOMATICALLY !!!!!!!!!!!!! @Big_Lolo
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment uses excessive punctuation and mentions a specific person. Comments should be professional and explain the reasoning rather than using emphatic styling. Consider: '# Users must be manually activated by administrators for security reasons' or reference a configuration setting/documentation.

Suggested change
new_lleidahacker.active = False # IMPORTANT DO NOT ACTIVATE USER AUTOMATICALLY !!!!!!!!!!!!! @Big_Lolo
new_lleidahacker.active = False # Users must be manually activated by administrators for security reasons

Copilot uses AI. Check for mistakes.

new_config = UserConfig(**payload.config.model_dump())

Expand Down
Loading