
    Xh^                     F    S SK Jr  S SKJrJr  S SKrSSKJr  SSKJ	r	  S r
g)    wraps)requestjsonifyN   )Config)get_db_connectionc                     ^  U 4S jnU$ )zs
A decorator to ensure a user has one of the required roles.
The user's role is expected to be in the JWT payload.
c                 4   >^  [        T 5      U U4S j5       nU$ )Nc                  @  > S nS[         R                  ;   a  [         R                  S   nU(       d  [        SS05      S4$  [        R                  " U[
        R                  S/S9nUR                  S5      nUR                  S5      nU(       d  [        SS	05      S
4$ UT;  a!  [        SSSR                  T5       305      S
4$  T" U/U Q70 UD6$ ! [        R                   a    [        SS05      S4s $ [        R                   a    [        SS05      S4s $ f = f)Nzx-access-tokenmessagez Authentication token is missing!i  HS256)
algorithmsroleuserz'Role information is missing from token!i  z4Access denied: Requires one of the following roles: z, zToken has expired!zToken is invalid!)r   headersr   jwtdecoder   JWT_SECRET_KEYgetjoinExpiredSignatureErrorInvalidTokenError)argskwargstokendata	user_rolecurrent_user_pidfrequired_roless         2/var/www/fran/franai/controllers/access_control.pydecorated_function<role_required.<locals>.decorator.<locals>.decorated_function   sP   E7??2(89	+MNOQTTTFzz%)>)>G9U HHV,	#'88F#3  "I/X#YZ\___N2"I1efjfofop~f  fA  0B  $C  D  FI  I  I 3 %7777 ,, G	+?@A3FF(( F	+>?@#EEFs   AC &C #D8"DDr   )r    r#   r!   s   ` r"   	decorator role_required.<locals>.decorator   s!    	q	8 
	84 "!     )r!   r%   s   ` r"   role_requiredr)      s    
": r'   )	functoolsr   flaskr   r   r   services.configr   services.mysql_servicer	   r)   r(   r'   r"   <module>r.      s     " 
 $ 6"r'   