Fixed registration and confirmation logs (#1734)

* Fixes issue where user's name and email would not appear in logs properly
* Closes #1706
This commit is contained in:
Alper Berber
2021-03-06 23:56:12 +03:00
committed by GitHub
parent 843546bfa8
commit 4125e7c00c
3 changed files with 20 additions and 6 deletions

View File

@@ -551,6 +551,7 @@ class ChallengeAttempt(Resource):
log( log(
"submissions", "submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [TOO FAST]", "[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [TOO FAST]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"), submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id, challenge_id=challenge_id,
kpm=kpm, kpm=kpm,
@@ -598,6 +599,7 @@ class ChallengeAttempt(Resource):
log( log(
"submissions", "submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [CORRECT]", "[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [CORRECT]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"), submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id, challenge_id=challenge_id,
kpm=kpm, kpm=kpm,
@@ -616,6 +618,7 @@ class ChallengeAttempt(Resource):
log( log(
"submissions", "submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [WRONG]", "[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [WRONG]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"), submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id, challenge_id=challenge_id,
kpm=kpm, kpm=kpm,
@@ -650,6 +653,7 @@ class ChallengeAttempt(Resource):
log( log(
"submissions", "submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [ALREADY SOLVED]", "[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [ALREADY SOLVED]",
name=user.name,
submission=request_data.get("submission", "").encode("utf-8"), submission=request_data.get("submission", "").encode("utf-8"),
challenge_id=challenge_id, challenge_id=challenge_id,
kpm=kpm, kpm=kpm,

View File

@@ -81,6 +81,7 @@ def confirm(data=None):
log( log(
"registrations", "registrations",
format="[{date}] {ip} - {name} initiated a confirmation email resend", format="[{date}] {ip} - {name} initiated a confirmation email resend",
name=user.name,
) )
return render_template( return render_template(
"confirm.html", infos=[f"Confirmation email sent to {user.email}!"] "confirm.html", infos=[f"Confirmation email sent to {user.email}!"]
@@ -140,7 +141,7 @@ def reset_password(data=None):
clear_user_session(user_id=user.id) clear_user_session(user_id=user.id)
log( log(
"logins", "logins",
format="[{date}] {ip} - successful password reset for {name}", format="[{date}] {ip} - successful password reset for {name}",
name=user.name, name=user.name,
) )
db.session.close() db.session.close()
@@ -323,6 +324,8 @@ def register():
log( log(
"registrations", "registrations",
format="[{date}] {ip} - {name} registered (UNCONFIRMED) with {email}", format="[{date}] {ip} - {name} registered (UNCONFIRMED) with {email}",
name=user.name,
email=user.email,
) )
email.verify_email_address(user.email) email.verify_email_address(user.email)
db.session.close() db.session.close()
@@ -333,7 +336,12 @@ def register():
): # We want to notify the user that they have registered. ): # We want to notify the user that they have registered.
email.successful_registration_notification(user.email) 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() db.session.close()
if is_teams_mode(): if is_teams_mode():
@@ -362,7 +370,7 @@ def login():
session.regenerate() session.regenerate()
login_user(user) login_user(user)
log("logins", "[{date}] {ip} - {name} logged in") log("logins", "[{date}] {ip} - {name} logged in", name=user.name)
db.session.close() db.session.close()
if request.args.get("next") and validators.is_safe_url( if request.args.get("next") and validators.is_safe_url(
@@ -373,7 +381,11 @@ def login():
else: else:
# This user exists but the password is wrong # 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") errors.append("Your username or password is incorrect")
db.session.close() db.session.close()
return render_template("login.html", errors=errors) return render_template("login.html", errors=errors)

View File

@@ -11,8 +11,6 @@ def log(logger, format, **kwargs):
logger = logging.getLogger(logger) logger = logging.getLogger(logger)
props = { props = {
"id": session.get("id"), "id": session.get("id"),
"name": session.get("name"),
"email": session.get("email"),
"date": time.strftime("%m/%d/%Y %X"), "date": time.strftime("%m/%d/%Y %X"),
"ip": get_ip(), "ip": get_ip(),
} }