File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change 1414@app .route ('/login' , methods = ['POST' ])
1515def 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.
You can’t perform that action at this time.
0 commit comments