# extends 'admin.html'
<!DOCTYPE html>
<html>
  <head>
    <title>
      # block admintitle
      ${dgettext("acct_mgr", "Account")}
      # endblock admintitle
    </title>
    # block head
    ${ super() }
    <script type="text/javascript">
      jQuery(document).ready(function($) {
        $('#password').focus();
      });
    </script>
    # endblock head
  </head>

  <body>
    # block adminpanel
    <div id="account_details">
      <div>
        <h2>${dgettext("acct_mgr", "Manage User Account")}</h2>
        <p>
          ${
            i18n_tag(dgettext('acct_mgr', 'for [1:%(name)s] ([2:%(user)s])'),
                     'strong', 'em', name=acctmgr.name, user=user)
            if acctmgr.name else
            i18n_tag(dgettext('acct_mgr', 'for [1:%(user)s]'),
                     'strong', user=user)
          }
          # if not change_uid_enabled
          <img src="${href.chrome('/acct_mgr/info.png')}"
               title="${dgettext('acct_mgr', 'User ID change requires additional components enabled')}"
               height="16" width="16" alt="" />
          # endif
        </p>
      </div>

      ## Account property editor
      <form id="account-editor" class="addnew" method="post">
        ${jmacros.form_token_input()}

        # if len(forms) > 1
        <ul id="forms">
          # for name, label in sorted(forms)
          <li class="${'active' if name == active_form}"
              id="${('form_%s' % name) if name}">
            # if name == active_form
            ${label}
            # else
            <a href="${href.admin('accounts', 'users', user, action=name)}">${label}</a>
            # endif
          </li>
          # endfor
        </ul>
        # endif

        <div id="formcontent">
          <fieldset>
            # if active_form == 'uid'
            <div>
              <div class="field">
                <input type="hidden" name="action" value="uid" />
                <label>
                  ${dgettext('acct_mgr', 'New Username:')}<br />
                  <input type="text" name="new_uid" id="new_uid" class="textwidget"
                         title="${dgettext('acct_mgr', 'Change user ID (\'username\')')}"
                         value="${acctmgr.new_uid}" />
                </label>
              </div>
              <div>
                <div class="field">
                  <label>
                    <input type="checkbox" name="uid_exists" value="true"
                           title="${dgettext('acct_mgr', 'Skip creating account and password reset')}"${
                           {'checked': uid_exists}|htmlattr} />
                    ${dgettext('acct_mgr', 'Assume existing account')}
                  </label>
                </div>
                <div class="field">
                  <label>
                    <input type="checkbox" name="attr_addonly" value="true"
                           title="${dgettext('acct_mgr', 'Do not overwrite existing attributes')}"${
                           {'checked': attr_addonly}|htmlattr} />
                    ${dgettext('acct_mgr', 'Copy only new account attributes')}
                  </label>
                </div>
                <div class="field">
                  <label>
                    <input type="checkbox" name="skip_delete" value="true"
                           title="${dgettext('acct_mgr', 'Skip final account deletion')}"${
                           {'checked': skip_delete}|htmlattr} />
                    ${dgettext('acct_mgr', 'Leave old login data')}
                  </label>
                </div>
              </div>
            </div>
            # else
            <div>
              <div>
                <div class="field">
                  <input type="hidden" name="action" value="edit" />
                  <label for="password">
                    ${dgettext('acct_mgr', 'Password:')}<br />
                    <input type="password" id="password" name="password" class="textwidget"
                           ${{'disabled': not password_change_enabled}|htmlattr} />
                  </label>
                </div>
                <div class="field">
                  <label for="confirm">
                    ${dgettext('acct_mgr', 'Confirm Password:')}<br />
                    <input type="password" id="confirm" name="password_confirm" class="textwidget"
                           ${{'disabled': not password_change_enabled}|htmlattr} />
                  </label>
                </div>
              </div>
              <div class="field">
                <label>
                  ${dgettext('acct_mgr', 'Pre-/Surname (Nickname):')}<br />
                  <input type="text" name="name" class="textwidget" value="${acctmgr.name}" />
                </label>
                # if acctmgr.name
                <input type="image" name="delete_name" class="delete"
                       src="${href.chrome('/acct_mgr/delete.png')}"
                       alt="${dgettext('acct_mgr', 'Delete value')}" />
                # endif
              </div>
              <div class="field">
                <label>
                  ${dgettext('acct_mgr', 'Email Address:')}<br />
                  <input type="text" name="email" class="textwidget" value="${acctmgr.email}" />
                </label>
                # if acctmgr.email
                <input type="image" name="delete_email" class="delete"
                       src="${href.chrome('/acct_mgr/delete.png')}"
                       alt="${dgettext('acct_mgr', 'Delete value')}" />
                # endif
                <br />
                # if verify_enabled
                <label>
                  <input type="checkbox" name="email_approved" value="true"
                         ${{'checked': email_approved}|htmlattr} />
                  ${dgettext('acct_mgr', 'Skip new email verification')}
                </label>
                # endif
              </div>
            </div>
            # endif
            <div class="buttons">
              <input type="submit" value="${dgettext('acct_mgr', 'Apply changes')}" />
            </div>
          </fieldset>
        </div>
      </form>

      # if not action_aside
      <hr style="clear: right"/>
      # endif

      <form method="get" action="${url}">
        <fieldset>
          <legend>
            <label>${dgettext('acct_mgr', 'Account Status')}</label>
          </legend>
          # if approval or user_locked
          <div id="user_locked">
            <p>
              # if release_time and not approval
              <span>
                <img src="${href.chrome('/acct_mgr/time-locked.png')}" />
                ${
                  i18n_tag(
                    dgettext(
                      "acct_mgr",
                      "This account has been locked until %(time)s[1:]and "
                      "even valid login attempts are rejected meanwhile."),
                    'br', time=release_time)
                }
              </span>
              # elif approval or not release_time
              <span>
                <img src="${href.chrome('/acct_mgr/locked.png')}" />
                ${dgettext('acct_mgr', 'This account has been locked permanently.')}
              </span>
              # endif
              <span class="buttons">
                <input type="submit" name="release"
                       alt="${dgettext('acct_mgr', 'Release account lock')}"
                       title="${dgettext('acct_mgr', 'Release account lock')}"
                       value="${dgettext('acct_mgr', 'Unlock')}" />
              </span>
            </p>
          </div>
          # endif

          # if lock_count
          <div id="restricted">
            # if not lock_count == 0
            <div>
              <p>${
                dngettext("acct_mgr",
                          "Time lock condition has been met %(count)s time by now."
                          "Time lock condition has been met %(count)s times by now.",
                          count=lock_count)
              }</p>
              # if not (approval or (user_locked and not release_time))
              <p>${
                dgettext("acct_mgr",
                         "Therefore after another failed login attempt "
                         "authentication for this account would be retarded "
                         "by %(time)s.", time=pretty_lock_time)
              }</p>
              # endif
            </div>
            # else
            <div>
              <p>${dgettext('acct_mgr', 'Lock condition has not been met yet.')}</p>
            </div>
            # endif
          </div>
          # elif not (approval or lock_count)
          <div id="unrestricted">
            <p>${dgettext('acct_mgr', 'No constraints are set for this account.')}</p>
          </div>
          # endif

          # if user_locked or approval
          <hr />
          # endif

          # if user_store
          <div id="user_store">
            <p>${
              i18n_tag(
                dgettext("acct_mgr",
                         "Credentials for this user are stored in AuthStore number "
                         "[1:%(order_num)s] (%(store)s)."),
                'em', order_num=store_order_num, store=user_store,
              )
            }</p>
            # if ignore_auth_case
            <p class="hint">${
              i18n_tag(dgettext('acct_mgr',
                                'Username matching is set to [1:not case-sensitive].'),
                       'strong')
            }</p>
            # else
            <p class="hint">${
              i18n_tag(dgettext('acct_mgr',
                                'Username matching is set to [1:case-sensitive].'),
                       'strong')
            }</p>
            # endif
          </div>
          # endif

          # if not (approval or user_store)
          <div id="no_user_store">
            <p>${
              i18n_tag(dgettext("acct_mgr",
                                "No readable store provides credentials for this user, so the user may"
                                " not get authenticated and access to this [1:account might be "
                                "effectively blocked]."),
                       'em')
          }</p>
          </div>
          # endif

          # if acctmgr.email
          <div>
            <p>${
              dgettext("acct_mgr", "Current email address: <%(email)s>",
                       email=acctmgr.email)
            }</p>
            # if verification
            #   if email_verified
            <p>${
              dgettext('acct_mgr', 'This address has been verified successfully.')
            }</p>
            #   elif not email_verified and email_verification_token
            <p>${
              i18n_tag(dgettext("acct_mgr", "Verification is pending [1:(token: %(token)s)]"),
                       tag.span(class_='hint'),
                       token=email_verification_token)
            }</p>
            #   else
            <p>${
              dgettext('acct_mgr', 'This address has not been verified yet.')
            }</p>
            #   endif
            # endif
          </div>
          # else
          <div>
            <p>${
              dgettext('acct_mgr', 'No email address is registered for this account.')
            }</p>
          </div>
          # endif
        </fieldset>

        <fieldset>
          <legend>
            <label>${dgettext('acct_mgr', 'Access History')}</label>
          </legend>
          <p>${
            dgettext('acct_mgr', 'Last login: %(time)s', time=format_datetime(last_visit))
            if last_visit else
            dgettext('acct_mgr', 'The user has not logged in before.')
          }</p>

          # if attempts_count
          <div id="failed_attempts">
            <p>${
              dgettext("acct_mgr", "Total failed attempts: %(count)s",
                       count=attempts_count)
            }</p>
            <p class="tableheader">${
              dgettext('acct_mgr', 'Table: Last failed login attempts log view')
            }</p>
            <table class="listing" id="login_attempts">
              <thead>
                <tr>
                  <th>${dgettext('acct_mgr', 'IP address')}</th>
                  <th>${dgettext('acct_mgr', 'Log time')}</th>
                </tr>
              </thead>
              <tbody>
                # for attempt in attempts
                <tr>
                  <td>${attempt.ipnr}</td>
                  <td>${format_datetime(attempt.time)}</td>
                </tr>
                # endfor
              </tbody>
            </table>
            # if not user_locked
            <div class="buttons">
              <input type="submit" name="delete"
                     title="${dgettext('acct_mgr', 'Delete login failure log')}"
                     value="${dgettext('acct_mgr', 'Delete Log')}" />
            </div>
            # endif
          </div>
          # else
          <div id="no_failed_attempts">
            <p>${
              dgettext('acct_mgr', 'There is currently no failed login attempt logged.')
            }</p>
          </div>
          # endif
        </fieldset>

        <div class="buttons">
          <input type="submit" name="update" value="${dgettext('acct_mgr', 'Refresh')}" />
        </div>
      </form>
    </div>
    # endblock adminpanel
  </body>
</html>
