<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
	<link type="text/css" rel="stylesheet" href="../../static/css/bookstore.css" />
	<link type="text/css" rel="stylesheet" href="../../static/css/bootstrap.min.css" />
</head>

<body>

	<th:block th:fragment="loginout">
		<div id="bookstore-loginout">
		
			<!--/*
			HTML element blocks when a user is authenticated

			** START: logout elements **
			*/-->
			<div sec:authorize="isAuthenticated()">
				<div>
					<form th:action="@{__${@Pages.LOGOUT}__}" method="post">
						<button type="submit" class="btn btn-info"
						th:href="@{__${@Pages.LOGOUT}__}"
						th:text="${#messages.msgOrNull('button.page.logout')} ?: 'button.page.logout'">
						button.page.logout
						</button>
					</form>
				</div>
				<p class="mt-2"
				th:text="${#httpServletRequest.remoteUser} ? (${#messages.msgOrNull('page.text.list.authenticated')} ?: 'page.text.list.authenticated') + ' ' + ${#httpServletRequest.remoteUser} : 'httpServletRequest.remoteUser'">
				page.text.list.authenticated httpServletRequest.remoteUser
				</p>
			</div>
			<!--/*
			** END: logout elements **
			*/-->

			<!--/*
			HTML element blocks when a user is not authenticated

			** START: login elements **
			*/-->
			<div sec:authorize="isAnonymous()">
			
				<form th:action="@{__${@Pages.LOGIN}__}" method="post">
				
					<!--/*
					Keep normal id field as fallback (i.e. for defining plain HTML CSS styles)
					*/-->
					<input type="text"
					id="b_username"
					th:id="${@environment.getProperty('auth.field.username')}"
					th:name="${@environment.getProperty('auth.field.username')}"
					placeholder="User name"
					th:placeholder="#{auth.field.placeholder.username}"
					/>
					
					<!--/*
					Keep normal id field as fallback (i.e. for defining plain HTML CSS styles)
					*/-->
					<input type="password"
					id="b_password"
					th:id="${@environment.getProperty('auth.field.password')}"
					th:name="${@environment.getProperty('auth.field.password')}"
					placeholder="Password"
					th:placeholder="#{auth.field.placeholder.password}"
					/>

					<!--/*
					This element is filled only when authentication fails
					*/-->
					<p th:text="${authfailure}"></p>

					<div class="mt-2">
						<button type="submit" class="btn btn-info"
						name="login-submit" id="login-submit"
						th:text="${#messages.msgOrNull('button.page.login')} ?: 'button.page.login'">
						button.page.login
						</button>
					</div>
				</form>
				<th:block th:replace="${@environment.getActiveProfiles()[0] == 'dev'} ? ~{fragments/devusers :: devusers} : _"/>
			</div>
			<!--/*
			** END: login elements **
			*/-->
			<div th:if="${@environment.getActiveProfiles()[0] == 'dev'}" style="margin: 10px 0;">
				<a th:href="@{__${@Pages.H2CONSOLE}__}">H2 database console access</a>
			</div>
		</div>
	</th:block>
</body>
</html>