forked from indymedia/epicyon
Convert password removal to function
parent
e18ea5dcbd
commit
36e83d174f
10
auth.py
10
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)
|
||||
|
|
11
epicyon.py
11
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
|
||||
|
|
Loading…
Reference in New Issue