mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
unsubscribe to email newsletter
This commit is contained in:
parent
6f32e8f20d
commit
28fa59a769
6 changed files with 37 additions and 5 deletions
|
@ -41,10 +41,13 @@ def send_welcome_email(user, application_required):
|
|||
def send_async_email(subject, sender, recipients, text_body, html_body, reply_to):
|
||||
if 'ngrok.app' in sender: # for local development
|
||||
sender = 'PieFed <noreply@piefed.social>'
|
||||
return_path = 'bounces@piefed.social'
|
||||
else:
|
||||
return_path = 'bounces@' + current_app.config['SERVER_NAME']
|
||||
# NB email will not be sent if you have not verified your domain name as an 'Identity' inside AWS SES
|
||||
if type(recipients) == str:
|
||||
recipients = [recipients]
|
||||
with current_app.app_context():
|
||||
return_path = 'bounces@' + current_app.config['SERVER_NAME']
|
||||
try:
|
||||
# Create a new SES resource and specify a region.
|
||||
amazon_client = boto3.client('ses', region_name=AWS_REGION)
|
||||
|
@ -87,7 +90,6 @@ def send_async_email(subject, sender, recipients, text_body, html_body, reply_to
|
|||
ReturnPath=return_path,
|
||||
ReplyToAddresses=[reply_to])
|
||||
# message.attach_alternative("...AMPHTML content...", "text/x-amp-html")
|
||||
|
||||
except ClientError as e:
|
||||
current_app.logger.error('Failed to send email. ' + e.response['Error']['Message'])
|
||||
return e.response['Error']['Message']
|
||||
|
|
|
@ -10,7 +10,7 @@ from app import db, cache
|
|||
from app.activitypub.util import default_context, make_image_sizes_async, refresh_user_profile, find_actor_or_create
|
||||
from app.constants import SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER, POST_TYPE_IMAGE, POST_TYPE_LINK, \
|
||||
SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR
|
||||
from app.email import send_email
|
||||
from app.email import send_email, send_welcome_email
|
||||
from app.inoculation import inoculation
|
||||
from app.main import bp
|
||||
from flask import g, session, flash, request, current_app, url_for, redirect, make_response, jsonify
|
||||
|
@ -259,6 +259,9 @@ def list_files(directory):
|
|||
|
||||
@bp.route('/test')
|
||||
def test():
|
||||
u = User.query.get(1)
|
||||
send_welcome_email(u, False)
|
||||
|
||||
return ''
|
||||
users_to_notify = User.query.join(Notification, User.id == Notification.user_id).filter(
|
||||
User.ap_id == None,
|
||||
|
|
|
@ -14,4 +14,4 @@
|
|||
<p>Rimu Atkinson<br />
|
||||
Founder</p>
|
||||
<p> </p>
|
||||
<p><small><a href="https://piefed.social/members/unsubscribe/reminder/{{ user.id }}/0">Unsubscribe from PieFed newsletter</a></small></p>
|
||||
<p><small><a href="{{ url_for('user.user_newsletter_unsubscribe', user_id=user.id, token=user.verification_token, _external=True) }}">Unsubscribe from PieFed newsletter</a></small></p>
|
||||
|
|
|
@ -15,4 +15,5 @@ PieFed is entirely self-funded so donations are much appreciated https://liberap
|
|||
Warm regards,
|
||||
|
||||
Rimu Atkinson
|
||||
Founder
|
||||
Founder
|
||||
|
||||
|
|
17
app/templates/user/newsletter_unsubscribed.html
Normal file
17
app/templates/user/newsletter_unsubscribed.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
{% extends 'base.html' %}
|
||||
{% from 'bootstrap/form.html' import render_form %}
|
||||
|
||||
{% block app_content %}
|
||||
<div class="row">
|
||||
<div class="col col-login mx-auto">
|
||||
<div class="card mt-5">
|
||||
<div class="card-body p-6">
|
||||
<div class="card-title text-center">{{ _('Unsubscribed') }}</div>
|
||||
<p>{{ _('You have unsubscribed from the email newsletter. We might email you for other reasons, though.') }}</p>
|
||||
<p><a href="{{ url_for('user.change_settings') }}">{{ _('More email settings') }}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -692,3 +692,12 @@ def user_settings_filters_delete(filter_id):
|
|||
cache.delete_memoized(user_filters_replies, current_user.id)
|
||||
flash(_('Filter deleted.'))
|
||||
return redirect(url_for('user.user_settings_filters'))
|
||||
|
||||
|
||||
@bp.route('/user/newsletter/<int:user_id>/<token>/unsubscribe', methods=['GET', 'POST'])
|
||||
def user_newsletter_unsubscribe(user_id, token):
|
||||
user = User.query.filter(User.id == user_id, User.verification_token == token).first()
|
||||
if user:
|
||||
user.newsletter = False
|
||||
db.session.commit()
|
||||
return render_template('user/newsletter_unsubscribed.html')
|
||||
|
|
Loading…
Reference in a new issue