Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d523dd0a68 | |||
| d7d96d5567 | |||
| a0018eebd5 | |||
| eebaaef9ea |
+55
-50
@@ -18,6 +18,7 @@ Features:
|
||||
"""
|
||||
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory, get_flashed_messages, jsonify, Response, make_response, send_file, abort
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from werkzeug.utils import secure_filename
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from werkzeug.exceptions import HTTPException
|
||||
@@ -115,6 +116,7 @@ app.config['PREFERRED_URL_SCHEME'] = 'https' if app.config['SESSION_COOKIE_SECUR
|
||||
# app.config['QR_CODE_FOLDER'] = cfg.QR_CODE_FOLDER # QR Code storage deactivated
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_port=1)
|
||||
app.register_blueprint(terminplaner_bp, url_prefix='/terminplaner')
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
"""--------------------------------------------------------------Path Init-------------------------------------------------------"""
|
||||
|
||||
@@ -7903,66 +7905,69 @@ def terminplan():
|
||||
@app.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
"""
|
||||
User registration route.false
|
||||
User registration route.
|
||||
Returns:
|
||||
flask.Response: Rendered template or redirect
|
||||
"""
|
||||
if 'username' not in session:
|
||||
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
||||
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adresse zu nutzen, versuchen Sie es erneut, nachdem Sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
||||
return redirect(url_for('login'))
|
||||
if 'username' in session:
|
||||
if request.method == 'POST':
|
||||
password = request.form['password']
|
||||
name = (request.form.get('name') or '').strip()
|
||||
last_name = (request.form.get('last-name') or '').strip()
|
||||
|
||||
if request.method == 'POST':
|
||||
password = request.form.get('password', '')
|
||||
name = (request.form.get('name') or '').strip()
|
||||
last_name = (request.form.get('last-name') or '').strip()
|
||||
|
||||
# Generate a username from the first 3 letters of first and last name.
|
||||
username = us.build_unique_username_from_name(name, last_name)
|
||||
username = us.build_unique_username_from_name(name, last_name)
|
||||
|
||||
permission_preset = (request.form.get('permission_preset') or 'standard_user').strip()
|
||||
use_custom_permissions = request.form.get('use_custom_permissions') == 'on'
|
||||
|
||||
if not username or not password or not name or not last_name:
|
||||
flash('Bitte füllen Sie alle Felder aus', 'error')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
permission_preset = (request.form.get('permission_preset') or 'standard_user').strip()
|
||||
use_custom_permissions = request.form.get('use_custom_permissions') == 'on'
|
||||
if not us.check_password_strength(password):
|
||||
flash('Passwort ist zu schwach oder entspricht nicht den Richtlinien', 'error')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
action_permissions = None
|
||||
page_permissions = None
|
||||
if use_custom_permissions:
|
||||
action_permissions = {}
|
||||
for action_key, _ in PERMISSION_ACTION_OPTIONS:
|
||||
action_permissions[action_key] = request.form.get(f'action_{action_key}') == 'on'
|
||||
|
||||
page_permissions = {}
|
||||
for endpoint_name, _ in PERMISSION_PAGE_OPTIONS:
|
||||
page_permissions[endpoint_name] = request.form.get(f'page_{endpoint_name}') == 'on'
|
||||
|
||||
if not username or not password or not name or not last_name:
|
||||
flash('Bitte füllen Sie alle Felder aus', 'error')
|
||||
return redirect(url_for('register'))
|
||||
if not us.check_password_strength(password):
|
||||
flash('Passwort ist zu schwach', 'error')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
action_permissions = None
|
||||
page_permissions = None
|
||||
if use_custom_permissions:
|
||||
action_permissions = {}
|
||||
for action_key, _ in PERMISSION_ACTION_OPTIONS:
|
||||
action_permissions[action_key] = request.form.get(f'action_{action_key}') == 'on'
|
||||
|
||||
page_permissions = {}
|
||||
for endpoint_name, _ in PERMISSION_PAGE_OPTIONS:
|
||||
page_permissions[endpoint_name] = request.form.get(f'page_{endpoint_name}') == 'on'
|
||||
|
||||
us.add_user(
|
||||
username,
|
||||
password,
|
||||
name,
|
||||
last_name,
|
||||
is_student=False,
|
||||
student_card_id=None,
|
||||
max_borrow_days=None,
|
||||
permission_preset=permission_preset,
|
||||
action_permissions=action_permissions,
|
||||
page_permissions=page_permissions,
|
||||
)
|
||||
return redirect(url_for('home_admin'))
|
||||
return render_template(
|
||||
'register.html',
|
||||
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
||||
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
||||
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
||||
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS
|
||||
us.add_user(
|
||||
username,
|
||||
password,
|
||||
name,
|
||||
last_name,
|
||||
is_student=False,
|
||||
student_card_id=None,
|
||||
max_borrow_days=None,
|
||||
permission_preset=permission_preset,
|
||||
action_permissions=action_permissions,
|
||||
page_permissions=page_permissions,
|
||||
)
|
||||
flash('Sie sind nicht berechtigt, diese Seite anzuzeigen', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
flash(f'Benutzer "{username}" wurde erfolgreich registriert!', 'success')
|
||||
return redirect(url_for('home_admin'))
|
||||
|
||||
return render_template(
|
||||
'register.html',
|
||||
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
||||
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
||||
student_default_borrow_days=cfg.STUDENT_DEFAULT_BORROW_DAYS,
|
||||
student_max_borrow_days=cfg.STUDENT_MAX_BORROW_DAYS,
|
||||
permission_presets=getattr(us, 'PERMISSION_PRESETS', {}),
|
||||
permission_action_options=PERMISSION_ACTION_OPTIONS,
|
||||
permission_page_options=PERMISSION_PAGE_OPTIONS
|
||||
)
|
||||
|
||||
@app.route('/user_del', methods=['GET'])
|
||||
def user_del():
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
flask
|
||||
flask-wtf
|
||||
werkzeug
|
||||
gunicorn
|
||||
pymongo
|
||||
|
||||
+137
-83
@@ -1,11 +1,3 @@
|
||||
<!--
|
||||
Copyright 2025-2026 AIIrondev
|
||||
|
||||
Licensed under the Inventarsystem EULA (Endbenutzer-Lizenzvertrag).
|
||||
See Legal/LICENSE for the full license text.
|
||||
Unauthorized commercial use, SaaS hosting, or removal of branding is prohibited.
|
||||
For commercial licensing inquiries: https://github.com/AIIrondev
|
||||
-->
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Register{% endblock %}
|
||||
@@ -33,6 +25,10 @@
|
||||
<div class="content">
|
||||
<div class="form-card">
|
||||
<form method="POST" action="{{ url_for('register') }}">
|
||||
|
||||
<!-- CSRF-Schutz (Zwingend erforderlich für POST) -->
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">Vorname</label>
|
||||
<div class="input-container">
|
||||
@@ -44,7 +40,7 @@
|
||||
<span class="input-icon">👤</span>
|
||||
<input type="text" id="last-name" name="last-name" placeholder="Geben Sie den Nachnamen ein" required onchange="generateUsername()" oninput="generateUsername()">
|
||||
</div>
|
||||
<label for="username">Benutzername <span style="color: #9ca3af;">(wird automatisch generiert)</span></label>
|
||||
<label for="username">Benutzername <span style="color: #9ca3af;">(Vorschau - wird serverseitig finalisiert)</span></label>
|
||||
<div class="input-container">
|
||||
<span class="input-icon">👤</span>
|
||||
<input type="text" id="username" name="username" placeholder="Automatisch aus Name und Nachname" readonly style="background-color: #f3f4f6; cursor: not-allowed;">
|
||||
@@ -64,9 +60,22 @@
|
||||
<li id="pw-rule-symbol" class="pw-rule">Mindestens ein Sonderzeichen</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="input-container">
|
||||
<span class="input-icon">🔒</span>
|
||||
<input type="password" id="password" name="password" placeholder="Geben Sie ein sicheres Passwort ein" required>
|
||||
|
||||
<div class="input-wrapper">
|
||||
<div class="input-container">
|
||||
<span class="input-icon">🔒</span>
|
||||
<!-- HTML5 Pattern blockiert unsichere Passwörter vor dem Absenden -->
|
||||
<input type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
placeholder="Geben Sie ein sicheres Passwort ein"
|
||||
required
|
||||
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{12,}">
|
||||
</div>
|
||||
<button type="button" class="btn-secondary" id="toggle-pw-btn" onclick="togglePasswordVisibility()" title="Passwort anzeigen/verbergen">👁️</button>
|
||||
</div>
|
||||
<div class="pw-actions">
|
||||
<button type="button" class="btn-secondary" onclick="generateSecurePassword()">🎲 Automatisches Passwort generieren</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -258,31 +267,6 @@ input::placeholder {
|
||||
background-color: #27ae60;
|
||||
}
|
||||
|
||||
.navigation-buttons {
|
||||
text-align: center;
|
||||
margin: 1.5rem 0;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: var(--transition);
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
background-color: rgba(52, 152, 219, 0.1);
|
||||
}
|
||||
|
||||
.back-icon {
|
||||
margin-right: 0.5rem;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.flash-container {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
@@ -422,49 +406,147 @@ input::placeholder {
|
||||
margin: 4px 0;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
/* Neue Styles für die Passwort-Erweiterungen */
|
||||
.pw-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
background-color: #f3f4f6;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9em;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: #e5e7eb;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.input-wrapper .input-container {
|
||||
flex-grow: 1;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// Function to generate username from first and last name (helper function)
|
||||
// Hilfsfunktion: Umlaute auflösen und Sonderzeichen entfernen
|
||||
function cleanNameForUsername(text) {
|
||||
if (!text) return '';
|
||||
// Remove special characters, convert umlauts, lowercase
|
||||
let cleaned = text
|
||||
.replace(/[^a-zA-Zäöüß\s-]/g, '')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
|
||||
// Convert German umlauts to ASCII
|
||||
cleaned = cleaned
|
||||
let cleaned = text.trim().toLowerCase()
|
||||
.replace(/ä/g, 'ae')
|
||||
.replace(/ö/g, 'oe')
|
||||
.replace(/ü/g, 'ue')
|
||||
.replace(/ß/g, 'ss');
|
||||
|
||||
.replace(/ß/g, 'ss')
|
||||
.replace(/[^a-z]/g, '');
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
// Generate username from name and last_name fields
|
||||
// Hilfsfunktion: Erster Buchstabe groß
|
||||
function formatPart(str, len) {
|
||||
if (!str) return '';
|
||||
const part = str.slice(0, len);
|
||||
return part.charAt(0).toUpperCase() + part.slice(1);
|
||||
}
|
||||
|
||||
// Generiert die Vorschau des Benutzernamens (z.B. SimFri)
|
||||
function generateUsername() {
|
||||
const firstName = cleanNameForUsername(document.getElementById('name').value || '');
|
||||
const lastName = cleanNameForUsername(document.getElementById('last-name').value || '');
|
||||
const firstName = cleanNameForUsername(document.getElementById('name').value);
|
||||
const lastName = cleanNameForUsername(document.getElementById('last-name').value);
|
||||
let username = '';
|
||||
|
||||
if (firstName && lastName) {
|
||||
username = (firstName.slice(0, 3) + lastName.slice(0, 3));
|
||||
username = formatPart(firstName, 3) + formatPart(lastName, 3);
|
||||
} else if (firstName) {
|
||||
username = firstName.slice(0, 6);
|
||||
username = formatPart(firstName, 6);
|
||||
} else if (lastName) {
|
||||
username = lastName.slice(0, 6);
|
||||
username = formatPart(lastName, 6);
|
||||
}
|
||||
|
||||
// Set the username field
|
||||
const usernameField = document.getElementById('username');
|
||||
if (usernameField) {
|
||||
usernameField.value = username || '';
|
||||
}
|
||||
}
|
||||
|
||||
// PASSWORT GENERATOR
|
||||
function generateSecurePassword() {
|
||||
const length = 16;
|
||||
const charsetLower = "abcdefghijklmnopqrstuvwxyz";
|
||||
const charsetUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const charsetNum = "0123456789";
|
||||
const charsetSym = "!@#$%^&*()_+~|}{[]:;?><,.-=";
|
||||
|
||||
let password = "";
|
||||
// Garantiert mindestens 1 Zeichen aus jeder Kategorie
|
||||
password += charsetLower[Math.floor(Math.random() * charsetLower.length)];
|
||||
password += charsetUpper[Math.floor(Math.random() * charsetUpper.length)];
|
||||
password += charsetNum[Math.floor(Math.random() * charsetNum.length)];
|
||||
password += charsetSym[Math.floor(Math.random() * charsetSym.length)];
|
||||
|
||||
const allChars = charsetLower + charsetUpper + charsetNum + charsetSym;
|
||||
// Restliche Zeichen auffüllen
|
||||
for (let i = 4; i < length; i++) {
|
||||
password += allChars[Math.floor(Math.random() * allChars.length)];
|
||||
}
|
||||
|
||||
// Passwort durchmischen
|
||||
password = password.split('').sort(() => 0.5 - Math.random()).join('');
|
||||
|
||||
const pwField = document.getElementById('password');
|
||||
pwField.value = password;
|
||||
|
||||
// Automatisch sichtbar machen, damit der User es kopieren kann
|
||||
pwField.type = 'text';
|
||||
document.getElementById('toggle-pw-btn').textContent = '🙈';
|
||||
|
||||
updatePasswordRules();
|
||||
}
|
||||
|
||||
// PASSWORT SICHTBARKEIT UMSCHALTEN
|
||||
function togglePasswordVisibility() {
|
||||
const pwField = document.getElementById('password');
|
||||
const toggleBtn = document.getElementById('toggle-pw-btn');
|
||||
if (pwField.type === "password") {
|
||||
pwField.type = "text";
|
||||
toggleBtn.textContent = '🙈';
|
||||
} else {
|
||||
pwField.type = "password";
|
||||
toggleBtn.textContent = '👁️';
|
||||
}
|
||||
}
|
||||
|
||||
// Globale Funktion für Passwort-Update
|
||||
function updatePasswordRules() {
|
||||
const passwordInput = document.getElementById('password');
|
||||
if (!passwordInput) return;
|
||||
|
||||
const value = String(passwordInput.value || '');
|
||||
|
||||
const setRuleState = (id, ok) => {
|
||||
const node = document.getElementById(id);
|
||||
if (node) node.classList.toggle('ok', !!ok);
|
||||
};
|
||||
|
||||
setRuleState('pw-rule-length', value.length >= 12);
|
||||
setRuleState('pw-rule-lower', /[a-z]/.test(value));
|
||||
setRuleState('pw-rule-upper', /[A-Z]/.test(value));
|
||||
setRuleState('pw-rule-digit', /[0-9]/.test(value));
|
||||
setRuleState('pw-rule-symbol', /[^A-Za-z0-9]/.test(value));
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const permissionPresets = {{ permission_presets | tojson }};
|
||||
const presetSelect = document.getElementById('permission-preset');
|
||||
@@ -507,34 +589,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
const passwordInput = document.getElementById('password');
|
||||
const passwordRules = {
|
||||
length: document.getElementById('pw-rule-length'),
|
||||
lower: document.getElementById('pw-rule-lower'),
|
||||
upper: document.getElementById('pw-rule-upper'),
|
||||
digit: document.getElementById('pw-rule-digit'),
|
||||
symbol: document.getElementById('pw-rule-symbol')
|
||||
};
|
||||
|
||||
function setRuleState(node, ok) {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
node.classList.toggle('ok', !!ok);
|
||||
}
|
||||
|
||||
function updatePasswordRules() {
|
||||
if (!passwordInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
const value = String(passwordInput.value || '');
|
||||
setRuleState(passwordRules.length, value.length >= 12);
|
||||
setRuleState(passwordRules.lower, /[a-z]/.test(value));
|
||||
setRuleState(passwordRules.upper, /[A-Z]/.test(value));
|
||||
setRuleState(passwordRules.digit, /[0-9]/.test(value));
|
||||
setRuleState(passwordRules.symbol, /[^A-Za-z0-9]/.test(value));
|
||||
}
|
||||
|
||||
if (passwordInput) {
|
||||
passwordInput.addEventListener('input', updatePasswordRules);
|
||||
passwordInput.addEventListener('blur', updatePasswordRules);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
flask
|
||||
flask-wtf
|
||||
werkzeug
|
||||
gunicorn
|
||||
pymongo==4.6.3
|
||||
|
||||
Reference in New Issue
Block a user