有人能帮我解下密码吗!因此,使用if子句,我想使程序仅在我使用admin登录时才打开操作员菜单。这样的代码是一个错误:管理员没有定义。我该怎么弥补?
def operator_menu():
print("Operator Menu")
print("1. Show all bookings")
print("2. Register a new driver")
print("3. Remove a booking")
print("4. View available drivers")
print("5. Logout")
menu_input = input("What would you like to do?: ")
if menu_input == "1":
show_bookings()
if menu_input == "2":
register_newdriver()
if menu_input == "3":
remove_booking()
if menu_input == "4":
available_drivers()
if menu_input == "5":
exit()
def show_bookings():
if not(current_user == create_company(conn, administrator)):
bookings = get_trips(conn)
if not bookings:
print("No bookings.")
else:
print("Available bookings:")
for i, booking in enumerate(bookings):
print(str(i)+". "+str(booking[4])+" -> "+str(booking[5]) + " -> "+str(booking[6])+ " - "+str(booking[7]))
input("Press any key to continue...")
operator_menu()
else:
driver_menu()
def create_company(conn,administrator):
sql = ''' INSERT INTO administrator(name)
VALUES(?) '''
cur = conn.cursor()
cur.execute(sql,administrator)
conn.commit()
return cur.lastrowid
1条答案
按热度按时间yiytaume1#
这里有两种可能的情况。一个是你试图看看登录的(windows)用户是否是管理员,第二个是你正在创建一个有登录窗口的应用程序,所以有两种用户:应用程序管理员和其他用户。
如果是第一种情况,那么你可以使用下面的子进程模块
如果是第二种情况,那么我认为这段代码可以帮助你,而且很容易理解。你必须在你的数据库中有一个表,按名称用户存储用户信息,包括一列确定登录用户的权限。然后你应该检索用户信息从现有的表即用户.如果你没有创建这个表,下面是代码:
然后你应该从这个表中检索用户信息,看看用户是否有特权。