本文整理汇总了Python中models.user.User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def post(self):
b=self.request.get("name")
self.response.write(b)
d=self.request.get("uname")
print d
f = self.request.get("upname")
print f
a=User.create_user(b)
self.response.write(a)
if b == a:
self.response.write("already exists")
else:
self.response.write("created")
User.create(b)
c=User.listofusers()
if d == a:
e=User.deleteuser(d)
print "deleted user"
else:
print "username didnt exist"
if b == a:
g=User.update(f)
print "updated"
示例2: sign_up
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def sign_up():
email = request.form.get('email').strip()
name = request.form.get('name').strip()
password = request.form.get('password').strip()
reg_ip = get_ip_by_request(request)
User.create(email=email, name=name, password=password, reg_ip=reg_ip)
return ok('sign up successfully')
示例3: test_user_created
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def test_user_created():
new_user = User.create(email='[email protected]', password='password')
assert new_user
assert new_user.password != 'password'
assert User.verify('[email protected]', 'password') == new_user
with pytest.raises(IntegrityError):
User.create(email='[email protected]', password='different')
示例4: user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def user():
fake = Faker()
user_data = {"username": fake.first_name(), "password": fake.text(10)}
user = User()
user.create(user_data)
user.password = user_data.get("password")
return user
示例5: create_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def create_user(self, callback=None):
logging.info('register ,create_user ...')
import os
#logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'), level = logging.DEBUG,
# filemode = 'w', format = '%(asctime)s - %(levelname)s: %(message)s')
self.email = self.get_argument("Email", default=None)
password = self.get_argument("Password", default=None)
verify_password = self.get_argument("VerifyPassword", default=None)
logging.info(self.email)
successed = False
if EmailIsValid(self.email) and password == verify_password and PasswdIsValid(password):
logging.info('EmailIsValid...')
user = User.find_by_email_and_password(self.email, password)
if user.empty:
logging.info('User create...')
logging.info(self.email)
successed = User.create(self.email, password)
else:
logging.info('no create user...')
logging.info('register ,create_user, successed ...')
logging.info(successed)
callback(successed)
示例6: init_facebook
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def init_facebook(self):
"""Sets up the request specific Facebook and User instance"""
facebook = Facebook()
user = None
# initial facebook request comes in as a POST with a signed_request
if u'signed_request' in self.request.POST:
facebook.load_signed_request(self.request.get('signed_request'))
# we reset the method to GET because a request from facebook with a
# signed_request uses POST for security reasons, despite it
# actually being a GET. in webapp causes loss of request.POST data.
self.request.method = u'GET'
self.set_cookie('u', facebook.user_cookie, datetime.timedelta(minutes=1440))
elif 'u' in self.request.cookies:
facebook.load_signed_request(self.request.cookies.get('u'))
# try to load or create a user object
if facebook.user_id:
user = User.get_by_key_name(facebook.user_id)
if user:
user.refresh_data(facebook)
if not user and facebook.access_token:
user = User.create(facebook)
self.facebook = facebook
self.user = user
示例7: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def post(self):
username = self.get_argument('username')
pwd = self.get_argument('pwd')
pwd_confirm = self.get_argument('pwd_confirm')
date = datetime.datetime.now().date()
to_date = date+datetime.timedelta(365)
if pwd == pwd_confirm:
user = User.create(username=username, pwd=pwd)
c_study = Category.create(user_id=user.id, content='学习',
color='#ffe9e9', level=1, status=1)
c_reading = Category.create(user_id=user.id, content='读书',
color='#edffde', level=1, status=1)
c_thinking = Category.create(user_id=user.id, content='思考',
color='#fbe4d6', level=1, status=1)
c_sports = Category.create(user_id=user.id, content='运动',
color='#e2fbfd', level=1, status=1)
c_shopping = Category.create(user_id=user.id, content='购物',
color='#ffeed4', level=1, status=1)
t_study = CommonTask.create(user_id=user.id, category_id=c_study.id,
status=1, content='打卡今日学习任务...',
visible_range=1, started_date=date, finished_date=to_date)
t_reading = CommonTask.create(user_id=user.id, category_id=c_reading.id,
status=1, content='打卡今日阅读任务...',
visible_range=1, started_date=date, finished_date=to_date)
t_thinking = CommonTask.create(user_id=user.id, category_id=c_thinking.id,
status=1, content='打卡今日思考任务...',
visible_range=1, started_date=date, finished_date=to_date)
t_sports = CommonTask.create(user_id=user.id, category_id=c_sports.id,
status=1, content='打卡今日运动任务...',
visible_range=1, started_date=date, finished_date=to_date)
t_shopping = CommonTask.create(user_id=user.id, category_id=c_shopping.id,
status=1, content='打卡今日购物任务...',
visible_range=1, started_date=date, finished_date=to_date)
CommonTaskFrequency.create(commontask_id=t_study.id, frequency=0)
CommonTaskFrequency.create(commontask_id=t_reading.id, frequency=0)
CommonTaskFrequency.create(commontask_id=t_thinking.id, frequency=0)
CommonTaskFrequency.create(commontask_id=t_sports.id, frequency=0)
CommonTaskFrequency.create(commontask_id=t_shopping.id, frequency=0)
for i in range(1, 8):
TaskRecord.create(user_id=user.id, commontask_id=t_study.id,
weekday=i, date=date)
for i in range(1, 8):
TaskRecord.create(user_id=user.id, commontask_id=t_reading.id,
weekday=i, date=date)
for i in range(1, 8):
TaskRecord.create(user_id=user.id, commontask_id=t_thinking.id,
weekday=i, date=date)
for i in range(1, 8):
TaskRecord.create(user_id=user.id, commontask_id=t_sports.id,
weekday=i, date=date)
for i in range(1, 8):
TaskRecord.create(user_id=user.id, commontask_id=t_shopping.id,
weekday=i, date=date)
self.redirect('/')
else:
self.redirect('/register')
示例8: test_multiple_session
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def test_multiple_session(self):
user = User.create()
sessions = [
Session.create(user = user),
Session.create(user = user)
]
for session in Session.find_by_user(user).all:
assert session in sessions
示例9: create_internal
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def create_internal(self, user, password):
user_id = User.create(user, password)
assert User.authenticate(user_id, password)
assert not User.authenticate(user_id, "otherpassword")
assert not User.authenticate(user_id, user)
recreated_user = User(user_id)
assert_equals(user_id, recreated_user.user_id)
assert_equals(user, recreated_user.name)
示例10: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def post(self):
username = self.request.POST['username']
passwor = self.request.POST['password']
gender = self.request.POST['sex']
manager = CRYPTPasswordManager(SHA256CRYPT)
password=manager.encode(passwor)
if re.match("^[a-zA-Z0-9._%-][email protected][a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", username) != None:
q = db.GqlQuery("SELECT * from User where email = :1",username)
a = q.get()
if a is not None:
self.session.add_flash("Username already exists!",key='error')
self.redirect("/signup")
else:
User.create(username,password,gender)
self.redirect("/login")
else:
self.session.add_flash("Enter valid email!",key='error')
self.redirect("/signup")
示例11: create
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def create():
email = request.json["email"]
password = request.json["password"]
try:
user = User.create(email, password)
print user
except db.IntegrityError:
return "Email has already been used", 400
session['user_id'] = user.id
return db.json_encode(user.to_dict())
示例12: register
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def register():
if request.form['email'] != request.form['email1']:
return redirect(url_for('new', message='email'))
if request.form['password'] != request.form['password']:
return redirect(url_for('new', message='password'))
if passwordmeter.test(request.form['password'])[0] < 0.4:
return redirect(url_for('new', message='password_weak'))
l = len(request.form['fullname'])
if l < 1 or l > 40:
return redirect(url_for('new', message='fullname_invalid'))
User.create(
request.form['email'],
request.form['password'],
fullname=request.form['fullname'],
).save()
return redirect(url_for('index', message='register_success'))
示例13: create_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def create_user(self, callback=None):
self.email = self.get_argument("Email", default = None)
password = self.get_argument("Password", default = None)
verify_password = self.get_argument("VerifyPassword", default = None)
successed = False
if EmailIsValid(self.email) and password == verify_password and PasswdIsValid(password):
user = User.find_by_email_and_password(email, password)
if user.empty:
successed = User.create(self.email, password)
callback(successed)
示例14: create_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def create_user(userData: UserType):
"""
Create a new user
"""
if User.check_username(userData.username):
msg = f"The username: {userData.username} isn't available. Please try another."
return http.JSONResponse({"message": msg}, status_code=409)
user = User()
user = user.create(userData)
msg = "User created successfully."
log.info(f"{msg} - ID: {user.id}")
headers = {"Content-Location": f"/users/{user.id}"}
return http.JSONResponse({"message": msg}, status_code=201, headers=headers)
示例15: register
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import create [as 别名]
def register():
try:
username = request.form['username']
passwd = request.form['passwd']
nickname = request.form['nickname']
gender = request.form['gender']
birthday = request.form['birthday']
avatar_url = request.form['avatar_url']
if len(username)==0 or len(passwd)==0:
raise(KeyError)
except KeyError:
return error(400, u'参数错误')
if len(gender) == 0:
gender = 0
if len(birthday) == 0:
birthday = '1990-1-1'
if User.get_by_username(username):
return error(10008, u'用户已存在')
passwd = md5.new(passwd).hexdigest()
user = User.create(username, passwd, nickname, gender, birthday, avatar_url)
if not user:
return error(10007, u'创建失败')
return user