feat: Semaine 9
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable
|
||||
|
||||
@dataclass
|
||||
class User:
|
||||
username: str
|
||||
is_authenticated: bool = False
|
||||
|
||||
def authentication_required(fonction: Callable):
|
||||
def internal_wrapper(user: User):
|
||||
if not user.is_authenticated:
|
||||
return PermissionError(f"L'utilisateur {user.username} n'est pas authentifié.")
|
||||
return fonction(user)
|
||||
return internal_wrapper
|
||||
|
||||
@authentication_required
|
||||
def operation_sensible(user: User):
|
||||
return f"Opération sensible faite par {user.username}."
|
||||
|
||||
alice = User("alice@courriel.fr", True)
|
||||
bob = User("bob@courriel.fr")
|
||||
|
||||
print(operation_sensible(alice))
|
||||
print(operation_sensible(bob))
|
||||
Reference in New Issue
Block a user