Skip to content

Commit 85c8f36

Browse files
ajdlinuxstephenfin
authored andcommitted
views: Provide a way to view, (re)generate tokens
Integrate token support into the web UI. Signed-off-by: Andrew Donnellan <[email protected]> Signed-off-by: Stephen Finucane <[email protected]>
1 parent 274763e commit 85c8f36

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

htdocs/css/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ table.form th.headerrow {
369369
}
370370

371371
table.form th {
372-
font-weight: normal;
373372
text-align: left;
374373
vertical-align: top;
375374
padding-top: 0.6em;

patchwork/templates/patchwork/profile.html

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,35 @@ <h2>Settings</h2>
134134

135135
<div class="box">
136136
<h2>Authentication</h2>
137-
<a href="{% url 'password_change' %}">Change password</a>
137+
138+
<table class="form">
139+
<tr>
140+
<th>Password:</th>
141+
<td><a href="{% url 'password_change' %}">Change password</a>
142+
</tr>
143+
<tr>
144+
<th>API Token:</th>
145+
<td>
146+
{% if api_token %}
147+
<input id="token" style="width: 25em;" readonly value="{{ api_token }}">
148+
<button type="button" class="btn-copy" title="Copy to clipboard"
149+
data-clipboard-target="#token">Copy</button>
150+
{% endif %}
151+
</td>
152+
<tr>
153+
<th></th>
154+
<td>
155+
<form method="post" action="{% url 'generate_token' %}">
156+
{% csrf_token %}
157+
{% if api_token %}
158+
<input type="submit" value="Regenerate token"/>
159+
{% else %}
160+
<input type="submit" value="Generate token"/>
161+
{% endif %}
162+
</form>
163+
</td>
164+
</tr>
165+
</table>
138166
</div>
139167

140168
</div>

patchwork/urls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@
235235

236236
urlpatterns += [
237237
url(r'^api/(?:(?P<version>(1.0))/)?', include(api_patterns)),
238+
239+
# token change
240+
url(r'^user/generate-token/$', user_views.generate_token,
241+
name='generate_token'),
238242
]
239243

240244

patchwork/views/user.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from patchwork.models import Project
4242
from patchwork.models import State
4343
from patchwork.views import generic_list
44+
from patchwork.views import utils
4445

4546

4647
def register(request):
@@ -126,6 +127,7 @@ def profile(request):
126127
.extra(select={'is_optout': optout_query})
127128
context['linked_emails'] = people
128129
context['linkform'] = EmailForm()
130+
context['api_token'] = request.user.profile.token
129131

130132
return render(request, 'patchwork/profile.html', context)
131133

@@ -232,3 +234,9 @@ def todo_list(request, project_id):
232234
context['action_required_states'] = \
233235
State.objects.filter(action_required=True).all()
234236
return render(request, 'patchwork/todo-list.html', context)
237+
238+
239+
@login_required
240+
def generate_token(request):
241+
utils.regenerate_token(request.user)
242+
return HttpResponseRedirect(reverse('user-profile'))

0 commit comments

Comments
 (0)