<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:py="http://genshi.edgewall.org/"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  py:strip="True">

<py:match path="loginform" once="true">
<div id="loginform" class="login">
  <h3>${_('Log In')}</h3>
  <p py:content="str(select('*|text()'))" />
  <div py:choose="(request.identity and '_csrf_token' in request.identity) or request.environ.get('CSRF_AUTH_SESSION_ID')" py:strip="True">
    <div py:when="True" py:strip="True">
      <form action="${tg.url(came_from)}" method="post">
        <p><a href="http://en.wikipedia.org/wiki/CSRF">${_('CSRF attacks')}</a>
        ${_(''' are a means for a malicious website to make a request of another
        web server as the user who contacted the malicious web site.  The
        purpose of this page is to help protect your account and this server
        from attacks from such malicious web sites.  By clicking below, you are
        proving that you are a person rather than just the web browser
        forwarding your authentication cookies on behalf of a malicious
        website.''')}</p>
        <input type="submit" name="csrf_login" class="button"
          value="${_('I am a human')}" />
      </form>
    </div>
    <div py:otherwise="" py:strip="True">
      <form action="${tg.url('/login_handler', params=dict(came_from=came_from.encode('utf-8'), __logins=login_counter.encode('utf-8')))}" method="post" accept-charset="UTF-8" class="loginfields">
        <label for="login">${_('Username:')}</label>
        <input type="text" id="login" name="login" class="text" />
        <br />
        <label for="password">${_('Password:')}</label>
        <input type="password" id="password" name="password" class="text" />
        <input type="submit" id="submit" class="button" value="${_('Login')}" />
      </form>
    </div>
    <ul>
      <li><a href="${tg.url(tg.config.get('fas.url', 'https://admin.fedoraproject.org/accounts').rstrip('/') + '/user/resetpass')}">${_('Forgot Password?')}</a></li>
      <li><a href="${tg.url(tg.config.get('fas.url', 'https://admin.fedoraproject.org/accounts').rstrip('/') + '/user/new')}">${_('Sign Up')}</a></li>
    </ul>
  </div>
</div>
</py:match>

<py:match path="logintoolitem" once="true">
<div py:choose="">
  <li py:when="request.identity" class="toolitem">
    ${_('Welcome')}
    <div py:choose="str(select('@href'))" py:strip="True">
      <span py:when="''" py:choose="" py:strip="True">
        <span py:when="hasattr(request.identity['user'], 'display_name')"
          py:replace="request.identity['user'].display_name" />
        <span py:otherwise="" py:replace="request.identity['user'].user_name" />
      </span>
      <a py:otherwise="" href="${select('@href')}" py:choose="">
        <span py:when="hasattr(request.identity['user'], 'display_name')"
          py:replace="request.identity['user'].display_name" />
        <span py:otherwise=""
          py:replace="request.identity['user'].user_name" />
      </a>
    </div>
  </li>
  <li py:when="not request.identity and not request.environ.get('CSRF_AUTH_SESSION_ID')"
    id="login-toolitem" class="toolitem">
    ${_('You are not logged in')}
    <form action="${tg.url('/login/?came_from=%s' % tg.quote_plus('?'.join((request.environ.get('PATH_INFO', '/'), request.environ.get('QUERY_STRING')))))}" method="POST">
      <input type="submit" value="${_('Login')}" class="button" />
    </form>
  </li>
  <li py:when="not request.identity" id="login-toolitem" class="toolitem">
    ${_('CSRF protected')}
    <form action="${tg.url('?'.join((request.environ.get('PATH_INFO', '/'), request.environ.get('QUERY_STRING'))))}" method="POST">
      <input type="submit" value="${_('Verify Login')}" class="button" />
    </form>
  </li>
  <li py:if="request.identity or request.environ.get('CSRF_AUTH_SESSION_ID')"
    id="login-toolitem" class="toolitem">
    <form action="${tg.url('/logout_handler')}" method="POST">
      <input type="submit" value="${_('Logout')}" class="button" />
    </form>
  </li>
</div>
</py:match>
</html>
