<%= form_for @user do |f| %>
Login
<%= f.text_field :login, :autocomplete => "username" %>
E-Mail
<%= f.text_field :email %>
Password
<%= f.password_field :password, :autocomplete => "new-password" %>
Confirm
<%= f.password_field :password_confirmation, :autocomplete => "new-password" %>
<% if current_user.admin? %>
Admin?
<%= f.check_box :admin %>
<% end %>
<%= f.submit "Update" %>
<% end %>
<% if @user == current_user %>
Second factor
<% if current_user.otp_enrolled? %>
Enabled.
<%= form_tag otp_enrollment_path, :method => :delete, :class => "otp_form" do %>
<%= text_field_tag :login, current_user.login, :autocomplete => "username", :readonly => true, :tabindex => -1, :class => "visually_hidden" %>
<%= password_field_tag :current_password, nil, :placeholder => "Current password", :autocomplete => "current-password" %>
<%= text_field_tag :code, nil, :placeholder => "Current code",
:autocomplete => "one-time-code", :inputmode => "numeric" %>
<%= button_tag :type => "submit", :class => "action_button" do %>
<%= icon("shield-off", library: "tabler", "aria-hidden": true) %> Disable second factor
<% end %>
<% end %>
<% else %>
Not enrolled.
<%= form_tag otp_enrollment_path, :method => :post, :class => "otp_form" do %>
<%= text_field_tag :login, current_user.login, :autocomplete => "username", :readonly => true, :tabindex => -1, :class => "visually_hidden" %>
<%= password_field_tag :current_password, nil, :placeholder => "Current password", :autocomplete => "current-password"%>
<%= button_tag :type => "submit", :class => "action_button" do %>
<%= icon("shield-lock", library: "tabler", "aria-hidden": true) %> Enable second factor
<% end %>
<% end %>
<% end %>
<% elsif current_user.admin? && @user.otp_enrolled? %>
Second factor
Enabled.
<%= button_to "Reset second factor", reset_otp_user_path(@user), :method => :put,
:form_class => "button_to destructive",
:form => { :data => { :confirm =>
"Reset #{@user.login}'s second factor? They will log in with password only afterwards." } } %>
<% end %>