From 37fcc5f34c939849e2a77e1f030900141a0bd1bc Mon Sep 17 00:00:00 2001 From: Kobe Date: Thu, 29 May 2025 22:40:59 +0200 Subject: [PATCH] fixed some issues with profile and events --- app.py | 2 +- routes/__pycache__/main.cpython-313.pyc | Bin 42369 -> 45250 bytes routes/main.py | 48 +++++++++++++++++- templates/profile/profile.html | 5 +- templates/settings/tabs/events.html | 4 +- .../__pycache__/event_logger.cpython-313.pyc | Bin 4462 -> 5383 bytes utils/event_logger.py | 38 +++++++++----- 7 files changed, 79 insertions(+), 18 deletions(-) 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 29df1e0004ba358a576244db39b066655f860cc4..27887f2a7b906b9ed45f66ff5c41dc4f78ecd86f 100644 GIT binary patch delta 4894 zcma)A4|G%I6@M@Pnx;t_NN7u&v@axW2`&FDrBG;*($aROe;?s+NTG)IHH4-~`H}*y zvH<==-6r@=L=-I?&XCP%U3V1EJVSQez{B*UOSCR#2-E4n&DBw-a~`+vzL%E-?Ag|H z`g`}g-~IR9d%yc$yZ@5pS63z48yby@B0n|1S+V`V!56jH8?v=zsVBcTHW8|p#_xL> zElXE#qNqlN>sg9&%JAVrql}d}DZFL95f2{IN<^NN@SYjwc`{Ze2&h&OW3Kl^MF}g% zOODOKUtm4H^T|y4i)2HG%NmV%joKjFkmXe4Pq9&5DIr?q$0zQ7>M>w_V=k@3JAFpn z*f`6i79=Rjn;}xpe38O~PZ=bgMR?y16K%%Y9l17(xaBMsDOOoY3$*yOQi)TYJ#5gj znIhXq3n#=GJ$flkLd+gCDynyrb2a1nk23fHtwHIa*{qdx=ThP_|8}3mA(@|W)m!cff&SiLUbAdb{CRM@ec;?n) zjMiB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t$L_N{%uM!y<|1bx@5j^G<-$WZ4V;*Za3Gf65Lw@iAc>{C{uobQg6$_- p2@ew|8r?XRE=Kth#3BY&s_qYW4+fQ5x(UkO*lT{&LKbSn{{?Inp&0-G 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' }}