Set a user's wiki password with auth server

This commit is contained in:
Tanner Collin 2020-09-16 22:14:27 +00:00
parent 53ae4c31bb
commit 6b841f3a78
3 changed files with 33 additions and 5 deletions

View File

@ -1,15 +1,38 @@
from log import logger
import time
import secrets
import subprocess
from flask import abort
HTTP_NOTFOUND = 404
def set_password(username, password):
# TODO
print(username, password)
def set_wiki_password(username, password):
# sets a user's wiki password
# creates the account if it doesn't exist
if not username:
logger.error('Empty username, aborting')
abort(400)
logger.info('Setting wiki password for: ' + username)
if not password:
logger.error('Empty password, aborting')
abort(400)
script = secrets.WIKI_MAINTENANCE + '/createAndPromote.php'
result = subprocess.run(['php', script, '--force', username, password],
shell=False, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = result.stdout or result.stderr
logger.info('Output: ' + output)
if result.stderr:
abort(400)
if __name__ == '__main__':
print(set_password('test.test', 'password'))
set_wiki_password('tanner.collin', 'protospace1')
pass

View File

@ -5,3 +5,8 @@
# For example, use the first output of this:
# head /dev/urandom | sha1sum
AUTH_TOKEN = ''
# Absolute path of Mediawiki maintenance directory
# Probably:
# /var/www/wiki/maintenance
WIKI_MAINTENANCE = ''

View File

@ -22,7 +22,7 @@ def set_password():
username = request.form['username']
password = request.form['password']
auth_functions.set_password(username, password)
auth_functions.set_wiki_password(username, password)
return ''
if __name__ == '__main__':