<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.ubnt.data.Admin" %>
<%@ page import="com.ubnt.data.X" %>
<%@ page import="com.ubnt.ace.view.JspHelper" %>
<%
boolean expired = false;
boolean error = false;
boolean do_login = true;
//JspHelper.dumpHttpRequest(request);
if (request.getParameter("login")!=null) {
	X login = JspHelper.login(request, response);
	if (login==null) {
		error = true;
	}
}
else if (request.getParameter("recover")!=null) {
    do_login = false;
    X result = JspHelper.recover(request, response);
    if (result==null) {
        error = true;
    }
}

if (request.getParameter("api")!=null) {
    response.setStatus(error ? 401 : 200);
    return;
}

if (request.getParameter("expired")!=null) {
	expired = true;
}
%>
<fmt:bundle basename="messages">
<!doctype html>
<!--[if lt IE 7]> <html lang="en-us" class="no-js ie6"> <![endif]-->
<!--[if IE 7]>    <html lang="en-us" class="no-js ie7"> <![endif]-->
<!--[if IE 8]>    <html lang="en-us" class="no-js ie8"> <![endif]-->
<!--[if IE 9]>    <html lang="en-us" class="no-js ie9"> <![endif]-->
<!--[if gt IE 9]><!--> <html lang="en-us" class="no-js"> <!--<![endif]-->
<head>
	<title><fmt:message key="LoginTitle" /> - <fmt:message key="product.name" /></title>
	<jsp:include page="head_include.jsp">
		<jsp:param name="page" value="login" />
	</jsp:include>
</head>
<body class="unifi login-page">
    <!--Start: Page Content -->
    <div id="PageContent" class="page-content">
        <div id="Login">
            <!-- Start: Page Header -->
            <div id="PageHeader" class="page-header">
                <div class="header-logo"><fmt:message key="product.name" /></div>
            </div>
            <!-- End: Page Header -->

            <!-- Start: Content -->
            <div class="content-outer-container">
                <div class="content-inner-container">
                    <div class="content login" <% if (!do_login) { %> style="display:none" <% } %>>
			    <h1 class="section-title"><%
				    if (!error) {
				        if (expired) {%><fmt:message key="ExpiredLogin" /><%} else {%><fmt:message key="PleaseLogin" /><%}
				    } else { %><fmt:message key="InvalidAdminLogin" /><% } %></h1>
                        <!-- Start: Section Container -->
                        <div class="section-container login">
                            <form id="LoginForm" method="post" action="/login" class="ui-form">
                                <input id="Username" name="username" class="text-input<% if (error) { %> ui-state-error<% } %>" type="text" placeholder="Username"/>
                                <input id="Password" name="password" class="text-input<% if (error) { %> ui-state-error<% } %>" type="password" placeholder="Password" />
                                <input name="login" class="submit-input" type="submit" value="<fmt:message key='LoginSubmit' />" />
                            </form>
                        </div>
                        <!-- End: Section Container -->
                        <div class="section-container misc">
                            <a href="javascript:void(0)" class="recover">Forgot your password?</a>
                        </div>
                    </div>
                    <div class="content recover" <% if (do_login) { %> style="display:none" <% } %>>
                        <h1 class="section-title"><% if (do_login) { %>Reset Password<% } else if (error) { %>Invalid Email Address<% }else { %>An email has been sent<% } %></h1>
                        <!-- Start: Section Container -->
                        <div class="section-container">
                            <form id="ResetForm" method="post" action="/login" class="ui-form">
                                <p class="subtitle">Enter your email to reset your password.</p>
                                <input id="Email" name="email" class="text-input<% if (error) { %> ui-state-error<% } %>" type="text" placeholder="Email Address"/>
                                <input name="recover" class="submit-input" type="submit" value="Submit" />
                            </form>
                        </div>
                        <!-- End: Section Container -->
                        <div class="section-container misc">
                            <a href="javascript:void(0)" class="back">Back to login</a>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End: Content -->
        </div>
    </div>
    <!-- End: Page Content -->

    <script type="text/javascript">
        $(function() {
            $('#LoginForm input[name=username]').focus();
            $('.submit-input').button();
            $('#Login a.recover').click(function() {
                $('#Login div.content.login').hide();
                $('#Login div.content.recover').show();
                $('#Login input[name=email]').focus().select();
            });
            $('#Login a.back').click(function() {
                $('#Login div.content.login').show();
                $('#Login div.content.recover').hide();
                $('#Login input[name=username]').focus().select();
            });
        });
    </script>
</body>
</html>
</fmt:bundle>
