diff --git a/ennstatus/root/forms.py b/ennstatus/root/forms.py --- a/ennstatus/root/forms.py +++ b/ennstatus/root/forms.py @@ -1,6 +1,7 @@ from flask_wtf import Form from wtforms import SelectField, StringField, RadioField, BooleanField, SubmitField -from wtforms.validators import DataRequired, InputRequired, Email, Optional +from wtforms.validators import DataRequired, InputRequired, Email, Optional, Length + COUNTRIES = [ @@ -41,7 +42,7 @@ class MembershipForm(Form): validators=[Optional()], ) zip = StringField('ZIP-Code', - validators=[Optional()], + validators=[Length(max=30), Optional()], ) city = StringField('City/Town', validators=[Optional()], @@ -58,9 +59,9 @@ class MembershipForm(Form): choices=[ ('regular', 'Regular membership (120€/year)'), ('student', 'Student memnbership (60€/year)'), - ('starving', 'Starving Hacker - Get in touch with info@enn.lu'), + ('starving', 'Starving Hacker - Get in touch with us at info@enn.lu'), ] ) - c3l = BooleanField('Include Chaos Computer Club Lëtzebuerg Membership¹') + c3l = BooleanField('Include "Chaos Computer Club Lëtzebuerg" Membership1') submit = SubmitField('Become a member') diff --git a/ennstatus/root/functions.py b/ennstatus/root/functions.py new file mode 100644 --- /dev/null +++ b/ennstatus/root/functions.py @@ -0,0 +1,34 @@ +from flask import render_template, current_app + +from flask_mail import Mail, Message + +from ennstatus.status.functions import mail + + +def send_membership_mail(form): + try: + msg = Message('New membership application', sender='ennstatus@enn.lu') + msg.add_recipient(current_app.config['ENNSTATUS_MEMBERSHIP_MAIL']) + + msg.body = render_template('root/membership_mail.txt', + username=form.username.data, + email=form.email.data, + membership=form.membership.data, + c3l=form.c3l.data, + firstname=form.firstname.data, + surname=form.surname.data, + street=form.street.data, + zip=form.zip.data, + city=form.city.data, + country=form.country.data, + gpg=form.gpg.data + ) + print(msg.body) + mail.send(msg) + except KeyError: + current_app.logger.error('Membership admin not found!') + except AssertionError: + pass + except Exception as e: + current_app.logger.error('Unexpecter error: %s' % e, + exc_info=True) diff --git a/ennstatus/root/views.py b/ennstatus/root/views.py --- a/ennstatus/root/views.py +++ b/ennstatus/root/views.py @@ -3,6 +3,7 @@ from flask import (Blueprint, render_tem from ennstatus.root.forms import BPMForm, MembershipForm from ennstatus.root.constants import BPM_ADDRESSES +from ennstatus.root.functions import send_membership_mail root_page = Blueprint('root', __name__) @@ -46,9 +47,7 @@ def membership(): if request.method == 'POST': current_app.logger.debug('Validating form') if form.validate_on_submit(): - pass - else: - pass + send_membership_mail(form) return render_template('root/membership.html', form=form) diff --git a/ennstatus/templates/root/member.html b/ennstatus/templates/root/member.html --- a/ennstatus/templates/root/member.html +++ b/ennstatus/templates/root/member.html @@ -35,7 +35,7 @@

How to become a member?

Becoming a member is very simple. Just follow these steps:

    -
  1. Download the following membership form and fill in the necessary information
  2. +
  3. Download the following membership form and fill in the necessary information or use this online form.
  4. Send the membership form per mail to info@enn.lu or to one of our snailmail address.
  5. Pay your annually membership fee. Use one of the payment methods (except Flattr or BPM Points) diff --git a/ennstatus/templates/root/membership.html b/ennstatus/templates/root/membership.html --- a/ennstatus/templates/root/membership.html +++ b/ennstatus/templates/root/membership.html @@ -7,9 +7,93 @@ {% block content %}

    Register as member

    - {{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }} +
    + {{ form.hidden_tag() }} +
    + {{ form.username.label(class_='control-label col-lg-2') }} +
    + {{ form.username(class_='form-control') }} +
    +
    +
    + {{ form.email.label(class_='control-label col-lg-2') }} +
    + {{ form.email(class_='form-control') }} +
    +
    +
    + {{ form.firstname.label(class_='control-label col-lg-2') }} +
    + {{ form.firstname(class_='form-control') }} +
    +
    +
    + {{ form.surname.label(class_='control-label col-lg-2') }} +
    + {{ form.surname(class_='form-control') }} +
    +
    +
    + {{ form.street.label(class_='control-label col-lg-2') }} +
    + {{ form.street(class_='form-control') }} +
    +
    +
    + {{ form.zip.label(class_='control-label col-lg-2') }} +
    + {{ form.zip(class_='form-control') }} +
    +
    +
    + {{ form.city.label(class_='control-label col-lg-2') }} +
    + {{ form.city(class_='form-control') }} +
    +
    +
    + {{ form.country.label(class_='control-label col-lg-2') }} +
    + {{ form.country(class_='form-control') }} +
    +
    +
    + {{ form.gpg.label(class_='control-label col-lg-2') }} +
    + {{ form.gpg(class_='form-control') }} +
    +
    +
    + {{ form.membership.label(class_='control-label col-lg-2') }} +
    + {% for field in form.membership %} +
    + +
    + {% endfor %} +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    + {{ form.submit(class_='btn btn-primary') }} +
    +
    +
    +

    Field marked with * are required!

    -

    ¹: If you have decided for the double membership, the membership fees are 150€/year for the regular +

    1: If you have decided to apply for the double membership, the membership fees are 150€/year for the regular membership and 70€/year for the student membership.

    {% endblock %} diff --git a/ennstatus/templates/root/membership_mail.txt b/ennstatus/templates/root/membership_mail.txt new file mode 100644 --- /dev/null +++ b/ennstatus/templates/root/membership_mail.txt @@ -0,0 +1,21 @@ +Hi, + +We got a new membership application! + +Username: {{ username }} +E-Mail: {{ email }} +Membership Plan: {{ membership }} +Double Membership: {{ c3l }} + +Additional information: + +First Name: {{ firstname }} +Surname: {{ surname }} +Nr., Street: {{ street }} +ZIP-Code: {{ zip }} +City: {{ city }} +Country: {{ country }} +GPG-ID: {{ gpg }} + +Sincerely, +Ennstatus