flask-security

How to use Flask-Security register view?

淺唱寂寞╮ 提交于 2020-01-01 04:08:06
问题 Has anyone used Flask-Security extension for authentication? How do I get register view to work? http://packages.python.org/Flask-Security/customizing.html I am referring to link above. @app.route('/register', methods=['GET']) def register(): return render_template('security/register_user.html') I don't want to extend the default class, I just want to wrap the default registration view in my site layout so I did this. {% extends "layout.html" %} {% block title %}upload{% endblock %} {% block

Flask-security - how to get form data in user_registered signal?

岁酱吖の 提交于 2019-12-25 03:47:26
问题 I started here, and now I have this code: @user_registered.connect_via(app) def user_registered_sighandler(sender, **extra): sender.logger.debug("logger-user_registered_sighandler:", extra) user = extra.get('user') print dir(sender) role = user_datastore.find_or_create_role('farmer') user_datastore.add_role_to_user(user,role) db.session.commit() print "print-user_registered_sighandler:", extra Now I'm interested in getting data from the register form. I need to do this because inside the form

Flask-Security user_registered Signal Not Received in Python 3.3, but works in 2.7

眉间皱痕 提交于 2019-12-23 07:04:54
问题 I'm trying to use the user_registered signal in order to set up default roles for users when they register using flask-security as in the following link: Setting Default Role in Flask Security In my searches I can see that there was a bug that was already addressed for this in flask-security: Not getting signal from flask-security, Fix - user_registered signal problem I've tried the following to prove if the signal is received by the handler without any luck: @user_registered.connect_via(app)

python import conflict with flask-security

一笑奈何 提交于 2019-12-23 05:29:16
问题 I run into this "import conflict" fairly often I'm trying to find the most Python way to solve it. My app's __init__ instantiates db and over in my user.models file, db is referenced extensively. However, to use Flask-Security, I need to initialize the user_datastore which requires both my db and my User model. These files can't import each other. I need User in the __init__ method but I also need the db over in the User model. I've tried all sorts of arrangements (short of moving my many

Setting a default role in flask-security

 ̄綄美尐妖づ 提交于 2019-12-21 06:20:42
问题 I am trying to set a default role when a user registers with my site, currently no roles are set when the user registers. I have created the roles I need, so I just need to define it somehow. Not sure how though. The code I have is pretty much copy paste from the quick start guide. Anyway, here it is: # Define models roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db

Hiding fields in Flask-Admin depending on logged in user?

一个人想着一个人 提交于 2019-12-19 04:21:44
问题 I have Users and Roles in my Flask app thanks to Flask-Security. For some roles I would like to hide certain fields in the forms created by Flask-Admin. I know about customizing ModelViews with eg. form_create_rules = ('title', 'file') but while instantiating a ModelView there isn't access to the current request so current_user.has_role(USER_ROLE) can't be called. Is there any other way to achieve this? 回答1: One way of achieving this is to create multiple view classes and register these view

How do you implement token authentication in Flask?

北战南征 提交于 2019-12-18 10:24:41
问题 I'm trying to allow users to login to my Flask app using their accounts from a separate web service. I can contact the api of this web service and receive a security token. How do I use this token to authenticate users so that they have access to restricted views? I don't need to save users into my own database. I only want to authenticate them for a session. I believe this can be done using Flask-Security and the @auth_token_required decorator but the documentation is not very detailed and I

flask-security encrypt_password('mypassword') varies every time when i reload the page

核能气质少年 提交于 2019-12-18 09:37:22
问题 I've already configured SECURITY_PASSWORD_SALT and use "bcrypt". But every time i reload the page print encrypt_password('mypassword') will print different values, so i can't verify user input password via verify_password(form.password.data, user.password) . But I can login from flask-security built-in login view Here is code to demonstrate the strange behavior of encrypt_password : from flask import Flask, render_template from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.security

StatementError: SQLite Date type only accepts Python date objects as input

守給你的承諾、 提交于 2019-12-14 04:05:48
问题 I am using Flask-Security, the code seems fine, but when inserting a data from register view it gives the bellow error. Since I made SECURITY_TRACKABLE = True I added some extra fields in my models and the problem might be there :( sqlalchemy.exc.StatementError StatementError: SQLite Date type only accepts Python date objects as input. (original cause: TypeError: SQLite Date type only accepts Python date objects as input.) 'INSERT INTO user (name, surname, email, password, birth_date, active,

SECURITY_PASSWORD_SALT must not be None - flask security

不想你离开。 提交于 2019-12-13 14:12:44
问题 This question is related to: Unique Salt per User using Flask-Security, but I'm more concerned with removing this error message. The linked question established that flask-security uses per-user salts, which is good since a global salt is pointless. So my question is what's the point of this configuration variable, and what should I set it to to resolve this error? Does it matter what I set it to? I don't think I need a global salt since flask-security uses passlib which takes care of salts