muizenval

Observe mouse traps remotely
Log | Files | Refs

commit 5f2198f05cf0c851519a4f455925ff0c5d86fdb7
parent 0590c61ac854fd1c4f8bfd0a211ad26aec8917d5
Author: Friedel Schön <[email protected]>
Date:   Thu, 12 May 2022 14:35:28 +0200

user/trap management

Diffstat:
ATODO | 8++++++++
Mserver/forms.py | 5+++--
Mserver/models.py | 11++++++-----
Mserver/routes.py | 9++++++++-
Mserver/site.db | 0
5 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO @@ -0,0 +1,7 @@ +- gebruikers management toegevoegd +- muizenval registreren (connect butten) +- (status -> database) + + +VOOR LATER: +- muizenval reconnect +\ No newline at end of file diff --git a/server/forms.py b/server/forms.py @@ -41,8 +41,9 @@ class RegistrationForm(FlaskForm): def validate_catcher_code(self, code): - if not User.query.filter_by(type=UserType.CATCHER, catcher_code=code.data).first(): - raise ValidationError('De rattenvanger is niet bekennt, hebt u de code juist ingevoerd?') + pass + #if not User.query.filter_by(type=UserType.CATCHER, catcher_code=code.data).first(): + # raise ValidationError('De rattenvanger is niet bekennt, hebt u de code juist ingevoerd?') """ login form for login.html """ diff --git a/server/models.py b/server/models.py @@ -1,3 +1,4 @@ +from email.policy import default from enum import Enum from flask_login import UserMixin @@ -18,7 +19,7 @@ class UserType(Enum): class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) - type = db.Column(db.Enum(UserType)) + type = db.Column(db.Enum(UserType), nullable=False, default=UserType.CLIENT) email = db.Column(db.String(120), unique=True, nullable=False) name = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) @@ -32,12 +33,12 @@ class User(db.Model, UserMixin): class Trap(db.Model): - id = db.Column(db.Integer, primary_key=True) - mac = db.Column(db.String(16), unique=True, nullable=False) + mac = db.Column(db.String(16), primary_key=True, nullable=False) name = db.Column(db.Text) - owner = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) last_heartbeat = db.Column(db.DateTime, nullable=True, default=0) - caught = db.Column(db.Boolean, nullable=False, default=False) + caught = db.Column(db.Boolean, nullable=False, default=False) + owner = db.Column(db.Integer, db.ForeignKey('user.id')) + connect_expired = db.Column(db.DateTime) def pretty_mac(self): upper = self.mac.upper() diff --git a/server/routes.py b/server/routes.py @@ -58,7 +58,14 @@ def register(): form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') - user = User(name=form.name.data, email=form.email.data, password=hashed_password) + address = f"{form.street} {form.housenumber}\n{form.postcode} {form.place}" + user = User( + name=form.name.data, + email=form.email.data, + password=hashed_password, + phone=form.phone.data, + address = address + ) db.session.add(user) db.session.commit() flash('Uw profiel werd toegevoegd! U kan nu inloggen.', 'success') diff --git a/server/site.db b/server/site.db Binary files differ.