<%--
 ~
 ~ Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
 ~
 ~ This software is the property of WSO2 Inc. and its suppliers, if any.
 ~ Dissemination of any information or reproduction of any material contained
 ~ herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
 ~ You may not alter or remove any copyright or other notice from copies of this content."
 ~
--%>

<%@ page import="org.wso2.carbon.identity.application.authentication.endpoint.util.Constants" %>
<%@ page import="java.io.File" %>
<%@ page import="java.util.Map" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="includes/localize.jsp" %>

    <%
        request.getSession().invalidate();
        String queryString = request.getQueryString();
        Map<String, String> idpAuthenticatorMapping = null;
        if (request.getAttribute(Constants.IDP_AUTHENTICATOR_MAP) != null) {
            idpAuthenticatorMapping = (Map<String, String>) request.getAttribute(Constants.IDP_AUTHENTICATOR_MAP);
        }

        String errorMessage = AuthenticationEndpointUtil.i18n(resourceBundle,"error.fail");
        String authenticationFailed = "false";

        if (Boolean.parseBoolean(request.getParameter(Constants.AUTH_FAILURE))) {
            authenticationFailed = "true";

            if (request.getParameter(Constants.AUTH_FAILURE_MSG) != null) {
                errorMessage = request.getParameter(Constants.AUTH_FAILURE_MSG);

                 if (errorMessage.equalsIgnoreCase("authentication.fail.message")) {
                    errorMessage = AuthenticationEndpointUtil.i18n(resourceBundle,"error.fail");
                }
            }
        }
    %>

    <html>
        <head>
            <!-- header -->
            <%
                File headerFile = new File(getServletContext().getRealPath("extensions/header.jsp"));
                if (headerFile.exists()) {
            %>
            <jsp:include page="extensions/header.jsp"/>
            <% } else { %>
            <jsp:include page="includes/header.jsp"/>
            <% } %>

            <script src="js/scripts.js"></script>
            <script src="/totpauthenticationendpoint/js/scripts.js"></script>

            <!--[if lt IE 9]>
            <script src="js/html5shiv.min.js"></script>
            <script src="js/respond.min.js"></script>
            <![endif]-->
        </head>

        <body class="login-portal layout totp-portal-layout" onload="getLoginDiv()">

            <div class="page-wrapper">
                <main class="center-segment">

                    <div class="slogan-container">
                        <!-- product-title -->
                        <%
                            File productTitleFile = new File(getServletContext().getRealPath("extensions/product-title.jsp"));
                            if (productTitleFile.exists()) {
                        %>
                            <jsp:include page="extensions/product-title.jsp"/>
                        <% } else { %>
                            <jsp:include page="includes/product-title.jsp"/>
                        <% } %>

                        <h2 class="ui header portal-logo-tagline slogan-message">
                            <%=AuthenticationEndpointUtil.i18n(resourceBundle, "error.fail")%>
                        </h2>

                        <h4 class="ui header sub-tagline slogan-message">
                            <%=AuthenticationEndpointUtil.i18n(resourceBundle, "error.totp.not.enabled")%>
                        </h4>

                        <p class="portal-tagline-description">
                            Please write to <a href="mailto:beta@asgardeo.io" target="_blank">
                            <span class="orange-text-color button">beta@asgardeo.io</span>
                            </a> for assistance.
                        </p>
                    </div>

                    <div class="ui container medium aligned middle aligned">
                        <!-- illustration-->
                        <div class="thank-you-img">
                            <img class="ui fluid image" src="libs/themes/asgardio/assets/images/something-went-wrong.svg">
                        </div>
                    </div>

                </main>

                <!-- product-footer -->
                <%
                    File productFooterFile = new File(getServletContext().getRealPath("extensions/product-footer.jsp"));
                    if (productFooterFile.exists()) {
                %>
                    <jsp:include page="extensions/product-footer.jsp"/>
                <% } else { %>
                    <jsp:include page="includes/product-footer.jsp"/>
                <% } %>

                <!-- footer -->
                <%
                    File footerFile = new File(getServletContext().getRealPath("extensions/footer.jsp"));
                    if (footerFile.exists()) {
                %>
                    <jsp:include page="extensions/footer.jsp"/>
                <% } else { %>
                    <jsp:include page="includes/footer.jsp"/>
                <% } %>
            </div>
        </body>
    </html>
