added profile page
This commit is contained in:
parent
4fd34ba5bc
commit
befdb5fc2b
47
app.py
47
app.py
@ -119,7 +119,6 @@ def logout():
|
|||||||
# Create a new route
|
# Create a new route
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
habits = current_user.get_habits()
|
habits = current_user.get_habits()
|
||||||
name = "Hallo " + current_user.name
|
name = "Hallo " + current_user.name
|
||||||
@ -173,7 +172,7 @@ def habit_creation():
|
|||||||
return render_template(
|
return render_template(
|
||||||
'habit.html',
|
'habit.html',
|
||||||
title='Erstelle ein Habit',
|
title='Erstelle ein Habit',
|
||||||
unit=1,
|
unit="Woche",
|
||||||
errors={},
|
errors={},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -251,6 +250,50 @@ def habit_create():
|
|||||||
)"""
|
)"""
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/profile')
|
||||||
|
@login_required
|
||||||
|
def profile():
|
||||||
|
return render_template(
|
||||||
|
"profile.html",
|
||||||
|
name=current_user.name,
|
||||||
|
email=current_user.email,
|
||||||
|
errors={}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/profile', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def profile_change():
|
||||||
|
newName = request.form.get('newName')
|
||||||
|
newEmail = request.form.get('newEmail')
|
||||||
|
newPassword = request.form.get('newPassword')
|
||||||
|
oldPassword = request.form.get('oldPassword')
|
||||||
|
|
||||||
|
# Check for errors
|
||||||
|
errors = {}
|
||||||
|
if not newName and not newEmail and not newPassword:
|
||||||
|
errors['newName'] = 'Mindestens eine Änderung muss erfolgen.'
|
||||||
|
errors['newEmail'] = 'Mindestens eine Änderung muss erfolgen.'
|
||||||
|
errors['newPassword'] = 'Mindestens eine Änderung muss erfolgen.'
|
||||||
|
if not oldPassword:
|
||||||
|
errors['oldPassword'] = 'Du musst dein aktuelles Passwort angeben.'
|
||||||
|
|
||||||
|
print(errors)
|
||||||
|
if errors:
|
||||||
|
return render_template(
|
||||||
|
"profile.html",
|
||||||
|
name=current_user.name,
|
||||||
|
email=current_user.email,
|
||||||
|
errors=errors
|
||||||
|
)
|
||||||
|
|
||||||
|
# Save habit to database
|
||||||
|
# habit = Habit.create(current_user.id, name, times, note, unit)
|
||||||
|
|
||||||
|
# Back to index
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/check', methods=['POST'])
|
@app.route('/check', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def check_habit():
|
def check_habit():
|
||||||
|
|||||||
@ -7,14 +7,14 @@
|
|||||||
<form action="/habit" method="POST">
|
<form action="/habit" method="POST">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="name" class="form-label">Name der Gewohnheit</label>
|
<label for="name" class="form-label">Name der Gewohnheit</label>
|
||||||
<input type="text" class="form-control {% if errors.get('name') %} is-invalid {% endif %}" id="name" name="name">
|
<input type="text" class="form-control {% if errors.get('name') %} is-invalid {% endif %}" id="name" name="name" value="{{name}}">
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ errors.get('name', '') }}
|
{{ errors.get('name', '') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="note" class="form-label">Beschreibung</label>
|
<label for="note" class="form-label">Beschreibung</label>
|
||||||
<input type="text" class="form-control {% if errors.get('note') %} is-invalid {% endif %}" id="note" name="note">
|
<input type="text" class="form-control {% if errors.get('note') %} is-invalid {% endif %}" id="note" name="note" value="{{note}}">
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ errors.get('note', '') }}
|
{{ errors.get('note', '') }}
|
||||||
</div>
|
</div>
|
||||||
@ -23,7 +23,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="mb-3 col-2">
|
<div class="mb-3 col-2">
|
||||||
<label for="times" class="form-label">Häufigkeit</label>
|
<label for="times" class="form-label">Häufigkeit</label>
|
||||||
<input type="number" min="1" class="form-control {% if errors.get('times') %} is-invalid {% endif %}" id="times" name="times">
|
<input type="number" min="1" class="form-control {% if errors.get('times') %} is-invalid {% endif %}" id="times" name="times" value="{{times}}">
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ errors.get('times', '') }}
|
{{ errors.get('times', '') }}
|
||||||
</div>
|
</div>
|
||||||
@ -31,12 +31,23 @@
|
|||||||
<div class="mb-3 col-10">
|
<div class="mb-3 col-10">
|
||||||
<label for="unit" class="form-label">Im Zeitraum</label>
|
<label for="unit" class="form-label">Im Zeitraum</label>
|
||||||
<select class="form-select {% if errors.get('unit') %} is-invalid {% endif %}" id="unit" name="unit">
|
<select class="form-select {% if errors.get('unit') %} is-invalid {% endif %}" id="unit" name="unit">
|
||||||
<option selected value="Woche">Woche</option>
|
|
||||||
<option value="Tag">Tag</option>
|
<option value="Tag">Tag</option>
|
||||||
|
<option value="Woche">Woche</option>
|
||||||
<option value="Monat">Monat</option>
|
<option value="Monat">Monat</option>
|
||||||
<option value="Jahr">Jahr</option>
|
<option value="Jahr">Jahr</option>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
|
let selectedElement = document.getElementById('unit');
|
||||||
|
|
||||||
|
for (let option of selectedElement.options) {
|
||||||
|
if (option.value == '{{ unit }}') {
|
||||||
|
option.selected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ errors.get('unit', '') }}
|
{{ errors.get('unit', '') }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
<link rel="stylesheet" href="/static/main.css">
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||||
|
|
||||||
<!-- Axios Libary-->
|
<!-- Axios Library-->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body style="background-color: White">
|
<body style="background-color: White">
|
||||||
@ -35,6 +35,9 @@
|
|||||||
<a class="btn btn-outline-secondary" aria-current="page" href="{{ url_for('signup') }}">Signup</a>
|
<a class="btn btn-outline-secondary" aria-current="page" href="{{ url_for('signup') }}">Signup</a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<li class="nav-item me-2">
|
||||||
|
<a class="btn text-white btn-primary" aria-current="page" href="{{ url_for('profile') }}">Profil</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item me-2">
|
<li class="nav-item me-2">
|
||||||
<a class="btn btn-primary" aria-current="page" href="{{ url_for('logout') }}">Logout</a>
|
<a class="btn btn-primary" aria-current="page" href="{{ url_for('logout') }}">Logout</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
46
templates/profile.html
Normal file
46
templates/profile.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{% extends 'layouts/main.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1 class="mt-5">Account Einstellungen👤</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<form action="/profile" method="POST">
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="newName">Neuer Name:</label>
|
||||||
|
<input type="text" class="form-control {% if errors.get('newName') %} is-invalid {% endif %}" id="newName" name="newName" value="{{name}}">
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{{ errors.get('newName', '') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="newEmail">Neue E-Mail:</label>
|
||||||
|
<input type="email" class="form-control {% if errors.get('newEmail') %} is-invalid {% endif %}" id="newEmail" name="newEmail" value="{{email}}">
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{{ errors.get('newEmail', '') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="newPassword">Neues Passwort:</label>
|
||||||
|
<input type="password" class="form-control {% if errors.get('newPassword') %} is-invalid {% endif %}" id="newPassword" name="newPassword">
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{{ errors.get('newPassword', '') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="oldPassword">Altes Passwort:</label>
|
||||||
|
<input type="password" class="form-control {% if errors.get('oldPassword') %} is-invalid {% endif %}" id="oldPassword" name="oldPassword">
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{{ errors.get('oldPassword', '') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Änderungen speichern</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user