mardi 23 octobre 2018

Creating users in text or json file and use it to the login to the python web

I've made simple web. This is the method which I use to basic login to the web:

@app.route('/signin/', methods=['GET', 'POST'])
def signin_page():
    error = None
    try:
        if request.method == "POST":
            attempted_email= request.form['email']
            attempted_password = request.form['password']

            flash(attempted_email)
            flash(attempted_password)

            if attempted_email == "admin@gmail.com" and attempted_password == "admin":
                return redirect(url_for('homepage'))
            else:
                error = "Invalid credentials. Try again."

    except Exception as e:
        flash(e)
        return render_template("signin.html", error = error)

How can I modify that code if i want to take the users data from txt or json file (i want to make it using basic editor txt), which contains information about users (email, password, etc.) How can I compare typed string in login form with content of the file?




Aucun commentaire:

Enregistrer un commentaire