Skip to content

Commit f42956d

Browse files
committed
Updated #75 removed nested if and avoid using keys() as suggested
1 parent b57c2cf commit f42956d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

examples/simple.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
# function is used to actually generate the token
1414
@app.route('/login', methods=['POST'])
1515
def login():
16-
if request.is_json:
17-
params = request.get_json()
18-
if 'username' in params.keys() and 'password' in params.keys():
19-
if params['username'] != 'test' or params['password'] != 'test':
20-
return jsonify({"msg": "Bad username or password"}), 401
21-
else:
22-
return jsonify({"msg": "Missing auth parameters"}), 401
23-
24-
# Identity can be any data that is json serializable
25-
ret = {'access_token': create_access_token(identity=params['username'])}
26-
return jsonify(ret), 200
27-
else:
16+
if not request.is_json:
2817
return jsonify({"msg": "Missing auth"}), 401
18+
params = request.get_json()
19+
if 'username' in params and 'password' in params:
20+
if params['username'] != 'test' or params['password'] != 'test':
21+
return jsonify({"msg": "Bad username or password"}), 401
22+
else:
23+
return jsonify({"msg": "Missing auth parameters"}), 401
24+
25+
# Identity can be any data that is json serializable
26+
ret = {'access_token': create_access_token(identity=params['username'])}
27+
return jsonify(ret), 200
28+
29+
2930

3031
# Protect a view with jwt_required, which requires a valid access token
3132
# in the request to access.

0 commit comments

Comments
 (0)