-1

I'm making an otp authentication for admin in my website, but as I'm trying to use this 'adopt' variable in my 'adrelog' function, it gives the error that 'adopt' variable is not defined. Please help me find out how to use this variable in 2 functions.

python code :

#admin password reset logic
adopt=" "
@app.route("/admin_repass", methods=["GET","POST"])
def Admin_reset_pass():
    email=str(request.form.get("email"))
    details=db.execute("select email from admin_master_tbl").fetchall()
    message="email not found"
    message1="enter your otp"
    for det in details:
        if email in det[0]:
            string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
            length = len(string)
            otp=""
            for i in range(6) :
                otp += string[math.floor(random.random() * length)]
            global adopt
            adotp=otp
            msg = Message("Subject", recipients=[email])
            msg.body = adopt
            mail.send(msg)
            return render_template("admin_relogin.html", message=message1)
        else:
            return render_template("admin_pass_reset.html", message=message)

@app.route("/admin_otp", methods=["GET","POST"])
def adrelog():
    global adopt
    message="login successfull"
    cotp=str(request.form.get("otp"))
    if adopt==cotp:
        return render_template("index.html", message=message)
    else:
        return "login failed"

html code 1 :

<html>
<body>
    <h2>{{message}}</h2>
    <form action="{{ url_for('Admin_reset_pass') }}" method="post" align:"center">
            <input type="text" name="email" placeholder="enter your mail for reset request">
                    <button>submit</button>
    </form>
</body>
</html>

html code 2:

<html>
<body>
    <form action="{{ url_for('adrelog') }}" method="post">
        <input type="text" name="otp" placeholder="enter your otp">
        <button>submit</button>
    </form>
</body>
</html>
stormcloak
  • 33
  • 7

1 Answers1

1

You can store them in session storage and access them in any view.

Hemant
  • 1,127
  • 1
  • 10
  • 18