<rd-header>
  <rd-header-title title-text="User settings"></rd-header-title>
  <rd-header-content>User settings</rd-header-content>
</rd-header>

<demo-feature-indicator ng-if="isDemoUser" content="'You cannot change the password of this account in the demo version of Portainer.'"> </demo-feature-indicator>

<div class="row">
  <div class="col-lg-12 col-md-12 col-xs-12">
    <rd-widget>
      <rd-widget-header icon="fa-lock" title-text="Change user password"></rd-widget-header>
      <rd-widget-body>
        <form name="form" class="form-horizontal" style="margin-top: 15px">
          <!-- current-password-input -->
          <div class="form-group">
            <label for="current_password" class="col-sm-2 control-label text-left">Current password</label>
            <div class="col-sm-8">
              <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-lock" aria-hidden="true"></i></span>
                <input type="password" class="form-control" ng-model="formValues.currentPassword" id="current_password" />
              </div>
            </div>
          </div>
          <!-- !current-password-input -->
          <!-- new-password-input -->
          <div class="form-group">
            <label for="new_password" class="col-sm-2 control-label text-left">New password</label>
            <div class="col-sm-8">
              <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-lock" aria-hidden="true"></i></span>
                <input type="password" class="form-control" ng-model="formValues.newPassword" ng-minlength="requiredPasswordLength" id="new_password" name="new_password" />
              </div>
            </div>
          </div>
          <!-- !new-password-input -->

          <!-- confirm-password-input -->
          <div class="form-group">
            <label for="confirm_password" class="col-sm-2 control-label text-left">Confirm password</label>
            <div class="col-sm-8">
              <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-lock" aria-hidden="true"></i></span>
                <input type="password" class="form-control" ng-model="formValues.confirmPassword" id="confirm_password" />
                <span class="input-group-addon"
                  ><i
                    ng-class="
                      { true: 'fa fa-check green-icon', false: 'fa fa-times red-icon' }[
                        form.new_password.$viewValue !== '' && form.new_password.$viewValue === formValues.confirmPassword
                      ]
                    "
                    aria-hidden="true"
                  ></i
                ></span>
              </div>
            </div>
          </div>
          <password-check-hint password-valid="form.new_password.$valid && formValues.newPassword" force-change-password="forceChangePassword"></password-check-hint>
          <div ng-if="userRole === 1">
            <p class="text-muted">
              <i class="fa fa-exclamation-circle blue-icon" aria-hidden="true"></i>
              Minimum password length is set <a ui-sref="portainer.settings.authentication">here.</a>
            </p>
          </div>
          <!-- !confirm-password-input -->
          <div class="form-group">
            <div class="col-sm-12">
              <button
                type="submit"
                class="btn btn-primary btn-sm"
                ng-disabled="isDemoUser || (AuthenticationMethod !== 1 && !initialUser) || !formValues.currentPassword || !formValues.newPassword || !formValues.confirmPassword || form.$invalid || form.new_password.$viewValue !== formValues.confirmPassword"
                ng-click="updatePassword()"
              >
                Update password
              </button>
              <button type="submit" class="btn btn-primary btn-sm" ng-click="skipPasswordChange()" ng-if="forceChangePassword && timesPasswordChangeSkipped < 2"
                >Remind me later</button
              >
              <span class="text-muted small" style="margin-left: 5px" ng-if="AuthenticationMethod === 2 && !initialUser">
                <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                You cannot change your password when using LDAP authentication.
              </span>
              <span class="text-muted small" style="margin-left: 5px" ng-if="AuthenticationMethod === 3 && !initialUser">
                <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                You cannot change your password when using OAuth authentication.
              </span>
            </div>
          </div>
        </form>
      </rd-widget-body>
    </rd-widget>
    <access-tokens-datatable
      title-text="Access tokens"
      title-icon="fa-key"
      dataset="tokens"
      table-key="tokens"
      order-by="Description"
      remove-action="removeAction"
      ui-can-exit="uiCanExit"
    ></access-tokens-datatable>
    <theme-settings></theme-settings>
  </div>
</div>
