def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.index')) form = ResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user is None: return redirect(url_for("main.index")) if validate_token(user=user, token=token, operation=Operations.RESET_PASSWORD, new_password=form.password.data): flash("Password updated", 'success') return redirect(url_for('.login')) else: flash("Invalid or expired link", "danger") return redirect(url_for('.forget_password')) return render_template('auth/reset_password.html', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.index')) user = User.verify_reset_password_token(token) if not user: return redirect(url_for('main.index')) form = ResetPasswordForm() if form.validate_on_submit(): user.set_password(form.password.data) user.save() flash('Your password has been reset.') return redirect(url_for('auth.login')) return render_template('views/auth/reset_password.html', form=form)
def reset_password(token): # if current_user.is_authenticated: # return redirect(url_for('main.index')) form = ResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower(),role_id = 1).first() if user is None: flash('用户不存在.','warning') return redirect(url_for('auth.login')) if validate_token(user=user, token=token, operation=Operations.RESET_PASSWORD, new_password=form.password.data): flash('密码重置成功.', 'success') return redirect(url_for('.login')) else: flash('链接无效或超时.', 'danger') return redirect(url_for('.forget_password')) return render_template('auth/reset_password.html', form=form)
def reset_password_token(token): if current_user.is_authenticated: return redirect(url_for('main.index')) user = User.decode_reset_password_token(token) if user: form = ResetPasswordForm() if form.validate_on_submit(): user.password = form.password.data # Send email db.session.add(user) db.session.commit() current_app.logger.info('%s has resetted the password', user.username) flash('Password alterada com sucesso!', 'success') return redirect(url_for('main.login')) return render_template('auth/reset.html', title='Reset Password', form=form) return redirect(url_for('main.reset_password_request'))
def reset_password(token): '''auth.reset_password(token)''' if current_user.is_authenticated: return redirect(current_user.index_url) form = ResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.strip().lower()).first() if user is None or not user.created or not user.activated or user.deleted: flash('用户邮箱错误', category='error') return redirect(url_for('auth.reset_password_request')) if user.reset_password(token, form.password.data): db.session.commit() flash('重置密码成功', category='success') add_user_log(user=user, event='重置密码', category='auth') return redirect(url_for('auth.login')) flash('重置密码失败', category='error') return redirect(url_for('auth.reset_password_request')) return minify(render_template( 'auth/reset_password.html', form=form, token=token ))