Hello everyone,
In my flask application there is some issue related to login system  and 
issue as below         1)in  flask app there are multiple users(roles) like 
admin ,indentor.....etc. and the problem is that if any user login on same 
browser where already any user logged in then previous user automatically 
logout and recent user logging successfully 
2)if browser are different and users also different means only one user 
login through one browser then there is no problem it works properly 
3)if browser is same and user also same then same name user login 
successfully but previous same user session id change 
4)in  any browser with same web page who running  on local server  all tabs 
session id same inside the cookies it means on same browser all tabs 
session id same for same web application 

i current situation i face the issue related to session management ,and 
issue is that only one user login at same time with same browser 

so please read all above the conditions very carefully and then provide the 
solution ,i also attach the code in below and session management working 
flow screenshot 

# Flask-Login Configuration
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

# User model
class User(UserMixin):
def __init__(self,user_id, username, password):
self.id=user_id
self.username = username
self.password = password
def get_id(self):
return str(self.id) # Convert to string if necessary

@login_manager.user_loader
def load_user(user_id):
user_data =collection_user.find_one({'user_type': user_id})
if user_data:
return User(user_id=user_data['user_type'],username=user_data['user_type'], 
password=user_data['password'])
return None
#LOGIN MODULE 
# Route for user login
@app.route('/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
print('inside the login')
user_type = request.form.get('user_type')
email = request.form.get('email')
password = request.form.get('password')
print('value of user type->>>', user_type)
print('value of email->>>', email)
print('value of password->>>', password)

user=collection_user.find_one({'user_type':user_type,'email':email,
'password':password})
print('value of user is->>>',user)
if user:
user_obj=load_user(user_type)
# Generate a unique session ID for the user
session_key = f"user_{user['_id']}_{uuid4()}"
# Store user-specific data in the session using the generated session key
session['user_type'] = user_type
session['user_email'] = email
session['session_key'] = session_key
print('value of user_obj is-->>',user_obj)
login_user(user_obj)
return redirect(url_for('dashboard'))
return render_template('login.html', error='Invalid credentials,plz enter 
valid id or password')
print('direct out of the if condition')

return render_template('login.html', error=None)

@app.route('/dashboard')
@login_required
def dashboard():
#Retrieve the session key from the session
session_key = session.get('session_key')
if session_key:

# Retrieve the session key from the cookie
user_type = session.get('user_type')
print('value user_type is-->>',user_type)
if user_type == 'admin':
print('inside the admin user')
return redirect(url_for('home_page'))
elif user_type == 'indenter':
print('inside the indenter user')
return redirect(url_for('indenter_dashboard'))
elif user_type == 'purchaser':
print('inside the purchaser user')
return redirect(url_for('purchaser_dashboard'))
elif user_type == 'store':
print('inside the store user')
return redirect(url_for('store_dashboard'[image: Screenshot from 2024-04-03 
16-36-43.png]))[image: Screenshot from 2024-04-03 16-36-43.png]

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/9c06cac8-f60d-4919-9184-fbae2083d439n%40googlegroups.com.

Reply via email to