<%= form_with(model: [:admin, user], class: "space-y-6", data: { controller: "form-errors" }) do |form| %> <%= render "shared/form_errors", form: form %>
<%= form.label :email_address, class: "block text-sm font-medium text-gray-700" %> <%= form.email_field :email_address, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "user@example.com" %>
<%= form.label :username, "Username (Optional)", class: "block text-sm font-medium text-gray-700" %> <%= form.text_field :username, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "jsmith" %>

Optional: Short username/handle for login. Can only contain letters, numbers, underscores, and hyphens.

<%= form.label :name, "Display Name (Optional)", class: "block text-sm font-medium text-gray-700" %> <%= form.text_field :name, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "John Smith" %>

Optional: Full name shown in applications. Defaults to email address if not set.

<%= form.label :password, class: "block text-sm font-medium text-gray-700" %> <%= form.password_field :password, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: user.persisted? ? "Leave blank to keep current password" : "Enter password" %> <% if user.persisted? %>

Leave blank to keep the current password

<% else %>

Leave blank to generate a random password

<% end %>
<%= form.label :status, class: "block text-sm font-medium text-gray-700" %> <%= form.select :status, User.statuses.keys.map { |s| [s.titleize, s] }, {}, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm" %>
<%= form.check_box :admin, class: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500", disabled: (user == Current.session.user) %> <%= form.label :admin, "Administrator", class: "ml-2 block text-sm text-gray-900" %> <% if user == Current.session.user %> (Cannot change your own admin status) <% end %>
<%= form.check_box :totp_required, class: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500" %> <%= form.label :totp_required, "Require Two-Factor Authentication", class: "ml-2 block text-sm text-gray-900" %> <% if user.totp_required? && !user.totp_enabled? %> (User has not set up 2FA yet) <% end %>
<% if user.totp_required? && !user.totp_enabled? %>

Warning: This user will be prompted to set up 2FA on their next login.

<% end %>

When enabled, this user must use two-factor authentication to sign in.

<%= form.label :custom_claims, "Custom Claims (JSON)", class: "block text-sm font-medium text-gray-700" %> <%= form.text_area :custom_claims, value: (user.custom_claims.present? ? JSON.pretty_generate(user.custom_claims) : ""), rows: 8, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm font-mono", placeholder: '{"department": "engineering", "level": "senior"}', data: { action: "input->json-validator#validate blur->json-validator#format", json_validator_target: "textarea" } %>

Optional: User-specific custom claims to add to OIDC tokens. These override group-level claims.

<%= form.submit user.persisted? ? "Update User" : "Create User", class: "rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600" %> <%= link_to "Cancel", admin_users_path, class: "rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" %>
<% end %>