def forgot_password(): form = ForgotPasswordForm(request.form) if form.validate_on_submit(): # generating a random token to send to the user email user_email = form.email.data try: print("here") user = User.query.filter_by(email=user_email).one() verification_code = verification_code = ''.join([ random.choice( string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(1,48) ]) msg = Message('MSTS Password Reset', sender="*****@*****.**", recipients=[user_email], ) msg.html = render_template('users/forgot_password_email.html',verification_code = verification_code) try: mail.send(msg) except socket.error as e: print("Message not successfully sent") except MultipleResultsFound as e: pass except NoResultFound as e: pass flash("If this email address has a registered account, we have sent an email with instructions on how to recover your account.","alert-success") print(form.errors) return render_template('users/forgot_password.html',form=form)
def forgotPassword(): form = ForgotPasswordForm() if form.validate_on_submit(): connection = sqlite3.connect('data/site.db') cur = connection.cursor() for row in cur.execute("SELECT username, password from user_data"): if form.username.data == row[0]: flash( "A new password has been sent to your email so you can reset your password !" ) resetPassword = generateRandomPassword() salt = bcrypt.gensalt() newResetPassword = bcrypt.hashpw(resetPassword.encode(), salt) username = form.username.data cur.execute("Update user_data set password=? where username=?", (newResetPassword, username)) connection.commit() cur.close() msg = Message('Forgot Password from Jean-Francois Website', recipients=[form.username.data]) msg.body = "Your password has been reset. Your new password is now : " + resetPassword + "\nYou can change your password with it." mail.send(msg) return redirect('/login') flash("There is no account associated with that email. ") return redirect('/forgotPassword') return render_template('forgotPassword.html', form=form)
def forgot_password_form(): form = ForgotPasswordForm() if current_user.is_authenticated: # Making sure the user is not logged in. return redirect(url_for('home')) if form.validate_on_submit(): user = find_user(form.username.data) # Checking if the user exists. if user: send_password_reset_email(user) flash( 'Check your email for the instructions to reset your password!', 'success') return redirect(url_for('password_reset_response')) return render_template("ForgotPassword.html", form=form)
def forgot(): form = ForgotPasswordForm() if form.validate_on_submit(): try: user = User.get(User.email == form.email.data) except User.DoesNotExist: flash('No account with that email was found.') return redirect(url_for('forgot')) send_recovery_email(form.email.data) flash('A recovery link will be sent to your email.') return redirect(url_for('index')) else: return render_template('forgot.html', form=form)
def forgot_password(user): if current_user.is_authenticated: return redirect(url_for('main')) user_object = db.session.query(relations.User).filter_by(id=user).first() question = user_object.question password= "" form = ForgotPasswordForm() if form.validate_on_submit(): if user and user_object.answer==form.answer.data: password= user_object.password return render_template('forgot_password.html', form=form, password=password, question=question) flash("Invalid Answer") return redirect(url_for('forgot_password', user=user)) return render_template('forgot_password.html', form=form, password=password, question=question)
def forgot_passwd(): form = ForgotPasswordForm(request.form) if form.validate_on_submit(): user = request.form['email'] if User.query.filter_by(email=user).first(): q = User.query.filter_by(email=user).first() forgot_password(user, q.password) return redirect(request.args.get("next") or url_for("login")) else: flash('Username not found') return redirect(request.args.get("next") or url_for("login")) return render_template("forgot_passwd.html", title="Forgot Password", form=form)
def forgot_passwd(): form = ForgotPasswordForm(request.form) if form.validate_on_submit(): user = request.form['email'] if User.query.filter_by(email=user).first(): q = User.query.filter_by(email=user).first() forgot_password(user, q.password) return redirect(request.args.get("next") or url_for("login")) else: flash('Username not found') return redirect(request.args.get("next") or url_for("login")) return render_template("forgot_passwd.html", title="Forgot Password", form=form)
def forgot_password(): form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() serialized_token = get_serialized_token(user, 'reset') send_reset_password_email(user, serialized_token) flash(msgs['SEND_RESET_EMAIL']) return redirect(url_for('.login')) for field in form.errors: flash('<strong>' + field.capitalize() + '</strong>' + ': ' + form.errors[field][0], 'error') login_link = '<p>Remembered your password? <a href="' + url_for('.login') + '">Click here to log in.</a></p>' return render_template('forgot_password.html', form=form, login=login_link)
def forgot(): form = ForgotPasswordForm() if form.validate_on_submit() or request.method == 'POST': cursor = db.cursor() sql = """SELECT * FROM USER WHERE U_id = '%s' AND Email = '%s'""" \ % (form.user_id.data, form.email.data) cursor.execute(sql) result = cursor.fetchall() cursor.close() # ID Chcek if len(result) is 1: session['forgot_user'] = form.user_id.data return redirect(url_for('reset')) return render_template('forgot.html', form=form)
def forgot_passwd(): meta = Metaindex.query.order_by(Metaindex.id.desc()).first() form = ForgotPasswordForm(request.form) if form.validate_on_submit(): user = request.form['email'] if User.query.filter_by(email=user).first(): q = User.query.filter_by(email=user).first() forgot_password(user, q.password) return redirect(request.args.get("next") or url_for("login")) else: flash('Usuario no enconstrado') return redirect(request.args.get("next") or url_for("login")) return render_template ("forgot_passwd.html", title="Recuperacion de contrase&ntide;a", form=form)
def forgot_passwd(): form = ForgotPasswordForm(request.form) if form.validate_on_submit(): user = request.form['email'] if User.query.filter_by(email=user).first(): q = User.query.filter_by(email=user).first() login_user(q) user = g.user # forgot_password(user, q.password) app.logger.debug('ready to change the password') return redirect(request.args.get("next") or url_for("new_pass")) else: flash('Username not found', 'error') # return redirect(request.args.get("next") or url_for("login")) return render_template("forgot_passwd.html", title="Forgot Password", form=form)
def forgot_password(): form = ForgotPasswordForm() if form.validate_on_submit(): #MySQL Integration cur = mysql.connection.cursor() result = cur.execute("SELECT password FROM users WHERE email = %s", [form.email.data]) if result > 0: newPassword = str(uuid.uuid4()) cur.execute("UPDATE users SET password = %s WHERE email = %s", (sha256_crypt.hash(str(newPassword)), form.email.data)) mysql.connection.commit() msg = Message('Reset my codon.io password!', recipients = [form.email.data]) msg.body = "Here is your new password: "******"We sent the required information to your email adress!", msg_type_to_color["success"]) else: cur.close() flash("Email not found!", msg_type_to_color["error"]) return render_template("forgot_password.html", form=form)
def forgot_password(): """Forgot password""" form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.get(form.email.data) if user is None: flash('Email does not exist') else: temp_password = str(uuid.uuid4())[:8] user.password = bcrypt.generate_password_hash(temp_password) db.session.add(user) db.session.commit() send_forgot_password_email(user, temp_password) return redirect(url_for("index")) return render_template("forgot_password.html", form=form)
def forgot_password(): form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: s = get_url_serializer(current_app) token = s.dumps(user.email, salt='recovery-key') context = { 'first_name': user.first_name, 'token': token } print(url_for('auth.reset', token=token, _external=True)) send_email( recipients=[user.email], subject='Password Reset', template_name='password_reset', **context ) flash('Email with link to reset password has been sent') return redirect(url_for('auth.login')) return render_template('auth/forgot_password.html', form=form)
def reset(): """ send reset password email to specified user email @return: refreshed page indicating success or failure """ form = ForgotPasswordForm() if form.validate_on_submit(): user = User.get(form.forgot_email.data) subject = "Password reset requested" token = ts.dumps(user.id, salt='recover-key') recover_url = url_for('reset_with_token', token=token, _external=True) html = render_template('recover.html', recover_url=recover_url) msg = Message(subject, sender=config.MAIL_USERNAME, recipients=[user.id]) msg.body = html mail.send(msg) flash('Password reset email sent to ' + user.id) return redirect(url_for('login')) return render_template('login.html', loginform=EmailPasswordForm(), forgotpw=ForgotPasswordForm())