diff --git a/auth.py b/auth.py index 38a8df3d..aa238f68 100644 --- a/auth.py +++ b/auth.py @@ -114,6 +114,16 @@ def storeBasicCredentials(baseDir: str,nickname: str,password: str) -> bool: passfile.write(storeStr+'\n') return True +def removePassword(baseDir: str,nickname: str) -> None: + passwordFile=baseDir+'/accounts/passwords' + if os.path.isfile(passwordFile): + with open(passwordFile, "r") as fin: + with open(passwordFile+'.new', "w") as fout: + for line in fin: + if not line.startswith(nickname+':'): + fout.write(line) + os.rename(passwordFile+'.new', passwordFile) + def authorize(baseDir: str,path: str,authHeader: str,debug: bool) -> bool: if authHeader.lower().startswith('basic '): return authorizeBasic(baseDir,path,authHeader,debug) diff --git a/epicyon.py b/epicyon.py index aadd2e0e..89ed52f7 100644 --- a/epicyon.py +++ b/epicyon.py @@ -39,6 +39,7 @@ from tests import runAllTests from config import setConfigParam from config import getConfigParam from auth import storeBasicCredentials +from auth import removePassword import argparse def str2bool(v): @@ -186,15 +187,7 @@ if args.rmaccount: sys.exit() handle=nickname+'@'+domain accountRemoved=False - passwordFile=baseDir+'/accounts/passwords' - if os.path.isfile(passwordFile): - # remove from passwords file - with open(passwordFile, "r") as fin: - with open(passwordFile+'.new', "w") as fout: - for line in fin: - if not line.startswith(nickname+':'): - fout.write(line) - os.rename(passwordFile+'.new', passwordFile) + removePassword(baseDir,nickname) if os.path.isdir(baseDir+'/accounts/'+handle): shutil.rmtree(baseDir+'/accounts/'+handle) accountRemoved=True