flask-login

Caching Flask-Login user_loader

笑着哭i 提交于 2019-12-10 21:06:19
问题 I had this. @login_manager.user_loader def load_user(id=None): return User.query.get(id) It was working fine until I introduced Flask-Principal. @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # return if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) # Assuming the User model has a list of roles, update the # identity with the roles that the user provides if hasattr(current

Flask-Admin can_create = True only for a given user

白昼怎懂夜的黑 提交于 2019-12-10 18:52:53
问题 I am using Flask-Admin in conjunction with Flask-Login and mongoengine. I wish to customize views depending on users. Hereafter, an example with can_create , that allows model creation. class MyModelView(ModelView): column_exclude_list = ['password'] def is_accessible(self): if (login.current_user.login != 'admin'): can_create=False return login.current_user.is_authenticated() Such a piece of code has no effect: all users can still create, no difference between admin and non-admin users.

Session is shared between two Flask apps on localhost

为君一笑 提交于 2019-12-10 18:17:16
问题 So, I have two Flask apps running on localhost, one on the port 5001, and the other one on the port 5003, and apparently both are using the same session. If I log in on one app, it logs out on the other. And for example, recently, if I logged in using my email on one app, it would also log in my account on the other app, since I have users using that email on both apps, and I was using the email as an user identifier, but that stop happening when I used another id for the users. I'm using

Using flask_login session with jinja2 templates

冷暖自知 提交于 2019-12-10 01:10:11
问题 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? 回答1: 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

flask and flask_login - organizing code

旧街凉风 提交于 2019-12-08 07:19:01
问题 I am currently coding up a simple web application using flask and flask_login, and got stuck due to a code organisation problem. import flask import flask_login app = flask.Flask(__name__) login_manager = flask_login.LoginManager() login_manager.init_app(app) The above works. The problem arises because I want to separate authentication related code from the main flask application code. In other words, I want my_auth.py that imports flask_login and initializes the login_manager , and I want

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

旧时模样 提交于 2019-12-07 22:56:39
问题 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

Flask-SQLAlchemy set relationship default value

青春壹個敷衍的年華 提交于 2019-12-07 21:35:56
问题 I have an app making by Flask and for database management I using Flask-admin and Flask-SQLAlchemy. And in my app there has three role, which is: admin , school parent here is the snipet of code on my table: roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id')) ) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True)

flask-login session gets destroyed on every apache restart

半世苍凉 提交于 2019-12-07 20:56:12
问题 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) 回答1: If anyone is suffering with this problem, you have to write the

Error with flask-login

一曲冷凌霜 提交于 2019-12-07 11:36:34
问题 I have difficulty in using the Flask-Login framework for authentication. I have looked through the documentation as thoroughly as possible but apparently I am missing something obvious. class User(): def __init__(self, userid=None, username=None, password=None): self.userid = userid self.username = username self.password = password def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.userid) def _

Flask-security and Bootstrap

拈花ヽ惹草 提交于 2019-12-07 07:47:50
问题 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