def send_bulk_email(): form = SendEmailForm(request.form) if form.validate_on_submit(): addAuditLog(AuditSeverity.MODERATION, current_user, "Sent bulk email", None, None, form.text.data) text = form.text.data html = render_markdown(text) for user in User.query.filter(User.email != None).all(): send_user_email.delay(user.email, form.subject.data, text, html) return redirect(url_for("admin.admin_page")) return render_template("admin/send_bulk_email.html", form=form)
def verify_email(): token = request.args.get("token") ver: UserEmailVerification = UserEmailVerification.query.filter_by( token=token).first() if ver is None: flash("Unknown verification token!", "danger") return redirect(url_for("homepage.home")) user = ver.user addAuditLog(AuditSeverity.USER, user, "Confirmed their email", url_for("users.profile", username=user.username)) was_activating = not user.is_active if ver.email and user.email != ver.email: if User.query.filter_by(email=ver.email).count() > 0: flash("Another user is already using that email", "danger") return redirect(url_for("homepage.home")) flash("Confirmed email change", "success") if user.email: send_user_email.delay( user.email, "Email address changed", "Your email address has changed. If you didn't request this, please contact an administrator." ) user.is_active = True user.email = ver.email db.session.delete(ver) db.session.commit() if ver.is_password_reset: login_user(user) user.password = None db.session.commit() return redirect(url_for("users.set_password")) if current_user.is_authenticated: return redirect( url_for("users.profile", username=current_user.username)) elif was_activating: flash("You may now log in", "success") return redirect(url_for("users.login")) else: return redirect(url_for("homepage.home"))
def send_single_email(): username = request.args["username"] user = User.query.filter_by(username=username).first() if user is None: abort(404) next_url = url_for("users.profile", username=user.username) if user.email is None: flash("User has no email address!", "danger") return redirect(next_url) form = SendEmailForm(request.form) if form.validate_on_submit(): addAuditLog(AuditSeverity.MODERATION, current_user, "Sent email to {}".format(user.display_name), url_for("users.profile", username=username)) text = form.text.data html = render_markdown(text) task = send_user_email.delay(user.email, form.subject.data, text, html) return redirect(url_for("tasks.check", id=task.id, r=next_url)) return render_template("admin/send_email.html", form=form, user=user)
def emit(self, record): text = self.format(record) if self.formatter else None html = "<pre>{}</pre>".format(text) for email in self.send_to: send_user_email.delay(email, self.getSubject(record), text, html)