Don't autocapitalize names

This commit is contained in:
Anthony Wang 2022-05-23 22:42:47 -05:00
parent f1e01dc348
commit f6056797c1
Signed by: a
GPG Key ID: BC96B00AEC5F2D76

21
api.py
View File

@ -11,7 +11,7 @@ class api(BaseHTTPRequestHandler):
def send(self, code, body):
"""Send HTTP response and body"""
print(code, body)
self.send_response(code)
self.send_header('Content-Type', 'text/plain')
@ -21,31 +21,32 @@ class api(BaseHTTPRequestHandler):
def usernew(self, data):
"""Register a new user"""
if data['code'] != code():
self.send(403, 'Nice try, but that secret code is totally wrong')
return
if not all(c.isdigit() or c.islower() for c in data['username']) or data['username'][0].isdigit():
self.send(403, 'I don\'t like that username')
return
# Add the user
adduser(data['username'], data['firstname'].capitalize(), data['lastname'].capitalize(),
data['email'], data['password'])
adduser(data['username'], data['firstname'],
data['lastname'], data['email'], data['password'])
self.send(200, 'Well I think it worked...')
def do_GET(self):
"""Handle GET requests"""
self.send(200, 'Hey there, you\'ve reached the top secret API')
def do_POST(self):
"""Handle API POST requests"""
content_length = int(self.headers['Content-Length'])
try:
data = dict(parse_qsl(self.rfile.read(content_length).decode('utf-8')))
data = dict(parse_qsl(self.rfile.read(
content_length).decode('utf-8')))
except:
self.send(400, 'Oops, that request doesn\'t look quite right')
@ -58,5 +59,5 @@ class api(BaseHTTPRequestHandler):
if self.path == '/api/user/new':
self.usernew(data)
return
self.send(501, 'We don\'t know how to do that yet')