Restructure API so the user registration endpoint is /api/user/new
This commit is contained in:
parent
471cc8d254
commit
cf559d1e2e
32
api.py
32
api.py
|
@ -19,6 +19,22 @@ class api(BaseHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(body.encode('utf-8'))
|
self.wfile.write(body.encode('utf-8'))
|
||||||
|
|
||||||
|
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'])
|
||||||
|
self.send(200, 'Well I think it worked...')
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
"""Handle GET requests"""
|
"""Handle GET requests"""
|
||||||
|
|
||||||
|
@ -39,20 +55,8 @@ class api(BaseHTTPRequestHandler):
|
||||||
debug.pop('confirmpassword')
|
debug.pop('confirmpassword')
|
||||||
print(debug)
|
print(debug)
|
||||||
|
|
||||||
if self.path == '/api/join':
|
if self.path == '/api/user/new':
|
||||||
# New user
|
self.usernew(data)
|
||||||
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'])
|
|
||||||
|
|
||||||
self.send(200, 'Well I think it worked...')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.send(501, 'We don\'t know how to do that yet')
|
self.send(501, 'We don\'t know how to do that yet')
|
||||||
|
|
Loading…
Reference in a new issue