Reputation: 59
I have implemented a web server using python flask and hosted in pythonanywhere.com ... I have used global variables in my implementation for handle login sessions. for example-
TOKENS = {"OAUTH_TOKEN": ""}
if(TOKENS['OAUTH_TOKEN']) == "":
authorized = Flase
else:
authorized = True
But the problem is when a user logged and authorized the second user get as a authorized user. pythonanywhere used WSGI as a server for run python flask web application. How can I handle each user as separates threads?
Upvotes: 2
Views: 1578
Reputation: 1357
You can write your code to create a login solotion but It's not realy safe.need to set the login credential in the session and load the user with each request and load it in each request and set g object.
#login
session['user'] = user_id
@app.before_request
def before_request():
current_user = user_obj
g.user = current_user
You can use this guide for a good login app.
Upvotes: 5
Reputation: 1413
You can use Flask-Login extension. It can handle most of typical user-management activities out-of-the-box.
Upvotes: 3