- Improved api return content
- Check if user exists already
This commit is contained in:
parent
6cbef534de
commit
26348b1aa6
@ -16,7 +16,7 @@ def users():
|
||||
for i in User.query.all():
|
||||
res.append(i.as_dict())
|
||||
|
||||
return jsonify(res)
|
||||
return jsonify({"status": 200, "data": res})
|
||||
|
||||
|
||||
@api.route('/login', methods=['POST'])
|
||||
@ -27,15 +27,16 @@ def login():
|
||||
|
||||
user = User.filter_by(username=username).first()
|
||||
if check_password(user.password, password):
|
||||
return True # TODO Return token
|
||||
# TODO Return token
|
||||
return jsonify({"status": 200, "text": "Successfully logged in"})
|
||||
else:
|
||||
return False
|
||||
return jsonify({"status": 500, "text": "Unable to login"})
|
||||
|
||||
|
||||
@api.route('/logout', methods=['GET'])
|
||||
def logout():
|
||||
# TODO
|
||||
pass
|
||||
return jsonify({"status": 200, "text": "Successfully logged out"})
|
||||
|
||||
|
||||
@api.route('/register', methods=['POST'])
|
||||
@ -44,6 +45,8 @@ def register():
|
||||
username = request_data['username']
|
||||
password = request_data['password']
|
||||
|
||||
if User.filter_by(username=username).first() is None:
|
||||
# Username doesn't exist yet
|
||||
user = User(
|
||||
username=username,
|
||||
password=hash_password(password),
|
||||
@ -52,4 +55,6 @@ def register():
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
pass
|
||||
return jsonify({"status": 200, "text": "Successfully registered user", "data": user.as_dict()})
|
||||
else:
|
||||
return jsonify({"status": 500, "text": "Username already exist"})
|
||||
|
Loading…
Reference in New Issue
Block a user