Rewrite srvuser API to parse application/x-www-form-urlencoded
This commit is contained in:
parent
aa548d1d7f
commit
1c73d74f75
25
srvuser.py
25
srvuser.py
|
@ -1,5 +1,5 @@
|
||||||
from subprocess import run, check_output
|
from subprocess import run, check_output
|
||||||
from json import loads
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
from http.server import BaseHTTPRequestHandler
|
from http.server import BaseHTTPRequestHandler
|
||||||
from adduser import adduser
|
from adduser import adduser
|
||||||
|
@ -9,14 +9,29 @@ from ldappass import code
|
||||||
class srvuser(BaseHTTPRequestHandler):
|
class srvuser(BaseHTTPRequestHandler):
|
||||||
"""User management HTTP server"""
|
"""User management HTTP server"""
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
"""Handle GET requests"""
|
||||||
|
|
||||||
|
body = 'It worked!'
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-Type', 'text/plain')
|
||||||
|
self.send_header('Content-Length', str(len(body)))
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(body.encode('utf-8'))
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
"""Handle registration POST requests"""
|
"""Handle API POST requests"""
|
||||||
|
|
||||||
content_length = int(self.headers['Content-Length'])
|
content_length = int(self.headers['Content-Length'])
|
||||||
data = loads(self.rfile.read(content_length).decode('utf-8'))
|
data = parse_qs(self.rfile.read(content_length).decode('utf-8'))
|
||||||
print([data[key] for key in data.keys() if key != 'password']) # Print data
|
|
||||||
|
|
||||||
if data['type'] == 'new':
|
# Print debug data
|
||||||
|
debug = data.copy()
|
||||||
|
debug.pop('password')
|
||||||
|
debug.pop('confirmpassword')
|
||||||
|
print(debug)
|
||||||
|
|
||||||
|
if self.path == '/api/join':
|
||||||
# New user
|
# New user
|
||||||
if data['code'] != code():
|
if data['code'] != code():
|
||||||
print('Incorrect code')
|
print('Incorrect code')
|
||||||
|
|
Loading…
Reference in a new issue