Python Forum
function-decorator , which is checking an access according to USERNAME
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function-decorator , which is checking an access according to USERNAME
#1
Hallo,

I'm asking for help for followed task:

"""
Realize a function-decorator , which is checking an access according to USERNAME
All USERNAMEs are saved as global in the List USERS
If User is agree for authorisation - he should input his username (saved as global)
Funktion should use two decorators: one for checking of authorisation, second - for check of access
"""

Why is error outputed?:




USERS = ['admin', 'guest', 'director', 'root', 'superstar']

yesno = input(""" Input Y if you want to authorisate yourself or input N if you want to work as an anonyme User """)

auth = yesno == "Y"

if auth:
    username = input("Input your username:")



def is_auth(func):
    def wrapper():
        if auth:
            print("User is authorised")
            func()
        else:
            print("User is not authorised. Function will not performed")
    return wrapper




@is_auth
@has_access
def from_db():
    print("some data from database")

from_db()


###:

def has_access(func):
    def wrapper():
        if username in USERS:
            print("Authorised as", username)
            func()
        else:
            print("Access for user", username, "is not allowed")
    return wrapper
I would like to ask for helping to correct the code
Reply


Messages In This Thread
function-decorator , which is checking an access according to USERNAME - by Liki - Feb-16-2024, 03:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python code tp determin a userName and print message jackAmin 4 1,867 Nov-20-2022, 12:03 AM
Last Post: rob101
  Help! Chatting App - Changing the "IP & Port" into Username Rowan99 0 1,425 Dec-20-2021, 07:02 AM
Last Post: Rowan99
  Decorator for a function with argument(s) banidjamali 1 1,857 Feb-09-2021, 11:55 AM
Last Post: Gribouillis
  i got a decorator question yosef 3 2,614 Aug-25-2020, 04:14 PM
Last Post: DeaD_EyE
  Decorator is using in class,but not working mbilalshafiq 2 2,146 Jul-04-2020, 08:53 PM
Last Post: mbilalshafiq
  Decorator and namespace. JayIvhen 2 2,811 Oct-26-2018, 03:56 PM
Last Post: nilamo
  Password and Username Verification AlwaysNew 4 17,234 Nov-12-2017, 11:51 AM
Last Post: wavic
  Username and password Steve2017 13 9,945 Sep-03-2017, 09:17 PM
Last Post: Steve2017
  python decorator alfredocabrera 0 3,156 Feb-22-2017, 07:04 AM
Last Post: alfredocabrera

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020