diff --git a/app/profile/routes.py b/app/profile/routes.py index 70ac51dfd85b6b78e8185fb90e6f43225312996d..8d3a7bd1e0c7d10f0520ae7ca1221873933d3b8d 100644 --- a/app/profile/routes.py +++ b/app/profile/routes.py @@ -6,7 +6,7 @@ from werkzeug.security import check_password_hash from app.profile import bp from app.models import User from app.logger import auth_logger -from app import db +from app import db, permission_required, user_permission @bp.route('/signup', methods=['GET', 'POST']) def signup(): @@ -193,10 +193,17 @@ def check_password_reset_2(): @bp.route('/password-reset/reset-password') +@permission_required(user_permission) def password_reset_3(): return render_template('profile/password-reset-3.html') +@bp.route('password-reset/from-profile') +@permission_required(user_permission) +def password_reset_from_profile(): + email = current_user.email + + @bp.route('/password-reset/reset-password', methods=['POST']) def password_reset_process(): email = session.get('password-reset-email') @@ -225,4 +232,18 @@ def manage_bookings(): if current_user.is_authenticated: return render_template('profile/manage_bookings.html', username=current_user.username) - return redirect(url_for('profile.login')) \ No newline at end of file + return redirect(url_for('profile.login')) + +@bp.route('/manage_profile', methods=['GET', 'POST']) +def manage_profile(): + user = User.search_user_id(current_user.id) + + if user == None: + flash('You must be logged in to update your profile','error') + return redirect(url_for('main.index')) + if request.method == 'POST': + name = request.form['name'] + email = request.form['email'] + + return redirect(url_for('profile.home')) + return render_template('profile/manage_profile.html', user=user) diff --git a/app/templates/base.html b/app/templates/base.html index 5aee9d151ded502dc33e80c738ba425e3a85dfc2..d8ab657335f94f23ffeb6c26094f4aa419e11207 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -74,7 +74,7 @@ {% if g.is_admin %} <li><a class="dropdown-item" href="{{ url_for('admin.index') }}">Admin Options</a></li> {% endif %} - <li><a class="dropdown-item" href="{{ url_for('profile.index') }}">Account Details</a></li> + <li><a class="dropdown-item" href="{{ url_for('profile.index') }}">My Profile</a></li> <li><a class="dropdown-item" href="{{ url_for('profile.manage_bookings')}}">My Bookings</a></li> <li><a class="dropdown-item" href="{{ url_for('profile.logout') }}">Log Out</a></li> {% else %} diff --git a/app/templates/profile/index.html b/app/templates/profile/index.html index b59772cde5c45f2268b922996f5a994ccfbe2921..1b208f46f5409d5ec9034af3c70231b3eb53f663 100644 --- a/app/templates/profile/index.html +++ b/app/templates/profile/index.html @@ -1,7 +1,30 @@ {% extends 'base.html' %} {% block content %} -<div> - <p>Welcome {{username}}!</p> - +<div class="container"> + <div class="jumbotron mt-5"> + <h1 class="display-4">Hello, {{username.capitalize()}}!</h1> + <p class="lead">Welcome to your Horizon Travels dashboard. Your next travel date is on the horizon!</p> + <hr class="my-4"> + </div> + <div class="row mt-4"> + <div class="col-md-6"> + <div class="card"> + <div class="card-body"> + <h5 class="card-title">Manage Bookings</h5> + <p class="card-text">Easily view and update your bookings.</p> + <a href="{{ url_for('profile.manage_bookings') }}" class="btn btn-primary">Go to Bookings</a> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="card"> + <div class="card-body"> + <h5 class="card-title">Update Personal Information</h5> + <p class="card-text">Keep your personal details up to date.</p> + <a href="{{ url_for('profile.manage_profile') }}" class="btn btn-secondary">Update Info</a> + </div> + </div> + </div> + </div> </div> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/templates/profile/manage_profile.html b/app/templates/profile/manage_profile.html new file mode 100644 index 0000000000000000000000000000000000000000..87968615832181b56e9af5ffde63a287d246f8c9 --- /dev/null +++ b/app/templates/profile/manage_profile.html @@ -0,0 +1,70 @@ +{% extends 'base.html' %} +{% block content %} +<div class="container"> + <div class="mt-5"> + <h1 class="display-4">User Profile</h1> + <div> + <button class="btn btn-info mb-3" id="editButton" onclick="enableEditing()"> + <i class="fas fa-wrench"></i> Edit + </button> + <form id="updateForm" action="{{ url_for('profile.manage_profile') }}" method="post" onsubmit="return showModal()"> + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"> + <div class="form-group"> + <label for="username">Username</label> + <input type="text" class="form-control" id="username" name="username" value="{{ user.username }}" disabled required> + </div> + <div class="form-group"> + <label for="email">Email</label> + <input type="email" class="form-control" id="email" name="email" value="{{ user.email }}" disabled required> + </div> + <button type="submit" class="btn btn-primary" disabled>Update Info</button> + </form> + <a href="{{ url_for('profile.password_reset_process') }}" class="btn btn-warning"><i class="fas fa-key"></i> Reset Password</a> + </div> + </div> +</div> + +<!-- Modal --> +<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title" id="confirmModalLabel">Confirm Update</h5> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + </div> + <div class="modal-body"> + <p>Type "CONFIRM" to proceed with the update.</p> + <input type="text" class="form-control" id="confirmInput" required> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> + <button type="button" class="btn btn-primary" onclick="submitForm()">Confirm</button> + </div> + </div> + </div> +</div> + +<script> + function enableEditing() { + document.getElementById('username').disabled = false; + document.getElementById('email').disabled = false; + document.querySelector('button[type="submit"]').disabled = false; + } + + function showModal() { + $('#confirmModal').modal('show'); + return false; + } + + function submitForm() { + var confirmInput = document.getElementById('confirmInput').value; + if (confirmInput === 'CONFIRM') { + document.getElementById('updateForm').submit(); + } else { + alert('Please type "CONFIRM" to proceed.'); + } + } +</script> +{% endblock %}