diff options
Diffstat (limited to 'routes/auth.py')
| -rw-r--r-- | routes/auth.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/routes/auth.py b/routes/auth.py index ebf52c0..a34aaa5 100644 --- a/routes/auth.py +++ b/routes/auth.py @@ -15,5 +15,19 @@ from ..helpers import * @route("/api/auth", method="POST") -def post_auth(): - raise HTTPResponse(status=501) +def post_auth_new(): + session = DBSession() + try: + username = request.forms.username + password = request.forms.password + except KeyError as e: + raise HTTPResponse("Username or password missing", 400) + + hash = calculateUserHash(username, password).hexdigest() + try: + session.query(User).filter(User.name == username or User.hash == hash).one() + raise HTTPResponse("User already exists", status=410) + except db.orm.exc.NoResultFound: + session.add(User(name=username, hash=hash)) + session.commit() + return HTTPResponse(status=201) |
