简体   繁体   English

我无法在基于 Flask 令牌的授权 2.o 中实现 API

[英]I can't implement API in flask token based authorization 2.o

Need help to implement token based authorization steps and solution.需要帮助来实施基于令牌的授权步骤和解决方案。 I am using flask as back-end and html and CSS front-end.我使用 Flask 作为后端,使用 html 和 CSS 前端。 But i am facing difficulty to find best content about api.但是我很难找到有关 api 的最佳内容。 my purpose is to build user login and registrations我的目的是建立用户登录和注册

This is my code这是我的代码

#database MySQL #数据库 MySQL

from flask import Flask, render_template, request, redirect, url_for,jsonify
import db
import datetime
import time
app = Flask(__name__)
cursor, conn = db.connection(app)



@app.route("/")
def index():
    return render_template("signup.html", title="SignUp")

@app.route("/signUp", methods = ["POST"])

def signUp():
    username=str(request.form["user"])
    password = str(request.form["password"])
    email = str(request.form["email"])
    cursor = conn.cursor()
    cursor.execute("INSERT INTO users(name, password, email)VALUES(%s, %s, %s)", (username, password, email))
    conn.commit()
    conn.close()
    return redirect(url_for("login"))

@app.route("/login")
def login():
    return render_template("login.html", title="data")

@app.route("/checkUser", methods=["POST"])
def check():
    username = str(request.form["user"])
    password = str(request.form["password"])
    cursor.execute("SELECT * FROM users where name = %s and password=%s", (username, password))
    users = cursor.fetchone()
    if users is None:
        return "username is wrong"
    else:
        return render_template("home.html")
@app.route("/home")
def home():
    return render_template("home.html")


if __name__ == "__main__":``
    app.run(debug=True)
db.py

from flaskext.mysql import MySQL
import config

def connection(app):
    mysql = MySQL()
    app.config['MYSQL_DATABASE_USER'] = config.dbuser
    app.config['MYSQL_DATABASE_PASSWORD'] = config.dbpassword
    app.config['MYSQL_DATABASE_DB'] = config.dbname
    app.config['MYSQL_DATABASE_HOST'] = config.dbhost
    mysql.init_app(app)
    conn = mysql.connect()
    cursor = conn.cursor()
    return cursor, conn

#config.py
dbuser = 'root'
dbpassword = ''
dbname = 'login_data'
dbhost = 'localhost'
debug = True
secret = 'flask-auth'
port = 8080

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过发布请求将授权令牌发送到Flask API - Can't send authorization token to flask api with post request Flask:基于令牌的授权 - Flask: token-based authorization 对于 REST API,我可以使用 flask-login 提供的身份验证机制,还是必须明确使用基于令牌的身份验证,如 JWT? - For a REST API, can I use authentication mechanism provided by flask-login or do I explicitly have to use token based authentication like JWT? 我可以将会话用于基于 Flask 的 REST API 吗? - Can I use sessions for a Flask-based REST API? Flask OAuth 2.0 授权码流 使用 Fitbit 的授权令牌无效 API - Flask OAuth 2.0 Authorization Code Flow Invalid Authorization Token with Fitbit API 如何使用基于 JWT 令牌的授权来保护 fastapi API 端点? - How to secure fastapi API endpoint with JWT Token based authorization? 在 AWS-Lambda(Python) 中,我如何调用需要在 header 中进行令牌授权的外部 API - In AWS-Lambda(Python), how can I Invoke External API which needs Token Authorization in the header Flask中基于令牌的身份验证 - Token based authentication in Flask 我无法使用 Barer 令牌将我的 POST 方法发送到 API - I can't send my POST method to the API with Barer Token 如何配置Flask API以允许使用令牌保护的用户特定响应? - How can I configure a Flask API to allow for token-protected user-specific responses?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM