Skip to content

Commit fe659de

Browse files
committed
Remove one more level of nested if statemente
1 parent 3596b6b commit fe659de

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

examples/simple.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@
1414
@app.route('/login', methods=['POST'])
1515
def login():
1616
if not request.is_json:
17-
return jsonify({"msg": "Missing auth"}), 401
17+
return jsonify({"msg": "Missing JSON in request"}), 400
18+
1819
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
20+
username = params.get('username', None)
21+
password = params.get('password', None)
22+
23+
if not username:
24+
return jsonify({"msg": "Missing username paramater"}), 400
25+
if not password
26+
return jsonify({"msg": "Missing password paramater"}), 400
27+
28+
if username != 'test' or password != 'test':
29+
return jsonify({"msg": "Bad username or password"}), 401
2430

2531
# Identity can be any data that is json serializable
26-
ret = {'access_token': create_access_token(identity=params['username'])}
32+
ret = {'access_token': create_access_token(identity=username)}
2733
return jsonify(ret), 200
2834

29-
35+
3036

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

0 commit comments

Comments
 (0)