diff options
| author | Fulgen301 <tokmajigeorge@gmail.com> | 2018-08-26 20:08:54 +0200 |
|---|---|---|
| committer | Fulgen301 <tokmajigeorge@gmail.com> | 2018-08-26 20:08:54 +0200 |
| commit | 305383c4b85dd6c826cb41faa42fd97015f33067 (patch) | |
| tree | ead97e4c63de382a6ca20a026f2d9b12b21fc8a6 /routes/auth.py | |
| parent | 50622f038d63490277d610a83fe095ee000f2b98 (diff) | |
| download | parry-305383c4b85dd6c826cb41faa42fd97015f33067.tar.gz parry-305383c4b85dd6c826cb41faa42fd97015f33067.zip | |
Rewrite database system with sqlalchemy, add /api/auth, add /api/uploads/<id>comments
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) |
