Files
        @ 6eea4a4d3b10
    
        
              Branch filter: 
        
    Location: FVDE/ennstatus/ennstatus/root/functions.py
        
            
            6eea4a4d3b10
            4.3 KiB
            text/x-python
        
        
    
    Added first version of the README
    | 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 | 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)
 |