flask-login

py.test to test flask register, AssertionError: Popped wrong request context

守給你的承諾、 提交于 2019-11-29 16:58:29
问题 I'm using flask to do register and login: from flask.ext.security.views import register, login class Register(Resource): def post(self): return register() class Login(Resource): def post(self): return login() api.add_resource(Login, '/login') api.add_resource(Register, '/register') then I use py.test to test the class: class TestAPI: def test_survey(self, app): client = app.test_client() data = {'email': 'test@test', 'password': 'password'} rv = client.post('/2014-10-17/register', data=json

Azure Flask HTTP Error 500.0 - INTERNAL SERVER ERROR

亡梦爱人 提交于 2019-11-29 12:10:49
I have a simple flask web app hosted on Microsoft Azure which allows users to login, upload files, view uploaded files and logout. Now to handle users more efficiently I decided to use session from flask. here is my sample code '''import statements''' from flask import render_template, request, session '''more import statements''' @app.route('/') def home(): return render_template('login.html') @app.route('/login_user', methods=['GET', 'POST']) def login_user(): username = str(request.form['username']) password = request.form['password'] connection = MongoClient('mongodb://username:password

How to implement login required decorator in Flask

大兔子大兔子 提交于 2019-11-29 09:47:36
问题 I have 2 Flask apps (different projects) that work together . One implements some API which uses tokens for auth. The second one consumes the API and makes a web interface for it. Now I have a login function that sends the username and password to the API, and if correct, gets the auth token in return. Once I have the token, I save it to the session of the user and the user should now be considered as logged in/ autheticated. How can I implement the login_required decorator for such a case.

How do I handle login in flask with multiple blueprints?

雨燕双飞 提交于 2019-11-29 00:08:17
I have multiple blueprints that needs to be integrated into a single app. I'm using flask-login to handle logins. However I'm confused on how to handle the LoginManager() and the .user_loader for my blueprints. This is my current file structure. system/ run.py config.py app/ __init__.py models.py views/ blueprint1.py blueprint2.py static/ templates/ <templates> What's the correct way to implement them? Do I just call them at the __init__.py and import the login manager variable at the blueprints? or Do I need to call them individually in the blueprints? Hopefully I'm able to portray the

Implementing Flask-Login with multiple User Classes

旧城冷巷雨未停 提交于 2019-11-28 17:37:43
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 sure how to tell the app that I want it to login that specific user. Right now, I only have one universal

flask-login can not be used in Blueprint object?

喜夏-厌秋 提交于 2019-11-28 07:47: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.py app = Flask(__name__) app.config.from_object(blog_config) app.register_blueprint(admin) if __name__ =

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

佐手、 提交于 2019-11-28 07:40:58
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=adsabs.harvard.edu; expires=Thu, 25-Apr-2213 16:53:22 GMT; Path=/' % cookie_value, 'WEBSITE_ID=%s;

Azure Flask HTTP Error 500.0 - INTERNAL SERVER ERROR

半腔热情 提交于 2019-11-28 06:21:15
问题 I have a simple flask web app hosted on Microsoft Azure which allows users to login, upload files, view uploaded files and logout. Now to handle users more efficiently I decided to use session from flask. here is my sample code '''import statements''' from flask import render_template, request, session '''more import statements''' @app.route('/') def home(): return render_template('login.html') @app.route('/login_user', methods=['GET', 'POST']) def login_user(): username = str(request.form[

Python Flask: keeping track of user sessions? How to get Session Cookie ID?

强颜欢笑 提交于 2019-11-28 04:35:12
I want to build a simple webapp as part of my learning activity. Webapp is supposed to ask for user to input their email_id if it encounters a first time visitor else it remembers the user through cookie and automatically logs him/her in to carry out the functions. This is my first time with creating a user based web app. I have a blue print in my mind but I am unable to figure out how to implement it. Primarily I am confused with respect to the way of collecting user cookie. I have looked into various tutorials and flask_login but I think what I want to implement is much simpler as compared

Python Flask: keeping track of user sessions? How to get Session Cookie ID?

[亡魂溺海] 提交于 2019-11-27 19:15:59
问题 I want to build a simple webapp as part of my learning activity. Webapp is supposed to ask for user to input their email_id if it encounters a first time visitor else it remembers the user through cookie and automatically logs him/her in to carry out the functions. This is my first time with creating a user based web app. I have a blue print in my mind but I am unable to figure out how to implement it. Primarily I am confused with respect to the way of collecting user cookie. I have looked