Convert password removal to function

master
Bob Mottram 2019-07-05 10:49:57 +01:00
parent e18ea5dcbd
commit 36e83d174f
2 changed files with 12 additions and 9 deletions

10
auth.py
View File

@ -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)

View File

@ -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