diff --git a/app.py b/app.py index 8d89b5f..9c95282 100644 --- a/app.py +++ b/app.py @@ -35,7 +35,7 @@ def create_app(): @app.context_processor def inject_csrf_token(): - return dict(csrf_token=generate_csrf()) + return dict(csrf_token=lambda: generate_csrf()) @app.context_processor def inject_config(): diff --git a/routes/__pycache__/main.cpython-313.pyc b/routes/__pycache__/main.cpython-313.pyc index 29df1e0..27887f2 100644 Binary files a/routes/__pycache__/main.cpython-313.pyc and b/routes/__pycache__/main.cpython-313.pyc differ diff --git a/routes/main.py b/routes/main.py index 169f103..47fa755 100644 --- a/routes/main.py +++ b/routes/main.py @@ -270,8 +270,12 @@ def init_routes(main_bp): @require_password_change def profile(): if request.method == 'POST': + logger.debug(f"Profile form submitted with data: {request.form}") + logger.debug(f"Files in request: {request.files}") + # Handle profile picture removal if 'remove_picture' in request.form: + logger.debug("Removing profile picture") if current_user.profile_picture: # Delete the old profile picture file old_picture_path = os.path.join(UPLOAD_FOLDER, current_user.profile_picture) @@ -283,6 +287,7 @@ def init_routes(main_bp): return redirect(url_for('main.profile')) new_email = request.form.get('email') + logger.debug(f"New email: {new_email}") # Check if the new email is already used by another user if new_email != current_user.email: existing_user = User.query.filter_by(email=new_email).first() @@ -292,6 +297,7 @@ def init_routes(main_bp): # Handle profile picture upload file = request.files.get('profile_picture') if file and file.filename: + logger.debug(f"Uploading new profile picture: {file.filename}") filename = secure_filename(file.filename) file_path = os.path.join(UPLOAD_FOLDER, filename) file.save(file_path) @@ -304,22 +310,62 @@ def init_routes(main_bp): current_user.company = request.form.get('company') current_user.position = request.form.get('position') current_user.notes = request.form.get('notes') + + logger.debug(f"Updated user data: username={current_user.username}, last_name={current_user.last_name}, email={current_user.email}") + # Handle password change if provided new_password = request.form.get('new_password') confirm_password = request.form.get('confirm_password') if new_password: + if not confirm_password: + flash('Please confirm your new password.', 'error') + return render_template('profile/profile.html') if new_password != confirm_password: flash('Passwords do not match.', 'error') return render_template('profile/profile.html') current_user.set_password(new_password) flash('Password updated successfully.', 'success') + elif confirm_password: + flash('Please enter a new password.', 'error') + return render_template('profile/profile.html') try: db.session.commit() + logger.debug("Profile changes committed to database") + # Log profile update event + event_details = { + 'user_id': current_user.id, + 'email': current_user.email, + 'update_type': 'profile_update', + 'updated_fields': { + 'username': current_user.username, + 'last_name': current_user.last_name, + 'email': current_user.email, + 'phone': current_user.phone, + 'company': current_user.company, + 'position': current_user.position, + 'notes': current_user.notes, + 'profile_picture': bool(current_user.profile_picture) + }, + 'changes': { + 'username': request.form.get('first_name'), + 'last_name': request.form.get('last_name'), + 'email': request.form.get('email'), + 'phone': request.form.get('phone'), + 'company': request.form.get('company'), + 'position': request.form.get('position'), + 'notes': request.form.get('notes'), + 'password_changed': bool(new_password) + } + } + logger.debug(f"Creating profile update event with details: {event_details}") + event = log_event('user_update', event_details, current_user.id) + logger.debug(f"Event created successfully with ID: {event.id}") flash('Profile updated successfully!', 'success') except Exception as e: + logger.error(f"Error updating profile or logging event: {str(e)}") db.session.rollback() flash('An error occurred while updating your profile.', 'error') - return redirect(url_for('main.profile')) + return redirect(url_for('main.dashboard')) return render_template('profile/profile.html') @main_bp.route('/starred') diff --git a/templates/profile/profile.html b/templates/profile/profile.html index ccfc7d0..f360b42 100644 --- a/templates/profile/profile.html +++ b/templates/profile/profile.html @@ -6,6 +6,7 @@
+
@@ -93,8 +94,8 @@
diff --git a/templates/settings/tabs/events.html b/templates/settings/tabs/events.html index 66be116..5d93c7c 100644 --- a/templates/settings/tabs/events.html +++ b/templates/settings/tabs/events.html @@ -42,7 +42,7 @@ @@ -122,7 +122,7 @@ {{ event.event_type }} {% endif %} - {{ event.user.username if event.user else 'Unknown' }} + {{ event.user.username }} {{ event.user.last_name if event.user else 'Unknown' }}