flask-login

Why isn't my current_user authenticated in flask-login?

青春壹個敷衍的年華 提交于 2019-12-07 06:27:22
问题 My goal is to make my home view ( / ) a login page. Once the user logs in, a different page is render depending on its role. When I login ( /auth ), I see that the username and password are correctly entered. It then attempts to render / , where it tells me that my user is not authenticated and renders /login . Here are the views that describe this: Views @app.route("/login") def login(): return flask.render_template('login.html') @app.route("/", methods=["GET"]) def home(): if current_user

How to track anonymous users with Flask

佐手、 提交于 2019-12-07 03:43:42
问题 My app implements a shopping cart in which anonymous users can fill their cart with products. User Login is required only before payment. How can this be implemented? The main challenge is that flask must keep track of the user (even if anonymous) and their orders. My current approach is to leverage the AnonymousUserMixin object that is assigned to current_user . The assumption is that current_user will not change throughout the session. However, I noticed that a new AnonymousUserMixin object

flask-login session gets destroyed on every apache restart

ε祈祈猫儿з 提交于 2019-12-06 09:38:25
I am using flask-login https://github.com/maxcountryman/flask-login and the field remember in login_user does not seem to work. The session gets destroyed after every restart of the apache ..ideally the remember field should take care of this.. even the session values gets destroyed. this is really frustrating... anyone knowing the solution please ping .. thanks i am using login_user as login_user(user, remember=True) If anyone is suffering with this problem, you have to write the function user_loader properly. @login_manager.user_loader def load_user(id): return "get the user properly and

Flask Testing self.app_context.push() not working?

人盡茶涼 提交于 2019-12-06 06:52:34
I am currently testing my flask application. I have the following test cases: import unittest from flask import get_flashed_messages from portal.factory import create_app class AuthTestConfig(object): SQLALCHEMY_TRACK_MODIFICATIONS = False TESTING = True LOGIN_DISABLED = False SERVER_NAME = 'Testing' SECRET_KEY = 'secret' DEBUG = True SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' class DebugTestCase(unittest.TestCase): def setUp(self): self.app = create_app(AuthTestConfig) self.client = self.app.test_client(use_cookies=True) def test_with(self): with self.client: r = self.client.get('/user

How is Flask-Login's request_loader related to user_loader?

白昼怎懂夜的黑 提交于 2019-12-05 22:47:13
问题 I apologize in advance for asking a rather cryptic question. However, I did not understand it despite going through a lot of material. It would be great if you could shed some light on this. What is the purpose of a request_loader in flask-login? How does it interact with the user_loader decorator? If I am using a token based authentication system (I am planning on sending the token to my angularJS front end, storing the token there and sending that token in the authorization-token header),

Does the order of decorators matter on a Flask view?

大兔子大兔子 提交于 2019-12-05 17:18:22
问题 I'm using the login_required decorator and another decorator which paginates output data. Is it important which one comes first? 回答1: While there probably won't be any problem in this case no matter what the order, you probably want login_required to execute first so that you don't make queries and paginate results that will just get thrown away. Decorators wrap the original function bottom to top, so when the function is called the wrapper added by each decorator executes top to bottom.

Flask-login: remember me not working if login_manager's session_protection is set to “strong”

我们两清 提交于 2019-12-05 10:55:45
i am using flask-login to integrate session management in my flask app. But the remember me functionality doesn't work if i set the session_protection to strong , however, it works absolutely fine if it's set to basic . user_loader: @login_manager.user_loader def load_user(email): user = get_user_with_email(email) if user: return User(user.id, user.email, user.role_id, user.createtime, user.updatetime) to fetch user from the database: from psycopg2.extras import NamedTupleCursor def get_user_with_email(email): cursor = get_db().cursor(cursor_factory=NamedTupleCursor) cursor.execute('SELECT *

Flask-security and Bootstrap

最后都变了- 提交于 2019-12-05 08:55:53
How can I style my Flask-security login site with Bootstrap? The html form looks like this: <form action="{{ url_for_security('login') }}" method="POST" name="login_form"> {{ login_user_form.hidden_tag() }} {{ render_field_with_errors(login_user_form.email) }} {{ render_field_with_errors(login_user_form.password) }} {{ render_field_with_errors(login_user_form.remember) }} {{ render_field(login_user_form.next) }} {{ render_field(login_user_form.submit) }} </form> Bootstrap is implemented, but I dont know how to edit the fields and the submit button.. The render_field_* functions accepts a class

Why isn't my current_user authenticated in flask-login?

元气小坏坏 提交于 2019-12-05 08:29:09
My goal is to make my home view ( / ) a login page. Once the user logs in, a different page is render depending on its role. When I login ( /auth ), I see that the username and password are correctly entered. It then attempts to render / , where it tells me that my user is not authenticated and renders /login . Here are the views that describe this: Views @app.route("/login") def login(): return flask.render_template('login.html') @app.route("/", methods=["GET"]) def home(): if current_user.is_authenticated: if current_user.is_admin(): return flask.render_template('admin_index.html') return

Using flask_login session with jinja2 templates

一世执手 提交于 2019-12-04 22:29:48
I have simple jinja2 template with registration/login links, I should hide them when user logged in, I also use flask_login module for this stuff. Question is: How should I identify is user logged in in jinja2 templates? Blender Flask-Login adds the current_user variable to your templates: {% if current_user.is_authenticated %} ... {% else %} ... {% endif %} They mention this briefly in the documentation . 来源: https://stackoverflow.com/questions/18361151/using-flask-login-session-with-jinja2-templates