Possibly support more srvuser request types in the future
This commit is contained in:
parent
105c297886
commit
677d1a9458
33
srvuser.py
33
srvuser.py
|
@ -1,5 +1,6 @@
|
|||
from subprocess import run, check_output
|
||||
from json import loads
|
||||
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
from adduser import adduser
|
||||
from ldappass import code
|
||||
|
@ -13,21 +14,25 @@ class srvuser(BaseHTTPRequestHandler):
|
|||
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
data = loads(self.rfile.read(content_length).decode('utf-8'))
|
||||
# Print data
|
||||
print([data[key] for key in data.keys() if key != 'password'])
|
||||
print([data[key] for key in data.keys() if key != 'password']) # Print data
|
||||
|
||||
if data['code'] != code():
|
||||
print('Incorrect code')
|
||||
return
|
||||
if not all(c.isdigit() or c.islower()
|
||||
for c in data['username']) or data['username'][0].isdigit():
|
||||
print('Bad username')
|
||||
return
|
||||
if data['type'] == 'new':
|
||||
# New user
|
||||
if data['code'] != code():
|
||||
print('Incorrect code')
|
||||
self.send_response(403)
|
||||
return
|
||||
if not all(c.isdigit() or c.islower() for c in data['username']) or data['username'][0].isdigit():
|
||||
print('Bad username')
|
||||
self.send_response(403)
|
||||
return
|
||||
|
||||
# Add the user
|
||||
adduser(data['username'], data['firstname'].capitalize(), data['lastname'].capitalize(),
|
||||
data['email'], data['password'])
|
||||
# Add the user
|
||||
adduser(data['username'], data['firstname'].capitalize(), data['lastname'].capitalize(),
|
||||
data['email'], data['password'])
|
||||
else:
|
||||
print('Bad request')
|
||||
self.send_response(400)
|
||||
return
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
|
|
Loading…
Reference in a new issue