flask-login

Disabling @login_required while unit-testing flask with flask-login

送分小仙女□ 提交于 2019-12-04 20:31:53
问题 I am unit testing my flask app which uses the flask-login extension. I am setting up all my tests like this using webtest: class TestCase(unittest.TestCase): def setUp(self): app.config['TESTING'] = True self.client = webtest.TestApp(app) But when I try to visit urls through self.client.get() which are decorated with @login_required, I get a 401 error with a message that I am not authorized to access the url. According to the documentation https://flask-login.readthedocs.org/en/latest/

Users appear to be logged in as another user

女生的网名这么多〃 提交于 2019-12-04 14:09:36
I'm using Flask-Security to manage users, and I'm getting reports that users are logged-in successfully as themselves, but randomly when they load a page, it will show them logged as someone completely different. I'm not sure where I'm going wrong. What are possible ways this could happen? I user a UserService to do some simple user management. I instantiate a user service before every request and pass in current_user. @app.before_request def load_request_services(): g.user_service = UserService(user_datastore, application_service, email_service, ORGS, current_user) Then, I get the current

How to manually install Flask extensions?

和自甴很熟 提交于 2019-12-04 10:58:07
I have a Flask project which I've put the flask module (version 0.9) directly beside my app.py file. I've done this so that I can bundle everything into a version control repository that won't require anyone else using it to install additional Python modules. I want to use flask-login so I've tried to manually install it by downloading the latest version and putting the flask_login.py file in my "local" flask/ext/ directory. However, while I can import flask and import flask.ext , I am unable to import flask.ext.login with Python throwing ImportError: No module named flask.ext.login . import

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

ぃ、小莉子 提交于 2019-12-04 04:07:14
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), will I need a request_loader or will a user_loader (where I check the auth header and see if the user

Flask-Login and Heroku issues

萝らか妹 提交于 2019-12-04 01:32:46
问题 I have a sample web application (flask with flask-login running on heroku) at this URL: http://twittaclone.herokuapp.com. When I run it on my localhost the login functionality works fine. When I push to heroku it freaks out and does not allow users to login (it does allow user registration). Database modifications are being made. Why would flask login not work on heroku? app = Flask(__name__) mysql = MySQL() app.config['MYSQL_DATABASE_HOST'] = os.environ['MYSQL_DATABASE_HOST'] if 'MYSQL

Disabling @login_required while unit-testing flask with flask-login

二次信任 提交于 2019-12-03 12:55:53
I am unit testing my flask app which uses the flask-login extension. I am setting up all my tests like this using webtest: class TestCase(unittest.TestCase): def setUp(self): app.config['TESTING'] = True self.client = webtest.TestApp(app) But when I try to visit urls through self.client.get() which are decorated with @login_required, I get a 401 error with a message that I am not authorized to access the url. According to the documentation https://flask-login.readthedocs.org/en/latest/#protecting-views and this discussion , setting the config value of 'TESTING' to True should disable the login

Flask Login: TypeError: decoding Unicode is not supported

不问归期 提交于 2019-12-03 12:26:59
I am running flask, pymongo and flask-login as a stack. My flask app is running fine locally, but once I deploy it with uwsgi on nginx, I get a strange unicode error from flask_login extension. In short: TypeError: decoding Unicode is not supported Traceback: [pid: 21753|app: 0|req: 5/5] 84.207.253.34 () {38 vars in 600 bytes} [Thu Jun 13 16:51:08 2013] GET / => generated 0 bytes in 4 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0) Traceback (most recent call last): File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__ return

Flask-login AttributeError: 'User' object has no attribute 'is_active'

巧了我就是萌 提交于 2019-12-03 10:19:51
问题 I have a problem with flask-login. After filling login form and clicking 'Submit' i'm get this error: Flask-login AttributeError: 'User' object has no attribute 'is_active' Some test users are created. And no problems with login template Traceback: Traceback (most recent call last): File "C:\flask_prj\project\venv\lib\site-packages\flask\app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "C:\flask_prj\project\venv\lib\site-packages\flask\app.py", line 1820, in

How do I call one Flask view from another one?

拥有回忆 提交于 2019-12-03 06:36:19
I have a JSON API in one blueprint module, and a web frontend in another one. I would like to shave off a few AJAX requests the client JS code would have to make by embedding some of the JSON it'll need in the frontend view template, before sending it to the client, like in this gist I found . How do I call one Flask view from another Flask view? I could have called the view function directly, but request would correspond to the “outer” request, and this confuses the called API function. I've tried using test_request_context and it almost works but I can't figure out how to keep the

Flask-login not redirecting to previous page

て烟熏妆下的殇ゞ 提交于 2019-12-03 06:27:46
I have seen quite a few questions with this in mind, but haven't been able to address my issue. I have a Flask app with flask-login for session management. And, when I try to view a page without logging in, I get redirected to a link in form of /login/?next=%2Fsettings%2F The issue is, as far as I could have it understand, that the "next" argument holds the part of the site I actually need, but when submitting a request to a login form, it is done via POST , so this argument is no longer available for me to redirect it to. I tried using Request.path from Request (and url) but both just return