diff --git a/Makefile b/Makefile index 15250f11c..edb11c279 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: debug: clean: - rm -f *.py~ Makefile~ README.md~ + rm -f *.md~ *.py~ *.json~ *.css~ Makefile~ rm -rf __pycache__ diff --git a/epicyon.py b/epicyon.py index 02d190175..1873527b8 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1193,6 +1193,8 @@ if args.testdata: password='boringpassword' print('Generating some test data for user: '+nickname) + setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations)) + createPerson(baseDir,'maxboardroom',domain,port,httpPrefix,True,password) createPerson(baseDir,'ultrapancake',domain,port,httpPrefix,True,password) createPerson(baseDir,'drokk',domain,port,httpPrefix,True,password) diff --git a/person.py b/person.py index c19b4acec..ab4fba225 100644 --- a/person.py +++ b/person.py @@ -23,6 +23,7 @@ from auth import storeBasicCredentials from roles import setRole from media import removeMetaData from utils import validNickname +from utils import noOfAccounts from config import setConfigParam from config import getConfigParam @@ -217,17 +218,6 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ return privateKeyPem,publicKeyPem,newPerson,webfingerEndpoint -def noOfAccounts(baseDir: str) -> bool: - """Returns the number of accounts on the system - """ - accountCtr=0 - for subdir, dirs, files in os.walk(baseDir+'/accounts'): - for account in dirs: - if '@' in account: - if not account.startswith('inbox'): - accountCtr+=1 - return accountCtr - def createPerson(baseDir: str,nickname: str,domain: str,port: int, \ httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}): """Returns the private key, public key, actor and webfinger endpoint diff --git a/utils.py b/utils.py index a78a3d515..d7a9e5fe0 100644 --- a/utils.py +++ b/utils.py @@ -200,3 +200,14 @@ def validNickname(nickname: str) -> bool: if nickname in reservedNames: return False return True + +def noOfAccounts(baseDir: str) -> bool: + """Returns the number of accounts on the system + """ + accountCtr=0 + for subdir, dirs, files in os.walk(baseDir+'/accounts'): + for account in dirs: + if '@' in account: + if not account.startswith('inbox'): + accountCtr+=1 + return accountCtr diff --git a/webinterface.py b/webinterface.py index c146037c7..a7a1d8704 100644 --- a/webinterface.py +++ b/webinterface.py @@ -17,6 +17,7 @@ from person import personBoxJson from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locatePost +from utils import noOfAccounts from follow import isFollowingActor from webfinger import webfingerHandle from posts import getPersonBox @@ -29,6 +30,7 @@ from like import likedByPerson from announce import announcedByPerson from blocking import isBlocked from content import getMentionsFromHtml +from config import getConfigParam def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str: """Shows the edit profile screen @@ -150,13 +152,18 @@ def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str): return nickname,password def htmlLogin(baseDir: str) -> str: + accounts=noOfAccounts(baseDir) + if not os.path.isfile(baseDir+'/accounts/login.png'): copyfile(baseDir+'/img/login.png',baseDir+'/accounts/login.png') if os.path.isfile(baseDir+'/img/login-background.png'): if not os.path.isfile(baseDir+'/accounts/login-background.png'): copyfile(baseDir+'/img/login-background.png',baseDir+'/accounts/login-background.png') - loginText='

Welcome. Please enter your login details below.

' + if accounts>0: + loginText='

Welcome. Please enter your login details below.

' + else: + loginText='

Please enter some credentials

You will become the admin of this site.

' if os.path.isfile(baseDir+'/accounts/login.txt'): with open(baseDir+'/accounts/login.txt', 'r') as file: loginText = '

'+file.read()+'

' @@ -164,6 +171,16 @@ def htmlLogin(baseDir: str) -> str: with open(baseDir+'/epicyon-login.css', 'r') as cssFile: loginCSS = cssFile.read() + # show the register button + registerButtonStr='' + if getConfigParam(baseDir,'registration')=='open': + if int(getConfigParam(baseDir,'registrationsRemaining'))>0: + registerButtonStr='' + + loginButtonStr='' + if accounts>0: + loginButtonStr='' + loginForm=htmlHeader(loginCSS) loginForm+= \ '
' \ @@ -177,9 +194,8 @@ def htmlLogin(baseDir: str) -> str: ' ' \ '' \ ' ' \ - ' ' \ - '' \ - ' ' \ + ' '+ \ + registerButtonStr+loginButtonStr+ \ ' ' \ '
' loginForm+=htmlFooter()