diff --git a/app/__init__.py b/app/__init__.py index 88dd52f..c95b3df 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from flask import Flask, render_template from .exts import db, mail, migrate from .expert import expert diff --git a/app/expert.py b/app/expert.py index 65e967e..fab3ac2 100644 --- a/app/expert.py +++ b/app/expert.py @@ -23,6 +23,7 @@ def expert_form(): create_select_field(ExpertForm, 'ipv6_pool', 'Wahlkreis', 'kein IPv6', current_app.config['API_POOL_IPV6'], 'ipv4_prefix') + form = ExpertForm() if form.validate_on_submit(): prefixes_v4 = [(current_app.config['API_POOL_HNA'], int(form.ipv4_prefix.data))] \ diff --git a/app/forms.py b/app/forms.py index c6de829..fb85b67 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,4 +1,5 @@ from sqlalchemy.orm import validates +from sqlalchemy import func from flask_wtf import FlaskForm from wtforms import StringField, HiddenField, SelectField, EmailField from wtforms.validators import Email, AnyOf, Length, DataRequired, ValidationError @@ -33,7 +34,7 @@ def validate_email(self, field): if r is None: raise ValidationError("Ungültige Anfrage") - if field.data != r.email: + if field.data.lower() != r.email.lower(): raise ValidationError("E-Mail stimmt nicht überein.") return field @@ -63,7 +64,7 @@ class SummaryForm(FlaskForm): @validates("email") def validate_email(self, field): - r = IPRequest.query.filter_by(email=field.data) + r = IPRequest.query.filter(func.lower(IPRequest.email) == func.lower(field.data)) if r is None: raise ValidationError("Ungültige Anfrage") return field diff --git a/app/models.py b/app/models.py index 60c938a..f0328da 100644 --- a/app/models.py +++ b/app/models.py @@ -13,7 +13,7 @@ class IPRequest(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120)) name = db.Column(db.String(120), unique=True) - router_id = db.Column(db.String(120)) + # router_id = db.Column(db.String(120)) verified = db.Column(db.Boolean(), default=False) token = db.Column(db.String(128), unique=True) created_at = db.Column(db.DateTime(), default=datetime.now) diff --git a/app/simplemode.py b/app/simplemode.py index 2957086..205ddd4 100644 --- a/app/simplemode.py +++ b/app/simplemode.py @@ -3,9 +3,11 @@ from .utils import request_create, send_email, activate_and_redirect from .forms import EmailForm from .exts import db +from wtforms.validators import DataRequired simplemode = Blueprint('simplemode', __name__) + @simplemode.route('/simplemode/activate//') def simplemode_activate(request_id, signed_token): template = 'simplemode/email.txt' @@ -14,23 +16,26 @@ def simplemode_activate(request_id, signed_token): @simplemode.route('/simplemode', methods=['GET', 'POST']) def simplemode_form(): - # add location type field dynamically (values are set in config) - prefix_defaults = current_app.config['PREFIX_DEFAULTS'] - choices = [(k, k) for k in list(prefix_defaults.keys())] - setattr(EmailForm, 'location_type', SelectField('Ort', choices=choices)) + # add location field dynamically (values are set in config) + v6pool = current_app.config['API_POOL_IPV6_SIMPLE'] + v6_choices = [("", "Bitte Stadteil wählen")] + [(k, k) for k in list(v6pool.keys())] + + setattr(EmailForm, 'ipv6_pool', SelectField('Stadtteil', choices=v6_choices, validators=[DataRequired()])) form = EmailForm() + if form.validate_on_submit(): - mesh_num = 3 pool_mesh = current_app.config['API_POOL_MESH'] - prefixes_mesh = [(pool_mesh, 32)] * mesh_num + prefixes_mesh = [(pool_mesh, 32)] * 3 # hna network pool_hna = current_app.config['API_POOL_HNA'] - prefixes_hna = [(pool_hna, prefix_defaults[form.location_type.data])] + prefixes_hna = [(pool_hna, '27')] + + prefixes_v6 = [(v6pool[form.ipv6_pool.data], None)] r = request_create(form.hostname.data, form.email.data, - prefixes_mesh + prefixes_hna, []) + prefixes_mesh + prefixes_hna, prefixes_v6) try: url = url_for(".simplemode_activate", request_id=r.id, @@ -38,10 +43,11 @@ def simplemode_form(): subject = "[Freifunk Berlin] Aktivierung - %s" % r.name data = {'name': r.name, 'url': url} send_email(r.email, subject, "activation.txt", data) - except: + except Exception as e: # if send_mail fails we delete the already saved request db.session.delete(r) db.session.commit() + current_app.logger.error(f'Error sending mail!\n {e}') raise return render_template('confirmation.html') diff --git a/app/templates/index.html b/app/templates/index.html index d2755e3..6e79fb7 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -17,11 +17,11 @@

