flask-login

网站后端.Flask.实战-社交博客开发-认证实现?

旧时模样 提交于 2020-03-12 19:50:38
1.flask-login扩展负责管理已登录用户的会话 2.Werkzeug负责计算密码散列值并进行核对 3.itsdangerous生成并核对指定时间有效的加密安全token 说明:要实现对用户跟踪,必须让程序在用户登录后知道当前用户的身份,最常用的认证方式通过电子邮件/用户名和一个密码,可使用flask-login+Werkzeug+itsdangerous实现一个完整的认证系统 来源: oschina 链接: https://my.oschina.net/u/2612057/blog/700793

网站后端.Flask.实战-社交博客开发-flask-login认证用户?

别来无恙 提交于 2020-03-12 19:42:17
用户模型 1.用户登录后认证状态需要被记录,这样浏览不同的页面才能记住这个状态,flask-login专门用来管理用户认证系统中的认证状态,且不依赖特定的认证机制 2.用户模型必须实现is_authenticated/is_active/is_anonymous/get_id四个方法才可以集成扩展,flask-login为我们提供了UserMixin类,包含了这些方法的默认实现,只需用户模型继承此类即可 is_authenticated() 如果用户已登录,必须返回True,否则返回False is_active() 如果允许用户登录,必须返回True,否则返回false,如果禁用账户,可返回False is_anonymous() 对普通用户必须返回False get_id() 必须返回用户对象的唯一标识符,常为主键id字段,使用Unicode编码字符串 FlaskWeb/app/models.py #!/usr/bin/env python # -*- coding: utf-8 -*- """ # # Authors: limanman # OsChina: http://my.oschina.net/pydevops/ # Purpose: # """ from . import db from flask_login import UserMixin from

What's the point of the “is_authenticated” method used in Flask-Login?

十年热恋 提交于 2020-01-29 02:51:30
问题 I'm working through the Flask Mega-Tutorial right now and I've come across this bit of code: class User(db.Model): id = db.Column(db.Integer, primary_key = True) nickname = db.Column(db.String(64), unique = True) email = db.Column(db.String(120), unique = True) role = db.Column(db.SmallInteger, default = ROLE_USER) posts = db.relationship('Post', backref = 'author', lazy = 'dynamic') def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False

ImportError: No module named flask.ext.login

你离开我真会死。 提交于 2020-01-22 10:16:28
问题 I have a problem with flask_login module. i have installed flask_login module successfully. Also from the command prompt i can run this script easily with no error: Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from flask.ext.login import LoginManager But when I am running this script: from flask import Flask from flask.ext.login import LoginManager app = Flask(__name__) @app.route("

Flask: login session times out too soon

无人久伴 提交于 2020-01-14 09:16:27
问题 While editing a record, if there is a long wait of let say a few minutes (getting coffee) and then coming back to press the save (POST), I get redirected to the main page to login instead and the data is lost. It seems the flask-login session expires too fast. I did some research and came across this. from flask import session, app session.permanent = True Is this the proper way to go? But even when I try this I get this exception: File "/Users/kave/workspace/F11A/src/application/__init__.py"

Admin(only) registration of users, Flask-Security

家住魔仙堡 提交于 2020-01-13 13:31:13
问题 I'm currently building a login for a webapp using Flask-Security (which includes Flask-WTForms, Flask-SQLalchemy and Flask-Login). I've been able to fairly painlessly set up the majority of my login flow, including forgotten password; however I want to make it so that the only way users can be registered is through a page only accessible to the admins. I've managed to configure Roles (Admin, User) and set up the following view: @app.route('/adminregister') @roles_accepted('admin') def

How do I call one Flask view from another one?

僤鯓⒐⒋嵵緔 提交于 2020-01-12 04:52:11
问题 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

Flask-Login breaks when my decorator accepts parameters

丶灬走出姿态 提交于 2020-01-06 04:23:48
问题 Thanks to what I learned from this question, I've been able to make a Flask-Login process with a endpoint like this: @app.route('/top_secret') @authorize @login_required def top_secret(): return render_template("top_secret.html") and (for now) a completely pass-through "authorize" decorator: from functools import wraps def authorize(func): @wraps(func) def newfunc(*args, **kwargs): return func(*args, **kwargs) return newfunc The @wraps(func) call allows Flask to find the endpoint that it's

How to manually install Flask extensions?

笑着哭i 提交于 2020-01-01 12:01:32
问题 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

Flask Login and Principal - current_user is Anonymous even though I'm logged in

那年仲夏 提交于 2020-01-01 04:52:06
问题 I'm using Flask Login and Principal for identity and role management. My needs are described straight out of the docs. My code is here: @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # Add the UserNeed to the identity if hasattr(current_user, 'get_id'): print 'current_user ' + str(current_user.get_id()) identity.provides.add(UserNeed(current_user.get_id)) # Assuming the User model has a list of roles,