flask-login

Flask-Login, Session Management and AJAX

痞子三分冷 提交于 2021-02-20 00:13:10
问题 I'm having trouble getting an AJAX call to work with the Flask-Login current_user object and the @login_required decorator. I believe it has something to do with the session not being passed. The goal is for a user to click on a link that makes an AJAX call to a route URL that will provide a SSO session ID through a SOAP service. The SOAP service requires an emp_id to be passed which can be accessed through the current_user.emp_id attribute. I initially attempted the AJAX call without the

How to mock `current_user` in flask templates?

女生的网名这么多〃 提交于 2021-02-18 11:36:54
问题 I want to mock flask-login 's current_user under the template rendering. This function return the current logged user. Right now I'm mocking the AnnonymousUserMixin from flask-login which is returned by default if the user is not authenticated. But this leads to all kind of juggles. If I could simply mock current_user I would be able to create a Mocked object for it to return. Here a sample of what I'm using today: import unnittest from flask_login.mixins import AnonymousUserMixin class

AttributeError: Object has no attribute 'user_loader'

丶灬走出姿态 提交于 2021-02-11 14:40:56
问题 I'm programming a Website with Authentification while using the Flask Framework. I've tried every solution that i found on the internet but nothing worked for me. My first idea was, that the Project Structure was corrupt. e.g. missing imports from other files. But thats not the problem i think. My models.py File: from flask_login import UserMixin, LoginManager from flaskapp import db, login_manager @login_manager.user_loader def get_user(user): try: return get_id(user) except: return None

How can I get information from 2 separate tables with a single request in Flask?

折月煮酒 提交于 2021-02-08 11:26:30
问题 class posts(db.Model): __tablename__ = "posts" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) postName = db.Column(db.String(100)) postDescription = db.Column(db.String(500)) postLike = db.Column(db.Integer) class postComment(db.Model): __tablename__ = "postComment" id = db.Column(db.Integer, primary_key=True) postID = db.Column(db.Integer) senderName = db.Column(db.String(20)) commentPost = db.Column(db.String(300)) class PostsSchema(ma.Schema): class Meta:

Flask: How To Prevent Replay Attacks

做~自己de王妃 提交于 2021-02-08 07:57:59
问题 I'm trying to implement a logic in my Flask application to prevent reply attacks. Regarding to the question asked here, My idea is to set the current session lifetime when user logs out from the system. In general, it is suggested to set the session lifetime this way: @app.before_request def before_request(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=10) However, I want to set my current session life time when user logs out from the system. Something like the

Flask: How To Prevent Replay Attacks

送分小仙女□ 提交于 2021-02-08 07:57:18
问题 I'm trying to implement a logic in my Flask application to prevent reply attacks. Regarding to the question asked here, My idea is to set the current session lifetime when user logs out from the system. In general, it is suggested to set the session lifetime this way: @app.before_request def before_request(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=10) However, I want to set my current session life time when user logs out from the system. Something like the

flask-login invalidates session randomly after authentication

左心房为你撑大大i 提交于 2021-02-08 03:38:48
问题 I'm using flask-login https://flask-login.readthedocs.io/en/latest for session management. The user first login in (login.html) the application and go to home.html. However, after the user has authenticated and click different links, it will kick out the session and go back to login page. This happens very randomly and I'm not sure what went wrong? It is using apache. It seems okay with localhost but having this issue in apache. Are there specific apache configurations need to pay attention?

flask-login invalidates session randomly after authentication

假如想象 提交于 2021-02-08 03:38:32
问题 I'm using flask-login https://flask-login.readthedocs.io/en/latest for session management. The user first login in (login.html) the application and go to home.html. However, after the user has authenticated and click different links, it will kick out the session and go back to login page. This happens very randomly and I'm not sure what went wrong? It is using apache. It seems okay with localhost but having this issue in apache. Are there specific apache configurations need to pay attention?

Overriding Flask-User/Flask-Login's default templates

馋奶兔 提交于 2021-02-07 13:31:47
问题 I have found a similar question here, but the answer does not seem to work for me. I use Flask User (which extends Flask Login, I believe) and for the most part it works very well. I have built my own completely fresh templates for sign in and registration, rather than using their provided ones. Following the documentation, I have placed these templates at templates/flask_user/login.html , templates/flask_user/register.html and so on. I have also set USER_UNAUTHENTICATED_ENDPOINT = "login"

[Flask]-Customising Flask-user login

非 Y 不嫁゛ 提交于 2021-02-05 08:55:49
问题 Have been working on Flask-user for the user management system, But I couldn't see a way to customise the login page and registration page. I installed flask-user using pip pip install flask-user Any help would be appreciated 回答1: In templates folder, create a new folder named flask_user and you can copy the login.html and register.html pages used by flask-user to the newly created folder. Then you can modify them as per your requirements. These files will override the pages used by flask