- IP-Vergabe (Standard/Wizard) + IP-Vergabe - IP-Vergabe (für Experten_innen) + IP-Vergabe (für Expert_innen)
@@ -46,12 +46,12 @@

Bei Bugs oder Anregungen erstelle bitte ein Issue auf - Github + Github oder schreib eine Mail an unsere Mailingliste. Für Infos bezüglich dieses Dienstes, siehe die - README + README oder durchstöbere unsere Wiki.

diff --git a/app/templates/simplemode/form.html b/app/templates/simplemode/form.html index 7e072b9..8ad3290 100644 --- a/app/templates/simplemode/form.html +++ b/app/templates/simplemode/form.html @@ -14,7 +14,7 @@ {{ form.csrf_token }} {{ render_bootstrap_field(form.hostname, "Spitzname des Routers", "Ein kurzer und eindeutiger Name für deinen Router (z.B. funkenpumpe oder HermannStr42_VH). Dieser Name wird nur intern für dich hinterlegt und muss zwischen 4 und 32 Zeichen lang sein.") }} {{ render_bootstrap_field(form.email, "Kontaktadresse", "Notwendig, damit wir dir die Router-Konfiguration per E-Mail zuschicken können. Benutze am besten immer die gleiche Adresse, auch falls du mehrere Router hast; dann kannst du die IPs hier gesammelt verwalten.") }} - {{ render_bootstrap_field(form.location_type, help="Je nach Standort benutzen mehr oder weniger viele Menschen zur selben Zeit den Freifunk-Router. Cafés und Kneipen haben mehr gleichzeitige Benutzer_innen und brauchen so mehr IP-Adressen als ein Router zu Hause.") }} + {{ render_bootstrap_field(form.ipv6_pool, help="Dies wird benötigt um Verbindungen im Netzwerk zu optimieren", placeholder="Bitte Stadtteil auswählen, html" ) }} {{ render_bootstrap_field(form.captcha, "Hauptstadt Deutschlands?", "Wird benötigt, um Spam-Bots auszuschließen.") }}
diff --git a/app/utils.py b/app/utils.py index b99150b..6994eb3 100644 --- a/app/utils.py +++ b/app/utils.py @@ -7,6 +7,7 @@ from werkzeug.exceptions import BadRequest from .nipap import NipapApi from .exts import mail +from sqlalchemy import func def get_api(): @@ -80,8 +81,7 @@ def ip_request_get(request_id): def ip_request_for_email(email): from .models import IPRequest - - r = IPRequest.query.filter_by(email=email, verified=True) + r = IPRequest.query.filter(func.lower(IPRequest.email) == func.lower(email), IPRequest.verified == True) if r.count() == 0: raise BadRequest("Kein Eintrag für diese E-Mail") return r diff --git a/default.cfg b/default.cfg index 4cadd9a..5f1847a 100644 --- a/default.cfg +++ b/default.cfg @@ -1,8 +1,4 @@ # -*- coding: utf-8 -*- -PREFIX_DEFAULTS = { - 'Wohnung (max. 14 Clients)' : 28, - 'Kneipe/Cafe (max. 30 Clients)' : 27 -} EXPERT_MAX_PREFIX = 24 diff --git a/requirements.txt b/requirements.txt index cba8c7a..05c13a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,10 +4,10 @@ Flask-Migrate==3.1.0 Flask-SQLAlchemy==3.1.1 Flask-Script==2.0.6 Flask-WTF==1.2.1 -SQLAlchemy==2.0.23 +SQLAlchemy==2.0.29 Jinja2==3.1.3 psycopg2-binary==2.9.9 WTForms==3.1.1 email-validator==1.3.1 prettytable==3.9.0 -markupsafe==2.1.3 \ No newline at end of file +markupsafe==2.1.3