bug: token bug fix

parent bf3ec49c
......@@ -17,7 +17,8 @@ from functools import wraps
def check_for_token(func):
@wraps(func)
def wrapped(*args, **kwargs):
token = request.args.get('Token')
token = request.headers['Authorization']
print("abcccccc")
print(token)
if not token:
return Response(
......@@ -25,22 +26,9 @@ def check_for_token(func):
status=200,
# need to find a way to continue the rest of called API, currently it shows the above message
)
try:
data=jwt.decode(token, 'app.SECRET_KEY', ['HS256'])
# return "123"
# return Response(
# response= json.dumps({"message": data}),
# status=200,
# need to find a way to continue the rest of called API, currently it shows the above message
# )
except:
return Response(
response= json.dumps({"message": "invalid token"}),
status=200,
# need to find a way to continue the rest of called API, currently it shows the above message
)
data=jwt.decode(token, 'app.SECRET_KEY', ['HS256'])
session['Auth'] = data
return func(*args, **kwargs)
return wrapped
......@@ -77,11 +65,14 @@ def login():
if dbResponse:
email = dbResponse["email"]
print(email)
id = str(dbResponse.get('_id'))
print(dbResponse.get('_id'))
if email == request.form['email'] and request.form["password"]:
session['user'] = request.form['email']
token = jwt.encode({
'user': request.form['email']
'user': request.form['email'],
'_id': id
}, 'app.SECRET_KEY')
return Response(
......
......@@ -24,7 +24,7 @@ print(redisClient)
# return str
@app.route("/getDetails", methods=["POST"])
@check_for_token
# @check_for_token
def get_point_redis():
earn_gain = "Earn_gained"
......
......@@ -3,13 +3,13 @@ from Main import app
# from flask import Blueprint
from flask import Response, request, session
from flask import Response, request
# import pymongo
import json
from bson.objectid import ObjectId
import Agripreneur_App.Auth.Token
from Agripreneur_App.Auth.Token import check_for_token
from werkzeug.security import generate_password_hash, check_password_hash
......@@ -92,8 +92,14 @@ def get_some_users():
# ====update user====
@app.route("/updateUsers/<id>", methods=["PUT"])
@check_for_token
def update_user(id):
request.headers
print("heeee")
id = session['Auth']['_id']
try:
dbResponse = db.users.update_one(
{"_id": ObjectId(id)},
{"$set": {"name": request.form["name"]}},upsert=True)
......@@ -125,7 +131,10 @@ def update_user(id):
# ====delete user====
@app.route("/deleteUsers/<id>", methods=["DELETE"])
@check_for_token
def delete_user(id):
request.headers
id = session['Auth']['_id']
try:
dbResponse = db.users.delete_one({"_id": ObjectId(id)},)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment