From 8babcf2ab4ca78b810fe2daeb308d42675c3ee06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 2 Oct 2015 14:34:17 +0200 Subject: [PATCH] =?UTF-8?q?manage.py=20auth:=20p=C5=99ihla=C5=A1ov=C3=A1n?= =?UTF-8?q?=C3=AD=20na=20wiki=20p=C5=99es=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/management/commands/auth.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 seminar/management/commands/auth.py diff --git a/seminar/management/commands/auth.py b/seminar/management/commands/auth.py new file mode 100644 index 00000000..1aa504dd --- /dev/null +++ b/seminar/management/commands/auth.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +from django.core.management.base import NoArgsCommand +from django.contrib.sessions.models import Session +from django.contrib.auth.models import User + +class Command(NoArgsCommand): + u"""Vypiš username přihlášeného orga s daným session_key. + + Příkaz pro manage.py, který ze vstupu přečte session_key (tak, jak je + uložen v cookie sessionid) a pokud session existuje a příslušný přihlášený + uživatel má právo přihlásit se do admina, vypíše jeho username. + """ + def handle_noargs(self, **options): + session_key = raw_input() + s = Session.objects.get(pk=session_key).get_decoded() + user_id = s['_auth_user_id'] + user = User.objects.get(pk=user_id) + if user.is_staff: + print(user.username)