userSettings = async ({ req, res, pwform, user }) => {
  let usersets, userSetsName;
  const user_settings_form = getState().getConfig("user_settings_form", "");
  if (user_settings_form) {
    const view = await View.findOne({ name: user_settings_form });
    if (view) {
      usersets = await view.run({ id: user.id }, { req, res });
      userSetsName = view.name;
    }
  }
  let apikeycard;
  const min_role_apikeygen = +getState().getConfig("min_role_apikeygen", 1);
  const twoFaPolicy = getState().get2FApolicy(user);
  const show2FAPolicy =
    twoFaPolicy !== "Disabled" || user._attributes.totp_enabled;
  if (user.role_id <= min_role_apikeygen)
    apikeycard = {
      type: "card",
      title: req.__("API token"),
      contents: [
        // api token for user
        div(
          user.api_token
            ? span({ class: "me-1" }, req.__("API token for this user: ")) +
                code(user.api_token)
            : req.__("No API token issued")
        ),
        // button for reset or generate api token
        div(
          { class: "mt-4 d-inline-block" },
          post_btn(
            `/auth/gen-api-token`,
            user.api_token ? req.__("Reset") : req.__("Generate"),
            req.csrfToken()
          )
        ),
        // button for remove api token
        user.api_token &&
          div(
            { class: "mt-4 ms-2 d-inline-block" },
            post_btn(
              `/auth/remove-api-token`,
              // TBD localization
              user.api_token ? req.__("Remove") : req.__("Generate"),
              req.csrfToken(),
              { req: req, confirm: true }
            )
          ),
      ],
    };
  let themeCfgCard;
  const layoutPlugin = getState().getLayoutPlugin(user);
  const modNames = getState().plugin_module_names;
  const pluginName = layoutPlugin.plugin_name;
  let safeName = pluginName;
  for (const [k, v] of Object.entries(modNames)) {
    if (v === pluginName) safeName = k;
  }

  const hasUserConfigs =
    layoutPlugin.user_config_form &&
    (await layoutPlugin.user_config_form(
      getState().plugin_cfgs[pluginName] || {}
    )) !== null;
  themeCfgCard = {
    type: "card",
    title: req.__("Layout"),
    contents: [
      div(
        hasUserConfigs
          ? req.__("Adjust the the theme for this user")
          : req.__("The current theme has no user specific settings")
      ),
      hasUserConfigs
        ? div(
            {
              class: "mt-4",
            },

            a(
              {
                class: "btn btn-primary",
                role: "button",
                href: `/plugins/user_configure/${encodeURIComponent(safeName)}`,
                title: req.__("Configure theme"),
              },
              req.__("Configure")
            ),
            button(
              {
                class: "btn btn-primary ms-2",
                onclick: "ajax_post('/plugins/remove_user_layout')",
                title: req.__("Remove all user specific theme settings"),
              },
              req.__("Reset")
            )
          )
        : "",
    ],
  };
  const auth_method_enabled = getState().get_auth_enabled_by_role(user.role_id);
  return {
    above: [
      {
        type: "breadcrumbs",
        crumbs: [{ text: req.__("User") }, { text: req.__("Settings") }],
      },
      ...(usersets
        ? [
            {
              type: "card",
              class: "mt-0",
              title: userSetsName,
              contents: usersets,
            },
          ]
        : []),
      {
        type: "card",
        title: req.__("User"),
        class: !usersets && "mt-0",
        contents: table(
          tbody(
            tr(
              th(req.__("Email: ")),
              td(a({ href: "mailto:" + req.user.email }, req.user.email))
            ),
            tr(th(req.__("Language: ")), td(setLanguageForm(req, user)))
          )
        ),
      },
      ...(user.password && auth_method_enabled?.Password !== false
        ? [
            {
              type: "card",
              title: req.__("Change password"),
              contents: renderForm(pwform, req.csrfToken()),
            },
          ]
        : []),
      ...(user.password && show2FAPolicy
        ? [
            {
              type: "card",
              title: req.__("Two-factor authentication"),
              contents: [
                div(
                  user._attributes.totp_enabled
                    ? req.__("Two-factor authentication is enabled")
                    : req.__("Two-factor authentication is disabled")
                ),
                div(
                  user._attributes.totp_enabled
                    ? a(
                        {
                          href: "/auth/twofa/disable/totp",
                          class: "btn btn-danger mt-2",
                        },
                        req.__("Disable 2FA")
                      )
                    : a(
                        {
                          href: "/auth/twofa/setup/totp",
                          class: "btn btn-primary mt-2",
                        },
                        req.__("Enable 2FA")
                      )
                ),
              ],
            },
          ]
        : []),
      ...(apikeycard ? [apikeycard] : []),
      ...(themeCfgCard ? [themeCfgCard] : []),
    ],
  };
}
@param {object} opts
@param {object} opts.req
@param {object} opts.res
@param {object} opts.pwform
@param {object} opts.user
@returns {Promise<object>}