[% SET username = c.user.get_from_storage.username %]
[% IF username %]

  <center>
    <p>
      <h5>Logged in as: [% username %]</h5>
    </p>
    <p>
      <h4><a target="_top" href="/auth/logout?redirect=/auth/login">Logout</a></h4>
    </p>
  </center>
  <br>

[% ELSE %]

  <script type="text/javascript">
    Ext.onReady(function(){
      var hiddenEl = Ext.get('redirect');
      // Pass the current window.location.href data through the login in 'target_href'
      //  this is where the auth controller will redirect to after login:
      var persist_redirect_target = function() {
        if(hiddenEl) {
          // Set the redirect to the current local href *unless* 
          // we're at the default url path '/auth/login'
          var l = window.location;
          hiddenEl.dom.setAttribute('value',
            (l.pathname == '/auth/login') 
            ? '/' : [l.pathname,l.search,l.hash].join('') 
          );
        }
      };
      
      persist_redirect_target();
      window.onhashchange = persist_redirect_target;
      
      // Focus the username field:
      var el = Ext.get('username');
      if(el) { el.focus(); }
    });
  </script>

  <form action="[% form_post_url %]" method="post" class="nice" id="l_form">

    <input type="hidden" id="redirect" name="redirect" value="">

    <div class="sepH_c">
      <div class="elVal">
        <label for="username">Username</label>
        <input type="text" id="username"  name="username" class="oversize expand input-text" />
      </div>
      <div class="elVal">
        <label for="password">Password</label>
        <input type="password" id="password"  name="password" class="oversize expand input-text" />
      </div>
    </div>

    <div class="cf" style="padding-bottom:30px;">
      <!--
      <label for="remember" class="left"><input type="checkbox" id="remember"> Remember me</label>
      -->
      <input type="submit" class="button small radius right black" value="Login" />
    </div>

  </form>

[% END %]