以编程方式在 web2py 中的 auth_user table 中插入一行
Programmatically insert a row in auth_user table in web2py
如何以编程方式将包含电子邮件和散列密码的行插入 web2py 中的 auth_user?类似于下面的烧瓶兼容代码。
def find_or_create_user(username, email, password, role=None):
""" Find existing user or create new user """
user = User.query.filter(User.email == email).first()
if not user:
user = User(username=username,
email=email,
password=current_app.user_manager.hash_password(password),
is_enabled=True,
confirmed_at=datetime.datetime.utcnow())
if role:
user.roles.append(role)
db.session.add(user)
return user
material行是:
db.auth_user.validate_and_insert(email=email, password=password...)
如何以编程方式将包含电子邮件和散列密码的行插入 web2py 中的 auth_user?类似于下面的烧瓶兼容代码。
def find_or_create_user(username, email, password, role=None):
""" Find existing user or create new user """
user = User.query.filter(User.email == email).first()
if not user:
user = User(username=username,
email=email,
password=current_app.user_manager.hash_password(password),
is_enabled=True,
confirmed_at=datetime.datetime.utcnow())
if role:
user.roles.append(role)
db.session.add(user)
return user
material行是:
db.auth_user.validate_and_insert(email=email, password=password...)