<commit_before>package nuclibook.routes;

import nuclibook.constants.C;
import nuclibook.constants.RequestType;
import nuclibook.entity_utils.SecurityUtils;
import nuclibook.models.Staff;
import nuclibook.server.HtmlRenderer;
import spark.Request;
import spark.Route;
import spark.Session;

public abstract class DefaultRoute implements Route {

	private RequestType requestType;
	private HtmlRenderer renderer;

	public DefaultRoute() {
		this(RequestType.GET);
	}

	public DefaultRoute(RequestType requestType) {
		// set request type
		this.requestType = requestType;

		// set up renderer
		renderer = new HtmlRenderer();
	}

	public void prepareToHandle(Request request) {
		// make sure this is a fresh start
		renderer.clearFields();
		renderer.clearCollections();

		// get current session and user
		Session session = request.session();
		Staff user = SecurityUtils.getCurrentUser(session);

		// set up login field
		if (SecurityUtils.checkLoggedIn(session)) {
			renderer.setField("logged-in", "yes");

			// automatic logout timer
			renderer.setField("automatic-timeout", C.AUTOMATIC_TIMEOUT);

			// add staff details;<commit_msg>Add csrf-token to default renderer<commit_after>package nuclibook.routes;

import nuclibook.constants.C;
import nuclibook.constants.RequestType;
import nuclibook.entity_utils.SecurityUtils;
import nuclibook.models.Staff;
import nuclibook.server.HtmlRenderer;
import spark.Request;
import spark.Route;
import spark.Session;

public abstract class DefaultRoute implements Route {

	private RequestType requestType;
	private HtmlRenderer renderer;

	public DefaultRoute() {
		this(RequestType.GET);
	}

	public DefaultRoute(RequestType requestType) {
		// set request type
		this.requestType = requestType;

		// set up renderer
		renderer = new HtmlRenderer();
	}

	public void prepareToHandle(Request request) {
		// make sure this is a fresh start
		renderer.clearFields();
		renderer.clearCollections();

		// get current session and user
		Session session = request.session();
		Staff user = SecurityUtils.getCurrentUser(session);

		// set up login field
		if (SecurityUtils.checkLoggedIn(session)) {
			renderer.setField("logged-in", "yes");

			// csrf token
			renderer.setField("csrf-token", SecurityUtils.getCsrfToken(session));

			// automatic logout timer
			renderer.setField("automatic-timeout", C.AUTOMATIC_TIMEOUT);

			// add staff details;
{'fraction_non_alphanumeric': 0.09666666666666666, 'fraction_numerical': 0.0, 'mean_word_length': 4.67612293144208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7480259', 'n_tokens_mistral': 758, 'n_tokens_neox': 708, 'n_words': 181}