path('oauth_callback/', views.oauth_callback, name='apiclient_oauth_callback'),
path('oauth-beta/', views.oauth, kwargs={'beta': True}, name='apiclient_beta_oauth'),
path('oauth_callback-beta/', views.oauth_callback, kwargs={'beta': True}, name='apiclient_beta_callback'),
+ path('disconnect', views.disconnect, name='apiclient_disconnect'),
]
from django.contrib.auth.decorators import login_required
from django.urls import reverse
from django.http import HttpResponseRedirect, HttpResponse
+from django.views.decorators.http import require_POST
import oauth2
from apiclient.models import OAuthConnection
conn.save()
return HttpResponseRedirect('/')
+
+
+@login_required
+@require_POST
+def disconnect(request):
+ request.user.oauthconnection_set.filter(beta=False).delete()
+ return HttpResponseRedirect(reverse('documents_user'))
{% endblock leftcolumn %}
{% block rightcolumn %}
-<div class="card">
+ {% if wllogin %}
+ <div class="card">
+ <div class="card-header">
+ <h2>Konto WL</h2>
+ </div>
+ <div class="card-body">
+ <p>
+ Podłączone konto na Wolnych Lekturach:
+ <strong>{{ wllogin }}</strong>
+ </p>
+ <form method="post" action="{% url 'apiclient_disconnect' %}">
+ {% csrf_token %}
+ <button class="btn btn-danger">
+ Odłącz
+ </button>
+ </form>
+ </div>
+
+ </div>
+ {% endif %}
+
+ <div class="card">
<div class="card-header">
<h2>{% trans "Your last edited documents" %}</h2>
</div>
from django.views.decorators.http import require_POST
from django_cas_ng.decorators import user_passes_test
-from apiclient import NotAuthorizedError
+from apiclient import api_call, NotAuthorizedError
from . import forms
from . import helpers
from .helpers import active_tab
key=lambda x: x[1]['time'], reverse=True)
for k, v in last_books:
v['time'] = datetime.fromtimestamp(v['time'])
+ try:
+ resp = api_call(request.user, 'username/')
+ except NotAuthorizedError:
+ wllogin = None
+ else:
+ wllogin = resp['username']
+
return render(request, 'documents/my_page.html', {
'last_books': last_books,
"logout_to": '/',
+ "wllogin": wllogin,
})