I need help with a question
Q: The admin web api must be able to confirm admin’s credentials using email and password.
I would say I have really basic knowledge of the GET, POST, DELETE request. But I am unsure of using these to do verification.
What I have tried:
I have come up with the below codes but am still not sure what I need to correct to get it work. Any explanation or advice is very appreciated..
In User.py, I have:
from model.DatabasePool import DatabasePool
class User:
@classmethod
def verifyUser(cls,email,password):
try:
dbConn=DatabasePool.getConnection()
cursor = dbConn.cursor(dictionary=True)
sql="select * from user where email=%s and password=%s"
cursor.execute(sql,(email,password))
user=cursor.fetchall()
return user
finally:
dbConn.close()
and in my app.py, I have:
<pre>from flask import Flask,jsonify,request
from model.User import User
from model.Menu import Menu
from model.Category import Category
app = Flask(__name__)
@app.route('/user',methods=["GET"])
def verifyUser():
try:
userJSON=request.json
user=User.verifyUser(userJSON['email'],userJSON['password'])
message={"Message":"Success"}
return jsonify(message),200
except Exception as err:
print(err)
return {},500
if __name__ == '__main__':
app.run(debug=True)