package es.uv.saic.web;

import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class KeepAliveController {

	/*
	 * Simple endpoint to check if the user session is still active.
	 * Returns "alive" if the user
	 * is authenticated, "0" otherwise.
	 * @param model
	 * @param auth Authentication
	 * @return "alive" if the user is
	 * authenticated, "0" otherwise.
	 */
	@GetMapping("/keepalive")
	@ResponseBody
	public String getItems(Model model, Authentication auth) {
		if(auth == null) {
			return "0";
		}
		return "alive";
	}
}
