flask-login

How to use g.user global in flask

六眼飞鱼酱① 提交于 2019-11-27 17:19:58
As I understand the g variable in Flask, it should provide me with a global place to stash data like holding the current user after login. Is this correct? I would like my navigation to display my user's name, once logged in, across the site. My views contain from Flask import g #among other things During login, I assign user = User.query.filter_by(username = form.username.data).first() if validate(user): session['logged_in'] = True g.user = user It doesn't seem I can access g.user. Instead, when my base.html template has the following... <ul class="nav"> {% if session['logged_in'] %} <li

flask-login: can't understand how it works

有些话、适合烂在心里 提交于 2019-11-27 10:13:32
I'm trying to understand how Flask-Login works. I see in their documentation that they use a pre-populated list of users. I want to play with a database-stored users list. However, I don't understand some things in this Flask-Login module. @login_manager.user_loader def load_user(userid): #print 'this is executed',userid return user(userid, 'asdf') This code will be called at every request? This is used to load all the details of my user object? For now, I have this code: @app.route('/make-login') def make_login(): username = 'asdf' password = 'asdf' user_data = authenticate(username, password

Implementing Flask-Login with multiple User Classes

杀马特。学长 韩版系。学妹 提交于 2019-11-27 05:23:18
问题 I am writing an app that has multiple classes that function as Users (for example, a School Account and a Staff account). I'm trying to use Flask-Login to make this easy but I'm not quite sure how to make it, so that when a user logs in I can have my app check to see whether or not the username belongs to a School account or Staff account, and then log in appropriately. I know how to figure out which type of account it belongs to (since all usernames must be unique). But after that I'm not

Flask-Login - How to get Session ID

岁酱吖の 提交于 2019-11-27 02:18:53
问题 Am doing a project with Flask, Gevent and web socket using flask development server environment. I used flask_login . Here how can get i get the Unique Session ID for each connection? I want to store the SessionID in the Database and delete it once client disconnects. How to get total active connections from flask_login import * login_manager = LoginManager() login_manager.setup_app(app) @app.route("/", methods=["GET", "POST"]) def login(): login_user([username], remember): @app.route("

flask-login can not be used in Blueprint object?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 02:03:32
问题 I have a question regarding flask-login and blueprint. admin.py admin = Blueprint('admin', __name__) login_manager = LoginManager() login_manager.setup_app(admin) @login_manager.user_loader def load_user(userid): return User.query.get(int(userid)) @admin.route('/login', methods=["GET", "POST"]) def login(): login_form = LoginForm() if request.method == 'POST': #####user validation#### login_user(user) return redirect('/') return render_template('admin/login.html', login_form=login_form) run

flask unit test: how to test request from logged in user

三世轮回 提交于 2019-11-27 01:55:38
问题 I'm writing some unit tests for my Flask web application and I'm trying to test the differences in the response between a request made by an anonymous user and a logged in user. I'm using the Flask-Login extension to implement the user login/logout. Obviously I'm able to perform an anonymous request, but how do I simulate a request from a logged in user? I thought it was enough to send in the headers the session cookie, but it's not working. headers = Headers({'Cookie':['WEBSITE_ID=%s; Domain

is_authenticated() raises TypeError TypeError: 'bool' object is not callable [duplicate]

送分小仙女□ 提交于 2019-11-27 01:38:47
问题 This question already has an answer here: Flask-Login raises TypeError: 'bool' object is not callable when trying to override is_active property 2 answers I tried to use is_authenticated() in a view, but got the error `TypeError: 'bool' object is not callable. Why am I getting this error and how do I fix it? @auth.before_app_request def before_request(): if current_user.is_authenticated() \ and not current_user.confirmed \ and request.endpoint[:5] != 'auth.' \ and request.endpoint != 'static'

flask-login: can't understand how it works

别等时光非礼了梦想. 提交于 2019-11-26 22:19:12
问题 I'm trying to understand how Flask-Login works. I see in their documentation that they use a pre-populated list of users. I want to play with a database-stored users list. However, I don't understand some things in this Flask-Login module. @login_manager.user_loader def load_user(userid): #print 'this is executed',userid return user(userid, 'asdf') This code will be called at every request? This is used to load all the details of my user object? For now, I have this code: @app.route('/make

How to use g.user global in flask

怎甘沉沦 提交于 2019-11-26 15:18:16
问题 As I understand the g variable in Flask, it should provide me with a global place to stash data like holding the current user after login. Is this correct? I would like my navigation to display my user's name, once logged in, across the site. My views contain from Flask import g #among other things During login, I assign user = User.query.filter_by(username = form.username.data).first() if validate(user): session['logged_in'] = True g.user = user It doesn't seem I can access g.user. Instead,

Flask-Login raises TypeError: &#39;bool&#39; object is not callable when trying to override is_active property

半世苍凉 提交于 2019-11-26 14:45:02
I want to modify is_active in Flask-Login so that users are not always active. The default always returns True , but I changed it to return the value of the banned column. Based on the docs, is_active should be a property. However, the internal Flask-Login code raises: TypeError: 'bool' object is not callable When trying to use is_active . How do I correctly use is_active to deactivate some users? class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) banned = db.Column(db.Boolean, default=False) @property def is_active(self): return self.banned login_user(user, form