Add manual email support
This commit is contained in:
parent
a68ac9cb4d
commit
fbf374ff5d
|
@ -32,7 +32,7 @@ app.config["FLATPAGES_EXTENSION"] = ".md"
|
||||||
app.config.from_pyfile(os.environ["FLASK_CONFIG"])
|
app.config.from_pyfile(os.environ["FLASK_CONFIG"])
|
||||||
|
|
||||||
menu.Menu(app=app)
|
menu.Menu(app=app)
|
||||||
Markdown(app, extensions=["fenced_code"], safe_mode=True, output_format="html5")
|
markdown = Markdown(app, extensions=["fenced_code"], safe_mode=True, output_format="html5")
|
||||||
github = GitHub(app)
|
github = GitHub(app)
|
||||||
csrf = CsrfProtect(app)
|
csrf = CsrfProtect(app)
|
||||||
mail = Mail(app)
|
mail = Mail(app)
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
<link rel="stylesheet" type="text/css" href="/static/easymde.min.css">
|
<link rel="stylesheet" type="text/css" href="/static/easymde.min.css">
|
||||||
<script>
|
<script>
|
||||||
$("textarea.markdown").each(function() {
|
$("textarea.markdown").each(function() {
|
||||||
new EasyMDE({ element: this, hideIcons: ["image"] });
|
new EasyMDE({ element: this, hideIcons: ["image"], forceSync: true });
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
{% block scriptextra %}{% endblock %}
|
{% block scriptextra %}{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Send Email
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Send Email</h1>
|
||||||
|
|
||||||
|
{% from "macros/forms.html" import render_field, render_submit_field %}
|
||||||
|
<form action="" method="POST" class="form" role="form">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ render_field(form.subject) }}
|
||||||
|
{{ render_field(form.text, fieldclass="form-control markdown") }}
|
||||||
|
{{ render_submit_field(form.submit) }}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -65,6 +65,25 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.MODERATOR) %}
|
||||||
|
<tr>
|
||||||
|
<td>Admin</td>
|
||||||
|
<td>
|
||||||
|
{% if user.email %}
|
||||||
|
<a class="btn btn-primary" href="{{ url_for('send_email_page', username=user.username) }}">
|
||||||
|
Email
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="btn btn-primary disabled"
|
||||||
|
data-toggle="tooltip" data-placement="bottom"
|
||||||
|
title="No email address for user"
|
||||||
|
style="pointer-events: all;">
|
||||||
|
Email
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% if user == current_user %}
|
{% if user == current_user %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Profile Picture:</td>
|
<td>Profile Picture:</td>
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
from flask import *
|
from flask import *
|
||||||
from flask_user import *
|
from flask_user import *
|
||||||
from flask_login import login_user, logout_user
|
from flask_login import login_user, logout_user
|
||||||
from app import app
|
from app import app, markdown
|
||||||
from app.models import *
|
from app.models import *
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import *
|
from wtforms import *
|
||||||
from wtforms.validators import *
|
from wtforms.validators import *
|
||||||
from app.utils import randomString, loginUser
|
from app.utils import randomString, loginUser, rank_required
|
||||||
from app.tasks.forumtasks import checkForumAccount
|
from app.tasks.forumtasks import checkForumAccount
|
||||||
from app.tasks.emails import sendVerifyEmail
|
from app.tasks.emails import sendVerifyEmail, sendEmailRaw
|
||||||
from app.tasks.phpbbparser import getProfile
|
from app.tasks.phpbbparser import getProfile
|
||||||
|
|
||||||
# Define the User profile form
|
# Define the User profile form
|
||||||
|
@ -126,6 +126,36 @@ def user_check(username):
|
||||||
return redirect(url_for("check_task", id=task.id, r=next_url))
|
return redirect(url_for("check_task", id=task.id, r=next_url))
|
||||||
|
|
||||||
|
|
||||||
|
class SendEmailForm(FlaskForm):
|
||||||
|
subject = StringField("Subject", [InputRequired(), Length(1, 300)])
|
||||||
|
text = TextAreaField("Message", [InputRequired()])
|
||||||
|
submit = SubmitField("Send")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/users/<username>/email/", methods=["GET", "POST"])
|
||||||
|
@rank_required(UserRank.MODERATOR)
|
||||||
|
def send_email_page(username):
|
||||||
|
user = User.query.filter_by(username=username).first()
|
||||||
|
if user is None:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
next_url = url_for("user_profile_page", username=user.username)
|
||||||
|
|
||||||
|
if user.email is None:
|
||||||
|
flash("User has no email address!", "error")
|
||||||
|
return redirect(next_url)
|
||||||
|
|
||||||
|
form = SendEmailForm(request.form)
|
||||||
|
if form.validate_on_submit():
|
||||||
|
text = form.text.data
|
||||||
|
html = markdown(text)
|
||||||
|
task = sendEmailRaw.delay([user.email], form.subject.data, text, html)
|
||||||
|
return redirect(url_for("check_task", id=task.id, r=next_url))
|
||||||
|
|
||||||
|
return render_template("users/send_email.html", form=form)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SetPasswordForm(FlaskForm):
|
class SetPasswordForm(FlaskForm):
|
||||||
email = StringField("Email", [Optional(), Email()])
|
email = StringField("Email", [Optional(), Email()])
|
||||||
password = PasswordField("New password", [InputRequired(), Length(2, 20)])
|
password = PasswordField("New password", [InputRequired(), Length(2, 20)])
|
||||||
|
|
Loading…
Reference in New Issue