[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # Contributor(s): Marc Schumann <wurblzap@gmail.com>
  #%]

[%# INTERFACE:
  #
  # editform:  is this an edit form? (It's a create form otherwise)
  # editusers: is viewing user member of editusers?
  # otheruser: Bugzilla::User object of user to edit
  #%]

<tr>
  <th><label for="login">Login name:</label></th>
  <td>
    [% IF editusers %]
      <input size="64" maxlength="255" name="login"
             id="login" value="[% otheruser.login FILTER html %]">
      [% IF editform %]
        [% IF !otheruser.in_group('bz_sudo_protect') %]
          <br>
          <a href="[% basepath FILTER none %]relogin.cgi?action=prepare-sudo&amp;target_login=
          [%- otheruser.login FILTER uri %]">Impersonate this user</a>
        [% END %]
      [% END %]
    [% ELSE %]
      [% otheruser.login FILTER html %]
    [% END %]
  </td>
</tr>
[% IF default_authorizer.extern_id_used %]
  <tr>
    <th><label for="extern_id">External Login ID:</label></th>
    <td>
      [% IF editusers %]
        <input size="64" maxlength="64" name="extern_id"
               id="extern_id" value="[% otheruser.extern_id FILTER html %]">
      [% ELSE %]
        [% otheruser.extern_id FILTER html %]
      [% END %]
    </td>
  </tr>
[% END %]
<tr>
  <th><label for="name">Real name:</label></th>
  <td>
    [% IF editusers || disableusers %]
      <input size="64" maxlength="255" name="name"
             autocomplete="off"
             id="name" value="[% otheruser.name FILTER html %]">
    [% ELSE %]
      [% otheruser.name FILTER html %]
    [% END %]
  </td>
</tr>

[% IF editusers %]
  <tr>
    <th>
      <label for="password">
        [% IF editform %]
          [% otheruser.cryptpassword == '*' ? "Set" : "Update" =%]
        [% END %]
        Password:
      </label>
    </th>
    <td>
      <input type="password" size="16" name="password" id="password" value="" autocomplete="off">
      [%# if a user's cryptpassword is '*' it means they use an auth provider
        # such as GitHub, or you can't log in with that account.  in either case
        # forcing a password reset isn't valid %]
      [% IF otheruser.cryptpassword != '*' && editform %]
        <br>
        <input type="checkbox" name="password_change_required" id="password_change_required" maxlength="64"
          [% " checked" IF otheruser.password_change_required %]>
        <label for="password_change_required">User must change their password immediately</label>
        <div id="password_change_reason_container">
          Password change reason (will be displayed to the user):<br>
          <input type="text" size="64"
                 name="password_change_reason" id="password_change_reason"
                 value="[% otheruser.password_change_reason || "You are required to change your password." FILTER html %]"
          >
        </div>
      [% END %]
    </td>
  </tr>
[% END %]

[% IF editusers || disableusers %]
  <tr>
    <th><label for="disable_mail">[% terms.Bug %]mail Disabled:</label></th>
    <td>
      <input type="checkbox" name="disable_mail" id="disable_mail" value="1"
      [% IF otheruser.email_disabled %] checked="checked" [% END %]>
      <label for="disable_mail">
        (This affects [% terms.bug %]mail and whinemail, not password-reset or other
        non-[% terms.bug %]-related emails)
      </label>
    </td>
  </tr>
  [% IF otheruser.bounce_count %]
  <tr>
    <th><label for="reset_bounce">Reset Bounce Count</label></th>
    <td>
      <input type="checkbox" name="reset_bounce" id="reset_bounce" value="1">
      (<a href="/bounced_emails/[% otheruser.id FILTER uri %]" title="View bounce email history">
        [% otheruser.bounce_count FILTER html %]</a>)
    </td>
  </tr>
  [% END %]
  <tr>
    <th><label for="disabledtext">Disable text:</label></th>
    <td>
      [% INCLUDE global/textarea.html.tmpl
         name           = 'disabledtext'
         id             = 'disabledtext'
         minrows        = 2
         maxrows        = 10
         defaultrows    = 10
         cols           = 60
         defaultcontent = otheruser.disabledtext
       %]<br>
      (If non-empty, then the account will be disabled, and this text should
      explain why.)
    </td>
  </tr>
[% END %]

[% IF editform && editusers %]
  <tr>
    <th><label for="mfa">Two-factor Auth:</label></th>
    <td>
      [% IF user.in_group('bz_can_disable_mfa') %]
        [% IF otheruser.mfa %]
          <select name="mfa" value="mfa">
            <option value="">Disable</option>
            [% SWITCH otheruser.mfa %]
              [% CASE "TOTP" %]
                <option value="TOTP" selected>Enabled - TOTP</option>
              [% CASE "Duo" %]
                <option value="Duo" selected>Enabled - Duo Security</option>
            [% END %]
          </select>
        [% ELSE %]
          Disabled
        [% END %]
      [% ELSE %]
        [% otheruser.mfa ? "Enabled - " _ otheruser.mfa : "Disabled" FILTER html %]
      [% END %]
    </td>
  </tr>
[% END %]

[% Hook.process('end') %]
