flask-login

Flask-login not redirecting to previous page

主宰稳场 提交于 2020-01-01 03:09:16
问题 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

flask and flask_login - avoid importing flask_login from main code

♀尐吖头ヾ 提交于 2019-12-25 09:04:53
问题 I am currently coding up a simple web application using flask and flask_login. This is main.py : import flask import flask_login app = flask.Flask(__name__) login_manager = flask_login.LoginManager() login_manager.init_app(app) @app.route('/') @flask_login.login_required def index(): return "Hello World!" The above code 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

How to login to Flask App when using Locust

蹲街弑〆低调 提交于 2019-12-24 23:16:20
问题 First time using Locust. I have a Flask App that requires user to login to access most routes. I cant get Locust to successfully login to my Flask App. Here is my Locust.py file: from locust import HttpLocust, TaskSet, task import re class UserBehavior(TaskSet): def on_start(self): """ on_start is called when a Locust start before any task is scheduled """ self.client.verify = False self.get_token() self.login() def on_stop(self): """ on_stop is called when the TaskSet is stopping """ self

How to use login_required with a class, in Flask?

余生长醉 提交于 2019-12-24 08:19:01
问题 from flask_login import login_required from flask_restful import Resource @login required class MyClass(Resource): #... In the main file I call the class's methods like: api.add_resource(MyClass, '/some_url', methods=['GET', 'PUT', 'POST', 'DELETE']) I think I am using @login_required the wrong way here, since I get the error AttributeError: 'function' object has no attribute 'as_view' So I am assuiming that @login_required can only be used with functions. Is there a way to incorporate it

Getting 'str' object has no attribute 'is_authenticated' in Flask using Flask-Login

◇◆丶佛笑我妖孽 提交于 2019-12-24 02:06:39
问题 I am trying to set up login for Flask using Flask-Login. I have a CouchDB for users; the customer documents have an object called "user". class User(UserMixin): def __init__ (self, user) : self.name = user['name'] self.password = user['password'] self.id= user['id'] def is_active(self): return True def is_authenticated(self): return True def is_anonymous(self): return False def get_id(self): return str(self.id) def check_user(id): for row in db.query(map_auth): if row.value['id'] == id:

flask-login user is set to anonymous after login

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 21:28:45
问题 im new to flask and flask-login and ive been struggling with this for days. Im trying to log a user in like this: from creds import auth_username, auth_password, pgsql_dbuser, pgsql_dbpassword, pgsql_db1name from flask import Flask, render_template, request, Response, redirect, url_for from flask.ext.bcrypt import Bcrypt from flask.ext.login import LoginManager, login_required, login_user, current_user, logout_user import logging import psycopg2 import uuid import datetime app = Flask(__name_

Get current user id in Flask

巧了我就是萌 提交于 2019-12-23 16:26:40
问题 I'm quite new to Python (and, to be honest, programming in general). I'm currently working on a kind of to-do list, where I need it to put to-do items into appropriate course (it's all related to educational stuff). So, the problem is quite straight-forward. I have this as a Flask-driven route: @app.route('/add_course', methods=('GET', 'POST')) @login_required def course(): form = forms.CourseForm() if form.validate_on_submit(): models.Course.create(teacher=g.user._get_current_object(), name

Flask-Login: How to force Firefox/Chrome to remove session cookie when tab is closed?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 09:57:02
问题 I have been trying to learn Flask, and along the way the Flask-Login extension. I can make basic authentication work as expected. The issue that has me stumped involves the "Show my windows and tabs from last time" setting in Firefox and the "Continue where I left off" setting in Chrome. All the research I have done on this site and elsewhere indicates that these settings should only work for open tabs. So if you are authenticated and then close the tab, and then close the browser, the

Flask: How to prevent to go to login page when already logged in?

我与影子孤独终老i 提交于 2019-12-23 05:36:10
问题 I have been doing the Flask Web Development Book by Miguel Grinberg, and just finished up with the authorization blueprint. Though, I am having an issue that if I am already logged in, I can still put the url of the login page and go there. How can I prevent this in Flask? While using Django, I came up with django-braces library which helps to do this, any such alternative available in Flask? 回答1: Redirect users who are logged in navigating to the login page. To check if they are already

Flask-login: remember me not working if login_manager's session_protection is set to “strong”

亡梦爱人 提交于 2019-12-22 06:22:22
问题 i am using flask-login to integrate session management in my flask app. But the remember me functionality doesn't work if i set the session_protection to strong , however, it works absolutely fine if it's set to basic . user_loader: @login_manager.user_loader def load_user(email): user = get_user_with_email(email) if user: return User(user.id, user.email, user.role_id, user.createtime, user.updatetime) to fetch user from the database: from psycopg2.extras import NamedTupleCursor def get_user