Files
@ e9e85b209c6f
Branch filter:
Location: FVDE/ennstatus/ennstatus/root/functions.py
e9e85b209c6f
4.9 KiB
text/x-python
Use rt instead of rtkit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | # Ënnstatus
# Copyright (C) 2015 Dennis Fink
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from flask import render_template, current_app, flash
from flask_mail import Mail, Message
from ennstatus.status.functions import mail
def send_membership_mail(form):
try:
body = render_template('root/membership_mail.txt',
username=form.username.data,
email=form.email.data,
membership=form.membership.data,
c3l=form.c3l.data,
fullname=form.fullname.data,
street=form.street.data,
zip=form.zip.data,
city=form.city.data,
country=form.country.data,
gpg=form.gpg.data
)
recipients = current_app.config['ENNSTATUS_MEMBERSHIP_MAIL']
with mail.connect() as conn:
for recipient in recipients:
msg = Message(
'New membership application',
sender='ennstatus@enn.lu'
)
msg.add_recipient(recipient)
current_app.logger.debug('Before encryption')
current_app.logger.debug(body)
if current_app.extensions['gnupg']:
encrypted_body = str(
current_app.extensions['gnupg'].encrypt(
body,
recipient,
always_trust=True
)
)
else:
encrypted_body = None
current_app.logger.debug('After encryption')
current_app.logger.debug(body)
msg.body = encrypted_body if encrypted_body else body
conn.send(msg)
flash('Application successfully submitted!', 'success')
except KeyError:
flash(
'Internal server error! Please get in touch with us at info@enn.lu!',
'error'
)
current_app.logger.error('Membership admin not found!')
except AssertionError:
pass
except Exception as e:
flash(
'Internal server error! Please get in touch with us at info@enn.lu!',
'error'
)
current_app.logger.error('Unexpected error: %s' % e,
exc_info=True)
def send_bridgeprogram_mail(form):
try:
body = render_template('root/bridgeprogram_mail.txt',
fullname=form.fullname.data,
email=form.email.data,
bridgename=form.bridgename.data,
duration=form.duration.data,
payment=form.payment.data
)
recipients = current_app.config['ENNSTATUS_BRIDGEPROGRAM_MAIL']
with mail.connect() as conn:
for recipient in recipients:
msg = Message('New bridge program application',
sender='ennstatus@enn.lu')
msg.add_recipient(recipient)
if current_app.extensions['gnupg']:
encrypted_body = str(
current_app.extensions['gnupg'].encrypt(
body,
recipient,
always_trust=True
)
)
else:
encrypted_body = None
msg.body = encrypted_body if encrypted_body else body
conn.send(msg)
flash(
'Application successfully submitted! We will send you an email with further information!',
'success'
)
except KeyError:
flash(
'Internal server error! Please get in touch with us at info@enn.lu',
'error'
)
current_app.logger.error('Bridgeprogram admin not found!')
except AssertionError:
pass
except Exception as e:
flash(
'Internal server error! Please get in touch with us at info@enn.lu!',
'error'
)
current_app.logger.error('Unexpected error: %s' % e,
exc_info=True)
|