<commit_before>#include "sim.h"

#ifndef STYLES_CSS_HASH
# define STYLES_CSS_HASH ""
#endif
#ifndef JQUERY_JS_HASH
# define JQUERY_JS_HASH ""
#endif
#ifndef SCRIPTS_JS_HASH
# define SCRIPTS_JS_HASH ""
#endif

void Sim::page_template(StringView title, StringView styles, StringView scripts)
{
	STACK_UNWINDING_MARK;

	// Protect from clickjacking
	resp.headers["X-Frame-Options"] = "DENY";
	resp.headers["Content-Security-Policy"] = "frame-ancestors 'none'";
	// Protect from XSS attack
	resp.headers["X-XSS-Protection"] = "1; mode=block";

	resp.headers["Content-Type"] = "text/html; charset=utf-8";
	resp.content = "";

	append("<!DOCTYPE html>"
		"<html lang=\"en\">"
			"<head>"
				"<meta charset=\"utf-8\">"
				"<title>", htmlEscape(title), "</title>"
				"<link rel=\"stylesheet\" type=\"text/css\""
					" href=\"/kit/styles.css?" STYLES_CSS_HASH "\">"
				"<script src=\"/kit/jquery.js?" JQUERY_JS_HASH "\"></script>"
				"<script src=\"/kit/scripts.js?" SCRIPTS_JS_HASH "\"></script>"
				"<link rel=\"shortcut icon\" href=\"/kit/img/favicon.png\">");

	if (scripts.size())
		append("<script>", scripts, "</script>");

	if (styles.size())
		append("<style>", styles, "</style>");

	append("</head>"
			"<body>"
				"<div class=\"navbar\">"
					"<div>"
						"<a href=\"/\" class=\"brand\">SIM beta</a>"
						"<script>"
							"a_view_button('/c', 'Contests', undefined,"
								"contest_chooser).appendTo('.navbar > div');"
							"$('.navbar > div > script').remove();"
						"</script>"
						"<a href=\"/p\">Problems</a>");

	if (session_open()) {
		if (uint(users_get_permissions() & UserPermissions::VIEW_ALL))
			append("<a href=\"/u\">Users</a>");

		if (uint(submissions_get_permissions() &
			SubmissionPermissions::VIEW_ALL))
		{
			append("<a href=\"/s\">Submissions</a>");
		}

		if (uint(jobs_get_permissions() & JobPermissions::VIEW_ALL))
			append("<a href=\"/jobs\">Job queue</a>");

		if (session_user_type == UserType::ADMIN)
			append("<a href=\"/logs\">Logs</a>");
	}

	append("</div>"
			"<div class=\"rightbar\">"
				"<time id=\"clock\">", date("%H:%M:%S"),
					"<sup>UTC</sup></time>");

	if (session_is_open)
		append("<div class=\"dropmenu down\">"
				"<a class=\"user dropmenu-toggle\">"
					"<strong>", htmlEscape(session_username), "</strong>"
				"</a>"
				"<ul>"
					"<a href=\"/u/", session_user_id, "\">My profile</a>"
					"<a href=\"/u/", session_user_id, "/edit\">"
						"Edit profile</a>"
					"<a href=\"/u/", session_user_id, "/change-password\">"
						"Change password</a>"
					"<a href=\"/logout\">Logout</a>"
				"</ul>"
				"</div>");

	else
		append("<a href=\"/login\"><strong>Log in</strong></a>"
			"<a href=\"/signup\">Sign up</a>");

	append("</div>"
		"</div>"
		"<div class=\"notifications\">", notifications, "</div>");<commit_msg>Fixed server error 500 when an error was to be shown during logging in or signing up<commit_after>#include "sim.h"

#ifndef STYLES_CSS_HASH
# define STYLES_CSS_HASH ""
#endif
#ifndef JQUERY_JS_HASH
# define JQUERY_JS_HASH ""
#endif
#ifndef SCRIPTS_JS_HASH
# define SCRIPTS_JS_HASH ""
#endif

void Sim::page_template(StringView title, StringView styles, StringView scripts)
{
	STACK_UNWINDING_MARK;

	// Protect from clickjacking
	resp.headers["X-Frame-Options"] = "DENY";
	resp.headers["Content-Security-Policy"] = "frame-ancestors 'none'";
	// Protect from XSS attack
	resp.headers["X-XSS-Protection"] = "1; mode=block";

	resp.headers["Content-Type"] = "text/html; charset=utf-8";
	resp.content = "";

	append("<!DOCTYPE html>"
		"<html lang=\"en\">"
			"<head>"
				"<meta charset=\"utf-8\">"
				"<title>", htmlEscape(title), "</title>"
				"<link rel=\"stylesheet\" type=\"text/css\""
					" href=\"/kit/styles.css?" STYLES_CSS_HASH "\">"
				"<script src=\"/kit/jquery.js?" JQUERY_JS_HASH "\"></script>"
				"<script src=\"/kit/scripts.js?" SCRIPTS_JS_HASH "\"></script>"
				"<link rel=\"shortcut icon\" href=\"/kit/img/favicon.png\">");

	if (scripts.size())
		append("<script>", scripts, "</script>");

	if (styles.size())
		append("<style>", styles, "</style>");

	append("</head>"
			"<body>"
				"<div class=\"navbar\">"
					"<div>"
						"<a href=\"/\" class=\"brand\">SIM beta</a>"
						"<script>"
							"a_view_button('/c', 'Contests', undefined,"
								"contest_chooser).appendTo('.navbar > div');"
							"$('.navbar > div > script').remove();"
						"</script>"
						"<a href=\"/p\">Problems</a>");

	if (session_open()) {
		if (uint(users_get_permissions() & UserPermissions::VIEW_ALL))
			append("<a href=\"/u\">Users</a>");

		if (uint(submissions_get_permissions() &
			SubmissionPermissions::VIEW_ALL))
		{
			append("<a href=\"/s\">Submissions</a>");
		}

		if (uint(jobs_get_permissions() & JobPermissions::VIEW_ALL))
			append("<a href=\"/jobs\">Job queue</a>");

		if (session_user_type == UserType::ADMIN)
			append("<a href=\"/logs\">Logs</a>");
	}

	append("</div>"
			"<div class=\"rightbar\">"
				"<time id=\"clock\">", date("%H:%M:%S"),
					"<sup>UTC</sup></time>");

	if (session_is_open)
		append("<div class=\"dropmenu down\">"
				"<a class=\"user dropmenu-toggle\">"
					"<strong>", htmlEscape(session_username), "</strong>"
				"</a>"
				"<ul>"
					"<a href=\"/u/", session_user_id, "\">My profile</a>"
					"<a href=\"/u/", session_user_id, "/edit\">"
						"Edit profile</a>"
					"<a href=\"/u/", session_user_id, "/change-password\">"
						"Change password</a>"
					"<a href=\"/logout\">Logout</a>"
				"</ul>"
				"</div>");

	else
		append("<a href=\"/login\"><strong>Log in</strong></a>"
			"<a href=\"/signup\">Sign up</a>");

	append("</div>"
		"</div>"
		"<div class=\"notifications\">", notifications, "</div>");
#ifdef DEBUG
	notifications.clear();
#endif
{'fraction_non_alphanumeric': 0.24602481216145378, 'fraction_numerical': 0.0015726017822820198, 'mean_word_length': 3.7581047381546133, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3602202', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2102, 'n_words': 377}