diff --git a/AT_frontend/.gitignore b/AT_frontend/.gitignore index 860b323..927797f 100644 --- a/AT_frontend/.gitignore +++ b/AT_frontend/.gitignore @@ -1,2 +1 @@ -.venv/ -__pychache__/ \ No newline at end of file +.venvs/ \ No newline at end of file diff --git a/AT_frontend/app.py b/AT_frontend/app.py index b1af769..f727eb4 100644 --- a/AT_frontend/app.py +++ b/AT_frontend/app.py @@ -1,152 +1,35 @@ -from flask import Flask, render_template, request, redirect, url_for, flash, session +from flask import Flask, render_template, session, redirect, url_for, session from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, BooleanField, SubmitField +from wtforms import (StringField, BooleanField, + RadioField, SelectField, + TextAreaField, SubmitField) from wtforms.validators import DataRequired -from functools import wraps -import os -from flask_sqlalchemy import SQLAlchemy -from datetime import datetime app = Flask(__name__) -app.config['SECRET_KEY'] = 'your-secret-key' # Change this to a random string -# Database configuration - update with your friend's database info -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///logs.db' # Change this to match your friend's DB -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -db = SQLAlchemy(app) +app.config['SECRET_KEY'] = 'mijngeheimesleutel' -# Simple log model - adjust to match your friend's database structure -class Log(db.Model): - id = db.Column(db.Integer, primary_key=True) - action = db.Column(db.String(100), nullable=False) - timestamp = db.Column(db.DateTime, default=datetime.utcnow) - - def __repr__(self): - return f"Log('{self.action}', '{self.timestamp}')" +class InfoForm(FlaskForm): -# Keep your existing user dictionary for authentication -users = { - "admin": {"password": "admin123", "role": "admin"}, - "user": {"password": "user123", "role": "user"} -} + naam = StringField('Wat is je naam?',validators=[DataRequired()]) + vrouw = BooleanField("Ben je een vrouw?") + instrument = RadioField('Welk instrument wil je leren bespelen?', choices=[('ins_een','Gitaar'),('ins_twee','Drums')]) + plaats = SelectField(u'Welke locatie heeft de voorkeur?', + choices=[('as', 'Assen'), ('dr', 'Drachten'), ('gr', 'Groningen')]) + feedback = TextAreaField() + submit = SubmitField('Verzend') -# Add a function to create a new log entry -def add_log(action): - log = Log(action=action) - db.session.add(log) - db.session.commit() - -class LoginForm(FlaskForm): - username = StringField('Username', validators=[DataRequired()]) - password = PasswordField('Password', validators=[DataRequired()]) - remember = BooleanField('Remember Me') - -class GateControlForm(FlaskForm): - open_gate = SubmitField('Open Gate') - close_gate = SubmitField('Close Gate') - check_camera = SubmitField('Check Camera') - debug_mode = BooleanField('Debug Mode') - -def login_required(f): - @wraps(f) - def decorated_function(*args, **kwargs): - if 'logged_in' not in session: - return redirect(url_for('login')) - return f(*args, **kwargs) - return decorated_function - -def admin_required(f): - @wraps(f) - def decorated_function(*args, **kwargs): - if 'role' not in session or session['role'] != 'admin': - flash('You need to be an admin to access this page.') - return redirect(url_for('login')) - return f(*args, **kwargs) - return decorated_function - -@app.route('/') +@app.route('/', methods=['GET', 'POST']) def index(): - if 'logged_in' in session: - if session['role'] == 'admin': - return redirect(url_for('dashboard')) - return redirect(url_for('user_page')) - return redirect(url_for('login')) -@app.route('/login', methods=['GET', 'POST']) -def login(): - form = LoginForm() - error = None - - if request.method == 'POST': - username = request.form['username'] - password = request.form['password'] - - if username in users and users[username]['password'] == password: - session['logged_in'] = True - session['username'] = username - session['role'] = users[username]['role'] - - # Log the login action - add_log(f"User {username} logged in") - - if users[username]['role'] == 'admin': - return redirect(url_for('dashboard')) - else: - return redirect(url_for('user_page')) - else: - # Log the failed login attempt - add_log(f"Failed login attempt for user {username}") - error = 'Invalid credentials. Please try again.' - - return render_template('inlog.html', form=form, error=error) - -@app.route('/dashboard', methods=['GET', 'POST']) -@login_required -@admin_required -def dashboard(): - form = GateControlForm() - gate_status = "Closed" - camera_status = "Inactive" - debug_mode = False - - # Get the most recent logs to display - recent_logs = Log.query.order_by(Log.timestamp.desc()).limit(10).all() - + form = InfoForm() if form.validate_on_submit(): - if form.open_gate.data: - gate_status = "Open" - add_log("Gate opened by " + session['username']) - elif form.close_gate.data: - gate_status = "Closed" - add_log("Gate closed by " + session['username']) - elif form.check_camera.data: - camera_status = "Active" - add_log("Camera checked by " + session['username']) - - debug_mode = form.debug_mode.data - if debug_mode: - add_log("Debug mode enabled by " + session['username']) - - return render_template('dashboard.html', form=form, gate_status=gate_status, - camera_status=camera_status, debug_mode=debug_mode, - recent_logs=recent_logs) -@app.route('/user') -@login_required -def user_page(): - add_log(f"User {session['username']} accessed user page") - return "Regular user page - Access restricted" + session['naam'] = form.username.data + session['password'] = form.password.data -@app.route('/logout') -def logout(): - if 'username' in session: - add_log(f"User {session['username']} logged out") - session.clear() - return redirect(url_for('login')) - -# Initialize database -with app.app_context(): - db.create_all() + return render_template('dashboard.html') + return render_template('login.html', form=form) if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/AT_frontend/static/images/car.png b/AT_frontend/static/images/car.png new file mode 100644 index 0000000..0c438c7 Binary files /dev/null and b/AT_frontend/static/images/car.png differ diff --git a/AT_frontend/static/images/logo-light.png b/AT_frontend/static/images/logo-light.png new file mode 100644 index 0000000..55710f0 Binary files /dev/null and b/AT_frontend/static/images/logo-light.png differ diff --git a/AT_frontend/templates/dashboard.html b/AT_frontend/templates/dashboard.html index db79af8..ed3225c 100644 --- a/AT_frontend/templates/dashboard.html +++ b/AT_frontend/templates/dashboard.html @@ -1,68 +1,18 @@ -{%extends 'base.html' %} -{% block content %} -
-
-
-
-
Gate Control Dashboard
-
- {{ form.hidden_tag() }} -
- {{ form.open_gate(class="btn btn-dark") }} -
-
- {{ form.close_gate(class="btn btn-dark") }} -
-
- {{ form.check_camera(class="btn btn-dark") }} -
-
- {{ form.debug_mode() }} - -
-
- -
-
-
Gate Status: {{ gate_status }}
-
Camera Status: {{ camera_status }}
- {% if debug_mode %} - Debug Mode is Enabled - {% endif %} -
-
-
-
-
-
-
System Logs
-
- - - - - - - - - - {% for log in recent_logs %} - - - - - - {% endfor %} - -
TimeActionStatus
{{ log.timestamp.strftime('%H:%M:%S') }}{{ log.action }} - - {{ log.status }} - -
-
-
-
-
- - -{% endblock %} \ No newline at end of file + + + + + + Document + + +

Bedankt voor de moeite.
Dit zijn de ingevulde gegevens:

+ + + \ No newline at end of file diff --git a/AT_frontend/templates/login.html b/AT_frontend/templates/login.html new file mode 100644 index 0000000..168127e --- /dev/null +++ b/AT_frontend/templates/login.html @@ -0,0 +1,75 @@ + + + + + + + Login + + + +
+
+ +
+
+
+
+
+
+ + + + +
+
+ +
+
+
+
+
+
+ Moving Image +
+ + + \ No newline at end of file