Commit 2d719ff5 authored by MOREAU Ulysse's avatar MOREAU Ulysse
Browse files

Initial commit

parent 3f440b24
{% extends 'core/base.html' %}
{% load static %}
{% load menu_item %}
{% block title %}User edit{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'accounts/css/edit.css' %}" />
{% endblock %}
{% block header %}Hihihi{% endblock %}
{% block menu %}
{% menu_item 'Liste des membres' 'accounts:members' %}
{% menu_item 'Mon profil' 'accounts:show' username=request.user.username %}
{% menu_item 'Editer mon profil' 'accounts:edit' username=request.user.username %}
{% endblock %}
{% block main %}
<h1>Hohoho</h1>
{% endblock %}
{% block scripts %}
<script src="{% static 'js/json_request.js' %}" ></script>
<script src="{% static 'js/popup.js' %}" ></script>
<script>
window.addEventListener("load", function() {
let user_popup = new UserSelectionPopup("Se logger en tant que : ", function (uid) {
window.location.replace("{{ redirect_url }}"+uid);
});
user_popup.pop();
});
</script>
{% endblock %}
...@@ -23,6 +23,8 @@ accounts_urlpatterns = [ ...@@ -23,6 +23,8 @@ accounts_urlpatterns = [
path('profile/', views.profile, name='profile'), path('profile/', views.profile, name='profile'),
path('<str:username>/', views.show, name='show'), path('<str:username>/', views.show, name='show'),
path('<str:username>/edit', views.edit, name='edit'), path('<str:username>/edit', views.edit, name='edit'),
path('forceloglist', views.forceloglist, name='forceloglist'),
path('forcelogas/<int:uid>', views.forcelogas, name='forcelogas'),
] ]
urlpatterns = [ urlpatterns = [
......
...@@ -5,7 +5,7 @@ from django.http import JsonResponse, Http404 ...@@ -5,7 +5,7 @@ from django.http import JsonResponse, Http404
from django.core.mail import send_mail from django.core.mail import send_mail
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.contrib import auth from django.contrib import auth
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse from django.urls import reverse
from django.db import transaction from django.db import transaction
...@@ -144,6 +144,22 @@ def edit(request, username): ...@@ -144,6 +144,22 @@ def edit(request, username):
return render(request, 'accounts/edit.html', context) return render(request, 'accounts/edit.html', context)
@user_passes_test(lambda u: u.is_superuser)
def forcelogas(request, uid):
try:
user = User.objects.select_related('profile').get(pk=uid)
except User.DoesNotExist:
raise Http404(f'User {user.username} does not exist')
auth.login(request, user, backend='django.contrib.auth.backends.ModelBackend')
return redirect(request.POST.get('next', reverse('news:index')))
@user_passes_test(lambda u: u.is_superuser)
def forceloglist(request):
return render(request, 'accounts/forceloglist.html', {"redirect_url": reverse("accounts:forcelogas", args=(0,))})
def get_contrib(user): def get_contrib(user):
try: try:
return user.contribution.type return user.contribution.type
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment