flask-login

Flask-Login and Heroku issues

旧巷老猫 提交于 2019-12-01 05:58:08
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_DATABASE_HOST' in os.environ else config.MYSQL_DATABASE_HOST app.config['MYSQL_DATABASE_PORT'] = os.environ

Accessing Flask Session variables from Flask Navigation for dynamic navigation menu

走远了吗. 提交于 2019-12-01 05:42:03
问题 I want to have a dynamic navigation menu that shows "Login" if the user is not currently logged on, and "Logout" if the user is logged in. I'm using code similar to the following: import flask import flask_nav import flask_nav.elements as fne frontend = flask.Blueprint('frontend', __name__) application = flask.Flask(__name__) mySess = flask_session.Session() flask_appconfig.AppConfig(application) flask_bootstrap.Bootstrap(application) application.register_blueprint(frontend) application

Flask-login with static user always yielding 401- Unauthorized

孤者浪人 提交于 2019-11-30 20:35:22
I am trying to build a super simple web app for my own use. I'll be the only user, so I don't feel the need to involve a database for user management. I'm trying to use flask-login, but even though my call to login_user succeeds, I'm still met with a 401-Unauthorized page after the redirect to a page with @login_required . Here is the entirety of my app: from flask import Flask, render_template, request, flash, redirect, url_for from flask.ext.login import LoginManager, login_user, logout_user, current_user, login_required, UserMixin app = Flask(__name__, static_url_path="") app.secret_key = "

Flask permanent session: where to define them?

牧云@^-^@ 提交于 2019-11-30 17:16:23
By default, Flask uses volatile sessions, which means the session cookie is set to expire when browser closes. In order to use permanent sessions, which will use a cookie with a defined expiration date, one should set session.permanent = True , as is mentioned in this question. , and the expiration date will be set based on config['PERMANENT_SESSION_LIFETIME'] . I am surprised that session lifetime is defined in config file, yet it is not possible to request the use of permanent sessions through configuration, such as a config['USE_PERMANENT_SESSION'] = True . But so be it. My question is: if

Flask permanent session: where to define them?

大城市里の小女人 提交于 2019-11-30 16:36:55
问题 By default, Flask uses volatile sessions, which means the session cookie is set to expire when browser closes. In order to use permanent sessions, which will use a cookie with a defined expiration date, one should set session.permanent = True , as is mentioned in this question., and the expiration date will be set based on config['PERMANENT_SESSION_LIFETIME'] . I am surprised that session lifetime is defined in config file, yet it is not possible to request the use of permanent sessions

Testing Flask login and authentication?

强颜欢笑 提交于 2019-11-30 12:04:50
问题 I'm developing a Flask application and using Flask-security for user authentication (which in turn uses Flask-login underneath). I have a route which requires authentication, /user . I'm trying to write a unit test which tests that, for an authenticated user, this returns the appropriate response. In my unittest I'm creating a user and logging as that user like so: from unittest import TestCase from app import app, db from models import User from flask_security.utils import login_user class

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

与世无争的帅哥 提交于 2019-11-30 11:28:36
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.dumps(data)) ... when I ran the test, the error occurred as follow: AssertionError: Popped wrong request

How to implement login required decorator in Flask

给你一囗甜甜゛ 提交于 2019-11-30 07:21:20
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. Here is my login function - def login(self): response = make_request(BASE_URL + 'login/', clean_data

How do I handle login in flask with multiple blueprints?

ぃ、小莉子 提交于 2019-11-30 07:00:59
问题 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

Flask-login with static user always yielding 401- Unauthorized

喜欢而已 提交于 2019-11-30 03:55:44
问题 I am trying to build a super simple web app for my own use. I'll be the only user, so I don't feel the need to involve a database for user management. I'm trying to use flask-login, but even though my call to login_user succeeds, I'm still met with a 401-Unauthorized page after the redirect to a page with @login_required . Here is the entirety of my app: from flask import Flask, render_template, request, flash, redirect, url_for from flask.ext.login import LoginManager, login_user, logout