Commit c7200b07 authored by Willard's avatar Willard

Make new_user() return JSON

parent 15337921
...@@ -43,22 +43,26 @@ def search(): ...@@ -43,22 +43,26 @@ def search():
@app.route('/api/users/new', methods=['POST']) @app.route('/api/users/new', methods=['POST'])
def new_user(): def new_user():
result = {success: True, message: ''}
username = request.form['username'] username = request.form['username']
email = request.form['email'] email = request.form['email']
password = request.form['password'] password = request.form['password']
user = User.query.filter_by(username=username).first() user = User.query.filter_by(username=username).first()
if user is not None: if user is not None:
return 'Username is already taken!' result['success'] = False
result['message'] = 'username'
user = User.query.filter_by(email=email).first() user = User.query.filter_by(email=email).first()
if user is not None: if user is not None:
return 'Email address is already taken!' result['success'] = False
result['message'] = 'email'
user = User(username, email, password) user = User(username, email, password)
db.session.add(user) db.session.add(user)
db.session.commit() db.session.commit()
return 'User account successfully created!' return result
@auth.verify_password @auth.verify_password
def verify_password(username, password): def verify_password(username, password):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment