Skip to content

Commit

Permalink
v0.9.15:Enhanced Auth Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
noahziheng committed Jun 19, 2018
1 parent fd004f5 commit f459ac2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions libfreeiot/core/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"""
import os
import datetime
from flask import request, jsonify
from bson import json_util
from flask import request, jsonify, Response
from flask_restful import Api
from flask_jwt_simple import JWTManager, create_jwt
from .resources.device import Device
Expand Down Expand Up @@ -44,13 +45,18 @@ def auth():
if not password:
return jsonify({"msg": "Missing password parameter"}), 400
if 'auth'in scope.keys():
if not scope["auth"].login(username, password):
authr = scope["auth"].login(username, password)
if not authr:
return jsonify({"msg": "Bad username or password"}), 401
else:
if username != 'admin' or password == 'admin':
return jsonify({"msg": "Bad username or password"}), 401

return jsonify({'jwt': create_jwt(identity=username)}), 200
res = authr or {}
res["jwt"] = create_jwt(identity=username)
return Response(
json_util.dumps(res),
mimetype='application/json'
), 200

# RESTFul API Routes definition
api = Api(app)
Expand Down
2 changes: 1 addition & 1 deletion libfreeiot/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"""

script_name = 'libfreeiot'
__version__ = '0.9.14'
__version__ = '0.9.15'

0 comments on commit f459ac2

Please sign in to comment.