本文整理汇总了Python中flask_security.utils.encrypt_password方法的典型用法代码示例。如果您正苦于以下问题:Python utils.encrypt_password方法的具体用法?Python utils.encrypt_password怎么用?Python utils.encrypt_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_security.utils
的用法示例。
在下文中一共展示了utils.encrypt_password方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def create():
'''Create a new user'''
data = {
'first_name': click.prompt('First name'),
'last_name': click.prompt('Last name'),
'email': click.prompt('Email'),
'password': click.prompt('Password', hide_input=True),
'password_confirm': click.prompt('Confirm Password', hide_input=True),
}
# Until https://github.com/mattupstate/flask-security/issues/672 is fixed
with current_app.test_request_context():
form = RegisterForm(MultiDict(data), meta={'csrf': False})
if form.validate():
data['password'] = encrypt_password(data['password'])
del data['password_confirm']
data['confirmed_at'] = datetime.utcnow()
user = datastore.create_user(**data)
success('User(id={u.id} email={u.email}) created'.format(u=user))
return user
errors = '\n'.join('\n'.join(e) for e in form.errors.values())
exit_with_error('Error creating user', errors)
示例2: user
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def user(self, role_names=None, organization=None):
if role_names is None:
role_names = []
from psi.app.models import User, Role
from flask_security.utils import encrypt_password
user = User()
user.active = True
user.display = self.faker.name()
user.email = self.faker.email()
user.login = self.faker.name()
password = self.faker.password()
user.password = encrypt_password(password)
if organization is None:
user.organization = self.organization()
else:
user.organization = organization
for role_name in role_names:
role = Role.query.filter_by(name=role_name).first()
user.roles.append(role)
return user, password
示例3: a_user
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def a_user(app, session, project_client, name, email,
logged_in, disabled, active):
""" gives us a user who is a member.
"""
from pygameweb.user.models import User, Group
from flask_security.utils import encrypt_password
group = Group(name='members', title='Member')
user = User(name=name,
email=email,
password=encrypt_password('password'),
disabled=disabled,
active=active,
roles=[group])
session.add(user)
session.commit()
# https://flask-login.readthedocs.org/en/latest/#fresh-logins
with project_client.session_transaction() as sess:
sess['user_id'] = user.id
sess['_fresh'] = True
return user
示例4: user
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def user(app, session, wiki_client):
""" gives us a user who is a member.
"""
from pygameweb.user.models import User
from flask_security.utils import encrypt_password
user = User(name='joe',
email='asdf@example.com',
password=encrypt_password('password'))
session.add(user)
session.commit()
# https://flask-login.readthedocs.org/en/latest/#fresh-logins
with wiki_client.session_transaction() as sess:
sess['user_id'] = user.id
sess['_fresh'] = True
return user
示例5: a_user
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def a_user(app, session, news_client, name, email,
logged_in, disabled, active):
""" gives us a user who is a member.
"""
from pygameweb.user.models import User, Group
from flask_security.utils import encrypt_password
group = Group(name='admin', title='Admin')
user = User(name=name,
email=email,
password=encrypt_password('password'),
disabled=disabled,
active=active,
roles=[group])
session.add(user)
session.commit()
# https://flask-login.readthedocs.org/en/latest/#fresh-logins
with news_client.session_transaction() as sess:
sess['user_id'] = user.id
sess['_fresh'] = True
return user
示例6: user
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def user(app, session, comment_client):
""" gives us a user who is a member.
"""
from pygameweb.user.models import User
from flask_security.utils import encrypt_password
user = User(name='joe',
email='asdf@example.com',
password=encrypt_password('password'))
session.add(user)
session.commit()
# https://flask-login.readthedocs.org/en/latest/#fresh-logins
with comment_client.session_transaction() as sess:
sess['user_id'] = user.id
sess['_fresh'] = True
return user
示例7: run
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def run(self, **kwargs):
# handle confirmed
if re.sub(r"\s", "", str(kwargs.pop("confirmed"))).lower() in [
"",
"y",
"yes",
"1",
"active",
]:
kwargs["confirmed_at"] = datetime.datetime.now()
# sanitize active input
ai = re.sub(r"\s", "", str(kwargs["active"]))
kwargs["active"] = ai.lower() in ["", "y", "yes", "1", "active"]
from flask_security.forms import ConfirmRegisterForm
from werkzeug.datastructures import MultiDict
form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False)
if form.validate():
kwargs["password"] = encrypt_password(kwargs["password"])
user_datastore.create_user(**kwargs)
print("User created successfully.")
kwargs["password"] = "****"
pprint(kwargs)
else:
print("Error creating user")
pprint(form.errors)
示例8: password
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def password(email):
user = datastore.get_user(email)
password = click.prompt('Enter new password', hide_input=True)
user.password = encrypt_password(password)
user.save()
示例9: on_model_change
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def on_model_change(self, form, model, is_created):
# If the password field isn't blank...
if len(model.password2):
# ... then encrypt the new password prior to storing it in the database. If the password field is blank,
# the existing password in the database will be retained.
model.password = encrypt_password(model.password2)
示例10: create_defaults
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def create_defaults(self):
from . import Country
from flask_security.utils import encrypt_password
admin_user = User()
admin_user.first_name = "Admin"
admin_user.last_name = "Admin"
admin_user.admin = True
admin_user.email = "admin@code4sa.org"
admin_user.country = Country.query.filter(Country.name == 'South Africa').one()
admin_user.password = encrypt_password('admin')
return [admin_user]
示例11: on_model_change
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def on_model_change(self, form, model, is_created):
if not is_super_admin():
super(UserAdmin, self).on_model_change(form, model, is_created)
# If the password field isn't blank...
if len(model.password2):
# ... then encrypt the new password prior to storing it in the database. If the password field is blank,
# the existing password in the database will be retained.
model.password = encrypt_password(model.password2)
示例12: on_model_change
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def on_model_change(self, form, model, is_created):
if len(model.password2):
model.password = utils.encrypt_password(model.password2)
示例13: create_test_models
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def create_test_models():
user_datastore.create_user(email='test', password=encrypt_password('test'))
user_datastore.create_user(email='test2', password=encrypt_password('test2'))
stuff = SomeStuff(data1=2, data2='toto', user_id=1)
db.session.add(stuff)
stuff = SomeStuff(data1=5, data2='titi', user_id=1)
db.session.add(stuff)
db.session.commit()
示例14: setUp
# 需要导入模块: from flask_security import utils [as 别名]
# 或者: from flask_security.utils import encrypt_password [as 别名]
def setUp(self):
app.config.from_object('config.TestingConfig')
self.client = app.test_client()
db.init_app(app)
with app.app_context():
db.create_all()
user_datastore.create_user(email='test', password=encrypt_password('test'))
db.session.commit()