[% SET mnt_pfx = c.mount_url %]
[% 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="[% mnt_pfx %]/auth/logout?redirect=[% mnt_pfx %]/auth/login">Logout</a></h4>
    </p>
  </center>
  <br>

[% ELSE %]

  <script type="text/javascript">
    var loginFormOnReadyFn = function() {
      var hiddenRedirectEl = document.getElementById('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(hiddenRedirectEl) {
          // Set the redirect to the current local href *unless* 
          // we're at the default url path '/auth/login'
          var l = window.location;
          hiddenRedirectEl.setAttribute('value',
            (l.pathname == '[% mnt_pfx %]/auth/login' && ! l.search) 
            ? '/' : [l.pathname,l.search,l.hash].join('') 
          );
        }
      };
      
      persist_redirect_target();
      window.onhashchange = persist_redirect_target;
    };
    
    if(typeof Ext !== 'undefined') {
      Ext.onReady(loginFormOnReadyFn);
    }
    else {
      window.onload = loginFormOnReadyFn;
    }
  </script>

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

    <input type="hidden" id="redirect" name="redirect" value="" />
    
    [%- IF c.req.params.to -%]
      <input type="hidden" id="to" name="to" value="[% c.req.params.to %]" />
    [%- END -%]

    <div class="sepH_c">
      <div class="elVal">
        <label for="username">Username</label>
        <input autofocus 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 %]