mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-23 20:35:03 +02:00
Added possibility to list all available API keys at the user settings page
This commit is contained in:
parent
040e86ea6d
commit
35a0e8464a
9 changed files with 245 additions and 42 deletions
61
templates/users/_api_tokens.html.twig
Normal file
61
templates/users/_api_tokens.html.twig
Normal file
|
@ -0,0 +1,61 @@
|
|||
{# @var user \App\Entity\UserSystem\User #}
|
||||
|
||||
{% macro format_date(datetime) %}
|
||||
{% if datetime is null %}
|
||||
<i>{% trans %}datetime.never{% endtrans %}</i>
|
||||
{% else %}
|
||||
{{ datetime|format_datetime }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">
|
||||
<i class="fa-solid fa-plug fa-fw" aria-hidden="true"></i>
|
||||
{% trans %}user.settings.api_tokens{% endtrans %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<span class="text-muted">{% trans %}user.settings.api_tokens.description{% endtrans %}</span><br>
|
||||
<a href="{{ path('api_doc') }}">{% trans %}user.settings.show_api_documentation{% endtrans %}</a>
|
||||
|
||||
{% if user.apiTokens.empty %}
|
||||
<br><br>
|
||||
<b>{% trans %}user.settings.api_tokens.no_api_tokens_yet{% endtrans %}</b>
|
||||
{% else %}
|
||||
<table class="table table-striped table-bordered table-hover table-sm mt-2">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans %}api_tokens.name{% endtrans %}</th>
|
||||
<th>{% trans %}api_tokens.access_level{% endtrans %}</th>
|
||||
<th>{% trans %}api_tokens.expiration_date{% endtrans %}</th>
|
||||
<th>{% trans %}tfa_u2f.keys.added_date{% endtrans %}</th>
|
||||
<th>{% trans %}api_tokens.last_time_used{% endtrans %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for api_token in user.apiTokens %}
|
||||
{# @var api_token \App\Entity\UserSystem\ApiToken #}
|
||||
<tr>
|
||||
<td>{{ api_token.name }}</td>
|
||||
<td>{{ api_token.level.translationKey|trans }}</td>
|
||||
<td>
|
||||
{{ _self.format_date(api_token.validUntil) }}
|
||||
{% if api_token.valid %}
|
||||
<span class="badge bg-success badge-success">{% trans %}api_token.valid{% endtrans %}</span>
|
||||
{% else %}
|
||||
<span class="badge bg-warning badge-warning">{% trans %}api_token.expired{% endtrans %}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ _self.format_date(api_token.addedDate) }}</td>
|
||||
<td>{{ _self.format_date(api_token.lastTimeUsed) }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ path('user_api_token_create') }}" class="btn btn-success" ><i class="fas fa-plus-square fa-fw"></i> {% trans %}api_token.create_new{% endtrans %}</a>
|
||||
|
||||
</div>
|
||||
</div>
|
|
@ -1,16 +1,30 @@
|
|||
{% extends "main_card.html.twig" %}
|
||||
|
||||
{% block card_title %}Add API token{% endblock %}
|
||||
{% block title %}{% trans %}api_token.create_new{% endtrans %}{% endblock %}
|
||||
|
||||
{% block card_title %}
|
||||
<i class="fa-solid fa-plug fa-fw" aria-hidden="true"></i>
|
||||
{% trans %}api_token.create_new{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block card_content %}
|
||||
{# Show API secret after submit #}
|
||||
|
||||
{% if secret is not null %}
|
||||
<div class="alert alert-success">
|
||||
Your API token is: <strong>{{ secret }}</strong><br>
|
||||
<span class="text-muted">Please save it. You wont be able to see it again!</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<b>{% trans %}api_tokens.your_token_is{% endtrans %}:</b><br>
|
||||
<div class="input-group input-group-sm">
|
||||
<input type="text" class="form-control" value="{{ secret }}" readonly>
|
||||
<button class="btn btn-outline-secondary" type="button" data-clipboard-text="{{ secret }}">
|
||||
<i class="fa-solid fa-clipboard fa-fw" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
<i>{% trans %}api_tokens.please_save_it{% endtrans %}</i>
|
||||
<br>
|
||||
|
||||
{{ form(form) }}
|
||||
<a href="{{ path('user_settings') }}" class="btn btn-primary mt-4">{% trans %}api_tokens.create_new.back_to_user_settings{% endtrans %}</a>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form(form) }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -76,4 +76,6 @@
|
|||
{{ form_end(pw_form) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% include "users/_api_tokens.html.twig" %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue