# Scorpion Plugin : UserManager module example
#
# The UserManager must implement two methods and register in to Scorpion
#
# Example Central Start
# import UserManager
# RegisterUserManager(UserManager.UserManager())
#
# logon(self,user)
# signature:
# string user - default/current user
# returns:
# bool,string,string - ok,user,password
#
# queryAccess(self,attr,user)
# signature:
# string attr - security attribute
# string user - current user
# returns:
# bool - ok
#
import sys
#security attributes in Scorpion 7.0.0.396
_attr = ('Start','Stop','Close','Settings','Service')
#The UserManager class
class UserManager:
def __init__(self):
self.users=('guest','operator','technician','admin')
self.passwords=('guest','oper','service','admin')
self.rights=(
(), #guest
(_attr[0],_attr[1],_attr[2]), #operator
(_attr[3]), #technician
_attr #admin
)
def logon(self,user):
#print self,'logon',user
while True:
ok,user,pw=LogonDialog(self.users,user)
if ok:
for i in range(len(self.users)):
if user==self.users[i]:
if pw==self.passwords[i]:
return True,user
def queryAccess(self,attr,user):
#print self,'queryAccess',user,attr
for i in range(len(self.users)):
if user==self.users[i]:
return attr in self.rights[i]
return False
#-------------------------------------------------------------------------------
# init / test
#-------------------------------------------------------------------------------
if "Scorpion" in sys.modules:
from Scorpion import LogonDialog
else: # tested in PyScripter / Eclipse test environment
def LogonDialog(users,user):
return 1,'operator','oper' #in test - return valid user/pw else run forever!!!
usrmgr=UserManager()
ok,usr=usrmgr.logon('operator')
print 'logon',ok,usr
if ok:
for i in _attr:
print usr,i,usrmgr.queryAccess(i,usr)
|