API Keys
<%= link_to new_user_api_key_path(CurrentUser.user.id), class: "button-primary" do %>
<%= plus_icon %> Add
<% end %>
<% if params[:user_id].present? %>
An API key is used to give programs access to your <%= Danbooru.config.canonical_app_name %> account.
If you're a developer, you can use an API key to access the
<%= link_to_wiki "#{Danbooru.config.canonical_app_name} API", "help:api" %>. If you're not a
developer, and you're not using any third-party apps, then you probably don't need an API key.
Your API key is like your password. Anyone who has it has full access to
your account. Don't give your API key to apps or people you don't trust, and don't post your
API key in public locations.
Example usage:
<% if @api_keys.present? %>
<%= profile_url(format: "json", login: CurrentUser.user.name, api_key: @api_keys.first.key) %>
<% else %>
<%= profile_url(format: "json", login: CurrentUser.user.name, api_key: "your_api_key_goes_here") %>
<% end %>
See the <%= link_to_wiki "API documentation", "help:api" %> to learn more.
<% end %>
<% if params[:user_id].present? && !@api_keys.present? %>
<%= link_to "Create API key", new_user_api_key_path(CurrentUser.user.id) %>
<% else %>
<%= table_for @api_keys, width: "100%", class: "striped autofit" do |t| %>
<% t.column :name %>
<% t.column :key, td: { class: "col-expand" } %>
<% t.column :permissions do |api_key| %>
<%= safe_join(api_key.permissions, "
".html_safe).presence || "All" %>
<% end %>
<% t.column "IPs" do |api_key| %>
<%= safe_join(api_key.permitted_ip_addresses, "
".html_safe).presence || "All" %>
<% end %>
<% t.column :uses %>
<% t.column "Last Used" do |api_key| %>
<%= time_ago_in_words_tagged api_key.last_used_at %>
<% if api_key.last_ip_address.present? %>
by <%= api_key.last_ip_address %>
<% end %>
<% end %>
<% t.column "Created" do |api_key| %>
<%= time_ago_in_words_tagged api_key.created_at %>
<% if !params[:user_id].present? %>
by <%= link_to_user api_key.user %>
<% end %>
<% end %>
<% t.column column: "control" do |api_key| %>
<%= link_to "Edit", edit_api_key_path(api_key) %>
| <%= link_to "Delete", api_key, method: :delete %>
<% end %>
<% end %>
<%= numbered_paginator(@api_keys) %>
<% end %>