mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	Rename zerver/lib/session_user.py to sessions.py.
This commit is contained in:
		
							
								
								
									
										19
									
								
								zerver/lib/sessions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								zerver/lib/sessions.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
from __future__ import absolute_import
 | 
			
		||||
 | 
			
		||||
from django.contrib.auth import SESSION_KEY, get_user_model
 | 
			
		||||
from django.contrib.sessions.models import Session
 | 
			
		||||
 | 
			
		||||
from typing import Mapping, Optional, Text
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_session_dict_user(session_dict):
 | 
			
		||||
    # type: (Mapping[Text, int]) -> Optional[int]
 | 
			
		||||
    # Compare django.contrib.auth._get_user_session_key
 | 
			
		||||
    try:
 | 
			
		||||
        return get_user_model()._meta.pk.to_python(session_dict[SESSION_KEY])
 | 
			
		||||
    except KeyError:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
def get_session_user(session):
 | 
			
		||||
    # type: (Session) -> int
 | 
			
		||||
    return get_session_dict_user(session.get_decoded())
 | 
			
		||||
		Reference in New Issue
	
	Block a user