aboutsummaryrefslogtreecommitdiff
path: root/app/manage
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-09-21 21:33:40 -0400
committerCara Salter <cara@devcara.com>2022-09-21 21:33:40 -0400
commitf9b99ce66f56995a29709e9bf24750dab9430767 (patch)
tree3624255932ab500bcfa3043932acd31b23fe86b3 /app/manage
parentb1ffd5220866dc9479fa284dfb2f0a0e111a6031 (diff)
downloadnccd-f9b99ce66f56995a29709e9bf24750dab9430767.tar.gz
nccd-f9b99ce66f56995a29709e9bf24750dab9430767.zip
bunch of features
registration, logging out, listing networks, user profiles
Diffstat (limited to 'app/manage')
-rw-r--r--app/manage/__init__.py50
-rw-r--r--app/manage/forms.py8
2 files changed, 58 insertions, 0 deletions
diff --git a/app/manage/__init__.py b/app/manage/__init__.py
new file mode 100644
index 0000000..c69376f
--- /dev/null
+++ b/app/manage/__init__.py
@@ -0,0 +1,50 @@
+from flask import Blueprint, render_template, request, flash, redirect, url_for
+from flask_login import login_required, current_user
+import ulid
+
+from app import db
+from app.database import Network
+
+from .forms import NewNetworkForm
+
+bp = Blueprint('manage', __name__, url_prefix="/manage")
+
+@bp.route("/networks", methods=["GET", "POST"])
+@login_required
+def list_networks():
+ nets = current_user.networks
+
+ form = NewNetworkForm(request.form)
+
+ if request.method == "POST" and form.validate_on_submit():
+ subnet = request.form.get('subnet')
+ description = request.form.get('description')
+
+ n = Network(
+ id=str(ulid.ulid()),
+ subnet=subnet,
+ description=description,
+ manager_id=str(current_user.id)
+ )
+ db.session.add(n)
+ db.session.commit()
+
+ flash("Network added")
+
+ return render_template("network_list.html", nets=nets, form=form)
+
+@bp.route("/networks/<string:id>/delete")
+@login_required
+def del_net(id):
+ n = Network.query.filter_by(id=id).first()
+
+ if n.manager_id != current_user.id:
+ flash("You aren't a manager of this network.")
+ return redirect(url_for("manage.list_networks"))
+
+ db.session.delete(n)
+ db.session.commit()
+
+ flash("Network deleted")
+
+ return redirect(url_for("manage.list_networks"))
diff --git a/app/manage/forms.py b/app/manage/forms.py
new file mode 100644
index 0000000..0849367
--- /dev/null
+++ b/app/manage/forms.py
@@ -0,0 +1,8 @@
+from flask_wtf import FlaskForm
+from wtforms.fields.simple import PasswordField, StringField, SubmitField
+from wtforms.validators import DataRequired, Regexp
+
+class NewNetworkForm(FlaskForm):
+ subnet = StringField("Subnet CIDR", validators=[DataRequired(), Regexp(r"^([0-9]{1,3}\.){3}[0-9]{1,3}($|/(8|16|24|32))$")])
+ description = StringField("Description", validators=[DataRequired()])
+ submit = SubmitField("Create")