Skip to content

Commit

Permalink
Fixed registration and confirmation logs (CTFd#1734)
Browse files Browse the repository at this point in the history
* Fixes issue where user's name and email would not appear in logs properly
* Closes CTFd#1706
  • Loading branch information
alperb authored Mar 6, 2021
1 parent 843546b commit 4125e7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CTFd/api/v1/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ def post(self):
log(
"submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [TOO FAST]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id,
kpm=kpm,
Expand Down Expand Up @@ -598,6 +599,7 @@ def post(self):
log(
"submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [CORRECT]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id,
kpm=kpm,
Expand All @@ -616,6 +618,7 @@ def post(self):
log(
"submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [WRONG]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id,
kpm=kpm,
Expand Down Expand Up @@ -650,6 +653,7 @@ def post(self):
log(
"submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [ALREADY SOLVED]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id,
kpm=kpm,
Expand Down
20 changes: 16 additions & 4 deletions CTFd/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def confirm(data=None):
log(
"registrations",
format="[{date}] {ip} - {name} initiated a confirmation email resend",
name=user.name,
)
return render_template(
"confirm.html", infos=[f"Confirmation email sent to {user.email}!"]
Expand Down Expand Up @@ -140,7 +141,7 @@ def reset_password(data=None):
clear_user_session(user_id=user.id)
log(
"logins",
format="[{date}] {ip} - successful password reset for {name}",
format="[{date}] {ip} - successful password reset for {name}",
name=user.name,
)
db.session.close()
Expand Down Expand Up @@ -323,6 +324,8 @@ def register():
log(
"registrations",
format="[{date}] {ip} - {name} registered (UNCONFIRMED) with {email}",
name=user.name,
email=user.email,
)
email.verify_email_address(user.email)
db.session.close()
Expand All @@ -333,7 +336,12 @@ def register():
): # We want to notify the user that they have registered.
email.successful_registration_notification(user.email)

log("registrations", "[{date}] {ip} - {name} registered with {email}")
log(
"registrations",
format="[{date}] {ip} - {name} registered with {email}",
name=user.name,
email=user.email,
)
db.session.close()

if is_teams_mode():
Expand Down Expand Up @@ -362,7 +370,7 @@ def login():
session.regenerate()

login_user(user)
log("logins", "[{date}] {ip} - {name} logged in")
log("logins", "[{date}] {ip} - {name} logged in", name=user.name)

db.session.close()
if request.args.get("next") and validators.is_safe_url(
Expand All @@ -373,7 +381,11 @@ def login():

else:
# This user exists but the password is wrong
log("logins", "[{date}] {ip} - submitted invalid password for {name}")
log(
"logins",
"[{date}] {ip} - submitted invalid password for {name}",
name=user.name,
)
errors.append("Your username or password is incorrect")
db.session.close()
return render_template("login.html", errors=errors)
Expand Down
2 changes: 0 additions & 2 deletions CTFd/utils/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def log(logger, format, **kwargs):
logger = logging.getLogger(logger)
props = {
"id": session.get("id"),
"name": session.get("name"),
"email": session.get("email"),
"date": time.strftime("%m/%d/%Y %X"),
"ip": get_ip(),
}
Expand Down

0 comments on commit 4125e7c

Please sign in to comment.