本文整理汇总了Python中model.User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: syncdb
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def syncdb():
from lib.util import find_subclasses
from model import db, User, Distribution, Category, Page
models = find_subclasses(db.Model)
for model in models:
if model.table_exists():
model.drop_table()
model.create_table()
logging.info('created table:%s' % model._meta.db_table)
Distribution.create(name = '免费配送', price = 0)
Distribution.create(name = '上门自提', price = 0)
Category.create(name = '积分商品', slug = 'credit', order = 1)
Category.create(name = '搭配购买', slug = 'acc', order = 2)
Category.create(name = '慕斯蛋糕', slug = 'mousse', order = 3)
Category.create(name = '巧克力蛋糕', slug = 'chocolate', order = 4)
Category.create(name = '乳酪蛋糕', slug = 'cheese', order = 5)
Category.create(name = '乳脂奶油蛋糕', slug = 'creambutter', order = 6)
Category.create(name = '冰淇淋蛋糕', slug = 'icecream', order = 7)
Page.create(name = '吉米的厨房', slug = 'aboutus', content = '')
Page.create(name = '包装展示', slug = 'bzzs', content = '')
Page.create(name = '订购说明', slug = 'dgsm', content = '')
Page.create(name = '如何收货', slug = 'rhsh', content = '')
Page.create(name = '付款方式', slug = 'fkfs', content = '')
Page.create(name = '配送范围', slug = 'psfw', content = '')
User.create(mobile = 'root', password = User.create_password('111111'), group = 9)
logging.info('superuser - username:root password:111111')
示例2: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def register():
'''
Register a new user and generate then an API Key.
Returns JSON-encoded username and API Key.
'''
reqjson = request.get_json()
username = reqjson.get('username', '')
password = reqjson.get('password', '')
if not username or not password:
logging.debug('Denying access for username of %s' % username)
abort(400)
try:
user = User.create(username=username, password=password)
except IntegrityError as e:
logging.error('unable to register user with username %s' % username, e)
abort(409)
key = hashlib.sha1(username + password + str(datetime.now().microsecond) + SALT)
apikey = ApiKey.create(owner=user.id, key=key.hexdigest())
logging.warn('registered user with username %s' % username)
return jsonify({'username': user.username, 'apikey': apikey.key}), 201
示例3: getUser
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def getUser(self, name):
"""Return a User object
@type name: string, or User Object
@param name: user name, or User object
@rtype: User object"""
return User.create(self.pm_getUserManager().getUser(self._unbox(name)),self._modelDataManager)
示例4: adminCreation
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def adminCreation():
form = forms.UserCreationForm()
if form.validate_on_submit():
user = User.create(form.username.data, form.password.data)
User(user.id).makeAdmin()
return user.serialize()
else:
raise MissingFieldsError(form.errors.keys())
示例5: addUser
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def addUser(self, name, fullName, password, email = None, url = None):
"""Create a User
@param name: user's name
@param fullName: user's full name
@param password: user's password
@param email: user's email (default value is set by Confluence)
@param url: user's URL on Confluence (default value is set by Confluence)
@rtype: User object
@return: newly created User"""
return User.create(self.pm_getUserManager().addUser(name, fullName, password, email, url),self._modelDataManager)
示例6: sign_up
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def sign_up():
if 'name' in bottle.request.POST and 'password' in bottle.request.POST:
name= bottle.request.POST['name']
if name not in reserved_usernames.split():
password = bottle.request.POST['password']
user = User.create(name,password)
if user:
sess = Session(bottle.request,bottle.response)
sess['id'] = user.id
sess.save()
bottle.redirect('/home')
return bottle.template('login',page='login',error_login=False,error_signup=True,logged=False)
示例7: index
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def index():
if request.method == "POST":
form = FormValidation(dict(request.form))
if form.flash_messages:
for message, category in form.flash_messages:
flash(message, category)
return render_template("index.html", old_form=request.form)
else:
salt = binascii.b2a_hex(os.urandom(15))
hashed_pw = md5(request.form['password'] + salt).hexdigest()
User.create(
first_name=request.form['first_name'],
last_name=request.form['last_name'],
birthdate=request.form['birthdate'],
email=request.form["email"],
password=hashed_pw,
salt=salt,
)
flash("Your user info was successfully submitted", "success")
return redirect("/login")
return render_template('index.html', old_form=None)
示例8: __init__
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
class Base:
def __init__(self, database):
self.model = User(database, bcrypt)
def on_get(self, req, resp):
if authorize_as(req.auth, 'developer'):
resp.body = dumps(self.model.all())
else:
raise HTTPUnauthorized('unautharized', 'unautharized')
def on_post(self, req, resp):
body = authorize_body(req)
new_user = self.model.create(body)
resp.status = HTTP_201
resp.body = dumps(new_user)
示例9: listUsers
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
def listUsers(self):
"""Return a list of current users
@rtype: User List
@return: list of available Users"""
return tuple(User.create({'name':name},self._modelDataManager) for name in self.pm_getUserManager().listUsers())
示例10: raw_input
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import create [as 别名]
from getpass import getpass
from model import User
from encas import app
print "Administrator account creation"
username = raw_input("Username: ")
while True:
password = getpass("Password: ")
confirm = getpass("Password confirmation: ")
if password == confirm:
break
with app.app_context():
new = User.create(username, password)
User(new.id).makeAdmin()