imlementation of a user management
This commit is contained in:
@@ -2064,6 +2064,72 @@ def change_email_and_resend():
|
||||
|
||||
return redirect(url_for("verify_account", username=username))
|
||||
|
||||
@app.route('/user/profile', methods=['GET', 'POST'])
|
||||
def user_profile():
|
||||
if 'username' not in session:
|
||||
flash("Bitte melden Sie sich an, um auf Ihr Profil zuzugreifen.", "warning")
|
||||
return redirect(url_for('login'))
|
||||
|
||||
username = session['username']
|
||||
|
||||
user = user_store.get_user(username)
|
||||
if not user:
|
||||
flash("Benutzer nicht gefunden. Bitte loggen Sie sich erneut ein.", "danger")
|
||||
session.clear()
|
||||
return redirect(url_for('login'))
|
||||
|
||||
if request.method == 'POST':
|
||||
action = request.form.get('action')
|
||||
|
||||
if action == 'update_info':
|
||||
email = request.form.get('email')
|
||||
full_name = request.form.get('full_name')
|
||||
|
||||
user_store.update_user_profile(username, full_name, email)
|
||||
|
||||
session['email'] = email
|
||||
session['full_name'] = full_name
|
||||
|
||||
flash("Ihre Profilinformationen wurden erfolgreich aktualisiert.", "success")
|
||||
return redirect(url_for('user_profile'))
|
||||
|
||||
elif action == 'change_password':
|
||||
current_password = request.form.get('current_password')
|
||||
new_password = request.form.get('new_password')
|
||||
confirm_password = request.form.get('confirm_password')
|
||||
|
||||
if not user_store.check_nm_pwd(username, current_password):
|
||||
flash("Das aktuelle Passwort ist nicht korrekt.", "danger")
|
||||
return redirect(url_for('user_profile'))
|
||||
|
||||
if new_password != confirm_password:
|
||||
flash("Die neuen Passwörter stimmen nicht überein.", "danger")
|
||||
return redirect(url_for('user_profile'))
|
||||
|
||||
if user_store.update_password(username, new_password):
|
||||
flash("Ihr Passwort wurde erfolgreich geändert.", "success")
|
||||
else:
|
||||
flash("Das Passwort ist zu schwach. Bitte verwenden Sie mindestens 6 Zeichen.", "warning")
|
||||
|
||||
return redirect(url_for('user_profile'))
|
||||
|
||||
elif action == 'delete_account':
|
||||
current_password = request.form.get('current_password')
|
||||
|
||||
if not user_store.check_nm_pwd(username, current_password):
|
||||
flash("Das Passwort ist nicht korrekt. Konto konnte nicht gelöscht werden.", "danger")
|
||||
return redirect(url_for('user_profile'))
|
||||
|
||||
if user_store.delete_user(username):
|
||||
session.clear()
|
||||
flash("Ihr Konto wurde erfolgreich gelöscht.", "info")
|
||||
return redirect(url_for('default'))
|
||||
else:
|
||||
flash("Fehler beim Löschen des Kontos. Bitte versuchen Sie es später erneut.", "danger")
|
||||
return redirect(url_for('user_profile'))
|
||||
|
||||
return render_template('user_profile.html', user=user)
|
||||
|
||||
@app.route('/download-sample')
|
||||
def download_sample():
|
||||
# Ensure the file is only served from the specific directory
|
||||
|
||||
@@ -133,4 +133,37 @@ def send_register_token(email: str, token: str) -> bool:
|
||||
</div>
|
||||
"""
|
||||
|
||||
return send(email, subject, text_body=text_note, html_body=html_note)
|
||||
|
||||
def send_password_reset_token(email: str, token: str) -> bool:
|
||||
"""Sends a professionally styled password reset token to the user."""
|
||||
|
||||
subject = "Aktion erforderlich: Ihr Passwort-Zurücksetzungs-Code für Invario"
|
||||
|
||||
text_note = (
|
||||
"Sie haben eine Anfrage zum Zurücksetzen Ihres Passworts gestellt.\n\n"
|
||||
"Um Ihr Passwort zurückzusetzen, geben Sie bitte den folgenden Sicherheitscode ein:\n\n"
|
||||
f"Code: {token}\n\n"
|
||||
"Dieser Code ist aus Sicherheitsgründen nur für begrenzte Zeit gültig. "
|
||||
"Falls Sie diese Anfrage nicht gestellt haben, können Sie diese E-Mail einfach ignorieren."
|
||||
)
|
||||
|
||||
html_note = f"""
|
||||
<div style="font-family: Arial, Helvetica, sans-serif; color: #333333;">
|
||||
<h2 style="color: #2c3e50; margin-top: 0;">Passwort zurücksetzen</h2>
|
||||
<p style="font-size: 15px; line-height: 1.6;">
|
||||
Sie haben eine Anfrage zum Zurücksetzen Ihres Passworts gestellt. Um fortzufahren, verwenden Sie bitte den folgenden Bestätigungscode:
|
||||
</p>
|
||||
|
||||
<div style="background-color: #f1f5f9; border-left: 4px solid #3b82f6; border-radius: 4px; padding: 25px; text-align: center; margin: 30px 0;">
|
||||
<span style="font-size: 32px; font-weight: bold; letter-spacing: 8px; color: #1e293b;">{token}</span>
|
||||
</div>
|
||||
|
||||
<p style="font-size: 13px; color: #64748b; line-height: 1.5;">
|
||||
Dieser Code ist aus Sicherheitsgründen nur für eine begrenzte Zeit gültig.<br>
|
||||
Falls Sie kein Zurücksetzen des Passworts angefordert haben, können Sie diese E-Mail sicher ignorieren.
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
|
||||
return send(email, subject, text_body=text_note, html_body=html_note)
|
||||
@@ -512,13 +512,17 @@
|
||||
<a href="{{ url_for('dienstleistungen') }}">Module</a>
|
||||
<a href="{{ url_for('preise') }}">Preise</a>
|
||||
<a href="{{ url_for('kontakt') }}">Kontakt</a>
|
||||
|
||||
{% if session.get('is_admin') %}
|
||||
<!-- NEU: Userverwaltung für Admins im mobilen Menü -->
|
||||
<a class="nav-user-link" href="{{ url_for('admin_users') }}">Userverwaltung</a>
|
||||
<a class="nav-user-link" href="{{ url_for('admin_invoices') }}">Rechnungsverwaltung</a>
|
||||
<a class="nav-user-link" href="{{ url_for('admin_blog') }}">Blog verwalten</a>
|
||||
<a class="nav-user-link" href="{{ url_for('admin_chats') }}">Admin-Chat</a>
|
||||
<a class="nav-user-link" href="{{ url_for('admin_tickets') }}">Support-Center</a>
|
||||
<a class="nav-user-link" href="{{ url_for('admin_system_tools') }}">System-Tools</a>
|
||||
{% elif 'username' in session %}
|
||||
<a class="nav-user-link" href="{{ url_for('user_profile') }}">Mein Profil</a>
|
||||
<a class="nav-user-link" href="{{ url_for('my_tutorials') }}">Tutorials</a>
|
||||
<a class="nav-user-link" href="{{ url_for('my_invoices') }}">Meine Rechnungen</a>
|
||||
<a class="nav-user-link" href="{{ url_for('my_instance_management') }}">Meine Instanz</a>
|
||||
@@ -536,7 +540,7 @@
|
||||
<details class="nav-dropdown">
|
||||
<summary class="nav-btn">Admin</summary>
|
||||
<div class="dropdown-menu">
|
||||
<a href="{{ url_for('admin_users') }}">Userverwaltung</a>
|
||||
<a href="{{ url_for('admin_users') }}">Userverwaltung</a> <!-- War bereits hier vorhanden -->
|
||||
<a href="{{ url_for('admin_invoices') }}">Rechnungsverwaltung</a>
|
||||
<a href="{{ url_for('admin_chats') }}">Admin-Chat</a>
|
||||
<a href="{{ url_for('admin_tickets') }}">Support-Center</a>
|
||||
@@ -550,6 +554,8 @@
|
||||
<details class="nav-dropdown">
|
||||
<summary class="nav-btn">Nutzerbereich</summary>
|
||||
<div class="dropdown-menu">
|
||||
<!-- NEU: Profilverwaltung für reguläre Nutzer im Desktop Dropdown -->
|
||||
<a href="{{ url_for('user_profile') }}">Mein Profil</a>
|
||||
<a href="{{ url_for('my_tutorials') }}">Tutorials</a>
|
||||
<a href="{{ url_for('my_invoices') }}">Meine Rechnungen</a>
|
||||
<a href="{{ url_for('my_instance_management') }}">Meine Instanz</a>
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Mein Profil - Invario{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<style>
|
||||
.profile-container {
|
||||
max-width: 900px;
|
||||
margin: 40px auto;
|
||||
padding: 0 20px;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.profile-header {
|
||||
margin-bottom: 30px;
|
||||
border-bottom: 2px solid #e2e8f0;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
.profile-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.profile-grid {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #ffffff;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
margin-top: 0;
|
||||
color: #1e293b;
|
||||
font-size: 1.25rem;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: #475569;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 6px;
|
||||
font-size: 0.95rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
|
||||
}
|
||||
|
||||
.form-control[readonly] {
|
||||
background-color: #f8fafc;
|
||||
color: #64748b;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-submit {
|
||||
background-color: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 18px;
|
||||
border-radius: 6px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.btn-submit:hover {
|
||||
background-color: #2563eb;
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.alert-success { background-color: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
|
||||
.alert-danger { background-color: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
|
||||
.alert-warning { background-color: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
|
||||
</style>
|
||||
|
||||
<div class="profile-container">
|
||||
<div class="profile-header">
|
||||
<h1>Mein Profil</h1>
|
||||
<p style="color: #64748b;">Verwalten Sie Ihre persönlichen Informationen und Sicherheitseinstellungen.</p>
|
||||
</div>
|
||||
|
||||
<!-- Flash-Nachrichten anzeigen -->
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="profile-grid">
|
||||
<!-- Karte 1: Allgemeine Informationen -->
|
||||
<div class="card">
|
||||
<h3>Persönliche Daten</h3>
|
||||
<form action="{{ url_for('user_profile') }}" method="POST">
|
||||
<input type="hidden" name="action" value="update_info">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="username">Benutzername</label>
|
||||
<input type="text" id="username" class="form-control" value="{{ session.get('username', '') }}" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="full_name">Vollständiger Name</label>
|
||||
<input type="text" id="full_name" name="full_name" class="form-control" value="{{ session.get('full_name', '') }}" placeholder="Max Mustermann">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">E-Mail-Adresse</label>
|
||||
<input type="email" id="email" name="email" class="form-control" value="{{ session.get('email', '') }}" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">Änderungen speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Karte 2: Passwort ändern -->
|
||||
<div class="card">
|
||||
<h3>Passwort ändern</h3>
|
||||
<form action="{{ url_for('user_profile') }}" method="POST">
|
||||
<input type="hidden" name="action" value="change_password">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="current_password">Aktuelles Passwort</label>
|
||||
<input type="password" id="current_password" name="current_password" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new_password">Neues Passwort</label>
|
||||
<input type="password" id="new_password" name="new_password" class="form-control" minlength="8" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm_password">Neues Passwort bestätigen</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" class="form-control" minlength="8" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">Passwort aktualisieren</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -219,6 +219,28 @@ def update_user_email_and_token(username, new_email, new_token):
|
||||
{'$set': {'email': new_email.strip().lower(), 'verification_token': hashed_token}}
|
||||
)
|
||||
return result.modified_count > 0
|
||||
finally:
|
||||
if client:
|
||||
client.close()
|
||||
|
||||
def update_user_profile(username, contact_person, email):
|
||||
"""
|
||||
Aktualisiert die Profilinformationen (Name und E-Mail) eines Nutzers.
|
||||
"""
|
||||
client = None
|
||||
try:
|
||||
client, users = _get_users_collection()
|
||||
result = users.update_one(
|
||||
{'Username': username},
|
||||
{'$set': {
|
||||
'contact_person': contact_person,
|
||||
'email': email.strip().lower()
|
||||
}}
|
||||
)
|
||||
return result.modified_count > 0
|
||||
except Exception as e:
|
||||
print(f"Error updating profile: {e}")
|
||||
return False
|
||||
finally:
|
||||
if client:
|
||||
client.close()
|
||||
Reference in New Issue
Block a user