manage.py auth: přihlašování na wiki přes admin
This commit is contained in:
		
							parent
							
								
									b77318e2d7
								
							
						
					
					
						commit
						8babcf2ab4
					
				
					 1 changed files with 20 additions and 0 deletions
				
			
		
							
								
								
									
										20
									
								
								seminar/management/commands/auth.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								seminar/management/commands/auth.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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) | ||||||
		Loading…
	
		Reference in a new issue
	
	 Matěj Kocián
						Matěj Kocián