Created
April 23, 2024 19:57
-
-
Save ShahriyarR/6c38d6d749d043181bfbf8b57b12fb1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
import threading | |
import time | |
app = Flask(__name__) | |
# Mock database storing user data | |
users = { | |
'1': {'email': 'user1@example.com'}, | |
'2': {'email': 'user2@example.com'} | |
} | |
# Shared variable for email updates | |
temporary_email_storage = "" | |
@app.route('/change_email/<user_id>', methods=['POST']) | |
def change_email(user_id): | |
global temporary_email_storage | |
new_email = request.form['email'] | |
print(f"Received request to change email for user {user_id} to {new_email}") | |
# Store the email in a shared variable | |
temporary_email_storage = new_email | |
# Simulate a delay to enhance the chance of race conditions | |
time.sleep(1) | |
# Check if the user exists | |
if user_id in users: | |
# Update the email from the shared variable | |
users[user_id]['email'] = temporary_email_storage | |
print(f"Email for user {user_id} changed to {temporary_email_storage}") | |
return f"Email changed to {temporary_email_storage} for user {user_id}", 200 | |
else: | |
return "User not found", 404 | |
if __name__ == '__main__': | |
app.run(debug=True, threaded=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment