From: Andrew Donnellan Date: Thu, 25 May 2017 05:42:16 +0000 (+1000) Subject: views: Provide a way to view, (re)generate tokens X-Git-Tag: v2.0.0-rc4~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85c8f369204a2397aac1cdfbb1c3da85ec2d7d5a;p=thirdparty%2Fpatchwork.git views: Provide a way to view, (re)generate tokens Integrate token support into the web UI. Signed-off-by: Andrew Donnellan Signed-off-by: Stephen Finucane --- diff --git a/htdocs/css/style.css b/htdocs/css/style.css index 5218f6d7..af2f0732 100644 --- a/htdocs/css/style.css +++ b/htdocs/css/style.css @@ -369,7 +369,6 @@ table.form th.headerrow { } table.form th { - font-weight: normal; text-align: left; vertical-align: top; padding-top: 0.6em; diff --git a/patchwork/templates/patchwork/profile.html b/patchwork/templates/patchwork/profile.html index f9761953..75c4f59f 100644 --- a/patchwork/templates/patchwork/profile.html +++ b/patchwork/templates/patchwork/profile.html @@ -134,7 +134,35 @@ address.

Authentication

-Change password + + + + + + + + + + + + +
Password:Change password +
API Token: + {% if api_token %} + + + {% endif %} +
+
+ {% csrf_token %} + {% if api_token %} + + {% else %} + + {% endif %} +
+
diff --git a/patchwork/urls.py b/patchwork/urls.py index be996c0b..285d5659 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -235,6 +235,10 @@ if settings.ENABLE_REST_API: urlpatterns += [ url(r'^api/(?:(?P(1.0))/)?', include(api_patterns)), + + # token change + url(r'^user/generate-token/$', user_views.generate_token, + name='generate_token'), ] diff --git a/patchwork/views/user.py b/patchwork/views/user.py index 375d3d9b..d99fedf0 100644 --- a/patchwork/views/user.py +++ b/patchwork/views/user.py @@ -41,6 +41,7 @@ from patchwork.models import Person from patchwork.models import Project from patchwork.models import State from patchwork.views import generic_list +from patchwork.views import utils def register(request): @@ -126,6 +127,7 @@ def profile(request): .extra(select={'is_optout': optout_query}) context['linked_emails'] = people context['linkform'] = EmailForm() + context['api_token'] = request.user.profile.token return render(request, 'patchwork/profile.html', context) @@ -232,3 +234,9 @@ def todo_list(request, project_id): context['action_required_states'] = \ State.objects.filter(action_required=True).all() return render(request, 'patchwork/todo-list.html', context) + + +@login_required +def generate_token(request): + utils.regenerate_token(request.user) + return HttpResponseRedirect(reverse('user-profile'))