Registrations status in config file

master
Bob Mottram 2019-08-08 11:50:58 +01:00
parent cd01a1f761
commit ebcdbf74b4
2 changed files with 53 additions and 0 deletions

View File

@ -255,6 +255,13 @@ parser.add_argument('--location', dest='location', type=str,default=None, \
help='Location/City of item being shared')
parser.add_argument('--duration', dest='duration', type=str,default=None, \
help='Duration for which to share an item')
parser.add_argument('--registration', dest='registration', type=str,default=None, \
help='Whether new registrations are open or closed')
parser.add_argument('--maxregistrations', dest='maxRegistrations', type=int,default=None, \
help='The maximum number of new registrations')
parser.add_argument("--resetregistrations", type=str2bool, nargs='?', \
const=True, default=False, \
help="Reset the number of remaining registrations")
args = parser.parse_args()
debug=False
@ -309,7 +316,44 @@ if baseDir.endswith('/'):
if args.domain:
domain=args.domain
setConfigParam(baseDir,'domain',domain)
# maximum number of new registrations
if not args.maxRegistrations:
maxRegistrations=getConfigParam(baseDir,'maxRegistrations')
if not maxRegistrations:
maxRegistrations=10
setConfigParam(baseDir,'maxRegistrations',str(maxRegistrations))
else:
maxRegistrations=int(maxRegistrations)
else:
maxRegistrations=args.maxRegistrations
setConfigParam(baseDir,'maxRegistrations',str(maxRegistrations))
# if this is the initial run then allow new registrations
if not getConfigParam(baseDir,'registration'):
setConfigParam(baseDir,'registration','open')
setConfigParam(baseDir,'maxRegistrations',str(maxRegistrations))
setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
if args.resetregistrations:
setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
print('Number of new registrations reset to '+str(maxRegistrations))
# whether new registrations are open or closed
if args.registration:
if args.registration.lower()=='open':
registration=getConfigParam(baseDir,'registration')
if not registration:
setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
else:
if registration!='open':
setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
setConfigParam(baseDir,'registration','open')
print('New registrations open')
else:
setConfigParam(baseDir,'registration','closed')
print('New registrations closed')
# unique ID for the instance
instanceId=getConfigParam(baseDir,'instanceId')
if not instanceId:

View File

@ -23,6 +23,8 @@ from auth import storeBasicCredentials
from roles import setRole
from media import removeMetaData
from utils import validNickname
from config import setConfigParam
from config import getConfigParam
def generateRSAKey() -> (str,str):
key = RSA.generate(2048)
@ -232,6 +234,11 @@ def createPerson(baseDir: str,nickname: str,domain: str,port: int, \
"""
if not validNickname(nickname):
return None,None,None,None
registrationsRemaining=int(getConfigParam(baseDir,'registrationsRemaining'))
if registrationsRemaining<=0:
return None,None,None,None
privateKeyPem,publicKeyPem,newPerson,webfingerEndpoint = \
createPersonBase(baseDir,nickname,domain,port,httpPrefix,saveToFile,password)
if noOfAccounts(baseDir)==1:
@ -249,6 +256,8 @@ def createPerson(baseDir: str,nickname: str,domain: str,port: int, \
copyfile(baseDir+'/img/image.png',baseDir+'/accounts/'+nickname+'@'+domain+'/image.png')
if os.path.isfile(baseDir+'/img/banner.png'):
copyfile(baseDir+'/img/banner.png',baseDir+'/accounts/'+nickname+'@'+domain+'/banner.png')
registrationsRemaining-=1
setConfigParam(baseDir,'registrationsRemaining',str(registrationsRemaining))
return privateKeyPem,publicKeyPem,newPerson,webfingerEndpoint
def createSharedInbox(baseDir: str,nickname: str,domain: str,port: int, \