def reset_pass():
    if 'db-access' in session:

        if request.method == "POST":
            form = request.form
            email = form['email']
            password = form['passowrd']
            conf_password = form['confirm-password']
            designation = form['designation']

            if check_reset_password_form(email, password, conf_password):
                reset_password(db_name, email, password, designation)

        return render_template('reset-pass.html')
    else:
        return redirect('/')
Esempio n. 2
0
def reset_password():
    form = forms.ResetPasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        salt, hash = logins.create_password_salt(form.new_password.data)
        if database.reset_password(form.username.data, form.reset_code.data,
                                   salt, hash):
            return redirect("/login")
        return render_template(
            "reset_password.html",
            form=form,
            error="Reset failed, credentials provided are invalid.")
    return render_template("reset_password.html", form=form)
Esempio n. 3
0
def reset_password(token):
    if request.method == "POST":

        email = request.form["email"]
        if email != session["email"]:
            return render_template("home.html", correct={"reset_password":True}, token=token, bad_reset=True, error="Emails do not match.")
        elif request.form["password"] != request.form["password-two"]:
            return render_template("home.html", correct={"reset_password":True}, token=token, bad_reset=True, error="Passwords must match.")
        else:
            try:
                database.reset_password(email, password=request.form["password"])
                return render_template("home.html", correct={"login":True}, bad_login=True, error="Your password has been reset.")
            except:
                return render_template("home.html", correct={"reset_password":True}, token=token, bad_reset=True, error="Password could not be reset. Contact System Administrator.")
    else:
        email = security.confirm_token(token)
        if email:
            session["email"] = email
            return render_template("home.html", correct={"reset_password":True}, token=token, bad_reset=False)
        else:
            return render_template("home.html", correct={"login":True}, bad_login=True, error="Invalid token, email could not be reset.")