master
Bob Mottram 2019-07-05 10:51:58 +01:00
parent 36e83d174f
commit 5bb7b73af3
1 changed files with 7 additions and 0 deletions

View File

@ -85,6 +85,8 @@ def authorizeBasic(baseDir: str,path: str,authHeader: str,debug: bool) -> bool:
return False return False
def storeBasicCredentials(baseDir: str,nickname: str,password: str) -> bool: def storeBasicCredentials(baseDir: str,nickname: str,password: str) -> bool:
"""Stores login credentials to a file
"""
if ':' in nickname or ':' in password: if ':' in nickname or ':' in password:
return False return False
nickname=nickname.replace('\n','').strip() nickname=nickname.replace('\n','').strip()
@ -115,6 +117,9 @@ def storeBasicCredentials(baseDir: str,nickname: str,password: str) -> bool:
return True return True
def removePassword(baseDir: str,nickname: str) -> None: def removePassword(baseDir: str,nickname: str) -> None:
"""Removes the password entry for the given nickname
This is called during account removal
"""
passwordFile=baseDir+'/accounts/passwords' passwordFile=baseDir+'/accounts/passwords'
if os.path.isfile(passwordFile): if os.path.isfile(passwordFile):
with open(passwordFile, "r") as fin: with open(passwordFile, "r") as fin:
@ -125,6 +130,8 @@ def removePassword(baseDir: str,nickname: str) -> None:
os.rename(passwordFile+'.new', passwordFile) os.rename(passwordFile+'.new', passwordFile)
def authorize(baseDir: str,path: str,authHeader: str,debug: bool) -> bool: def authorize(baseDir: str,path: str,authHeader: str,debug: bool) -> bool:
"""Authorize using http header
"""
if authHeader.lower().startswith('basic '): if authHeader.lower().startswith('basic '):
return authorizeBasic(baseDir,path,authHeader,debug) return authorizeBasic(baseDir,path,authHeader,debug)
return False return False