def forgetpassword(): if request.method == "GET": return render_template("auth/forgetpassword.html") elif request.method == "POST": form = MdpForm(request.form) if form.validate(): email = form.email.data email += "@insa-lyon.fr" # No need for email, we ask the full email already person = Person.query.filter_by(email=email).first() if person is None: problem = u"L'utilisateur %s n'existe pas" % email flash(problem, u"error_forgetpassword") else: mdp = generate_mdp() problem = u"La demande de reinitialisation vous a été envoyée " person.password = hash_password(mdp) db.session.commit() mail_mot_de_passe_oublie(person.nickname, person.email, mdp) flash(problem, u"ok_forgetpassword") return render_template("auth/forgetpassword.html") else: problem = u"Problème dans le formulaire - Vous ne devez pas écrire @insa-lyon.fr" flash(problem, u"error_forgetpassword") return render_template("auth/forgetpassword.html")
def update_from_form(person, form): if form.password.data: form.password.data = hash_password(form.password.data) else: form.password.data = person.password if not form.image.data: form.image.data = person.image form.populate_obj(person) if form.goal.data: person.fitnessInfo.goal = int(form.goal.data) db.session.merge(person) db.session.commit()
def change_password(person, password): person.password = hash_password(password) db.session.commit() return