本文整理汇总了Python中model.user.User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_db
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def init_db():
from model.user import User
from model.url import URL
from model.cata import Cata
from model.mod_log import ModLog
from misc.const import d_cata, d_source
# 创建表
db.create_tables([User, URL, Cata, ModLog])
# 新建用户
data = dict(
user="admin",
name="admin",
pwd=hashlib.md5('admin').hexdigest(),
)
User.create(**data)
# 创建交叉表
for k in d_cata.keys():
for k1 in d_source.keys():
c = Cata.select().where(Cata.cata == k, Cata.source == k1)
if not c:
d_ = dict(
cata=k,
source=k1,
)
Cata.create(**d_)
示例2: handle_facebook_login
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def handle_facebook_login(self):
access_token = self.request.get('access_token')
user_id = self.request.get('user_id')
profile_url = 'https://graph.facebook.com/me?access_token=%s'
profile = json.loads(urlfetch.fetch(profile_url%access_token).content)
logging.info('Facebook Login:: ')
logging.info(profile)
id = profile['id']
if not id == user_id:
response = {"success": False, "error": "Facebook ids don't match."}
else:
if 'email' in profile:
email = profile['email']
else:
email = id
user = User.get_by_key_name(email)
device_token = self.request.get('token_hex')
if not user:
user = User.create(email, profile['first_name'], profile['last_name'], device_token)
ThirdPartyUser.create('FB', user, access_token, id)
profile_picture = self.get_profile_picture(id)
User.update(email, profile_picture=profile_picture, device_token=device_token)
else:
User.update(email, device_token=device_token)
util.set_session(email)
response = {"success": True, "email": email, "first_name": user.first_name, "last_name": user.last_name}
return response
示例3: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def post(self):
email = self.request.get('email')
first_name = self.request.get('first_name')
last_name = self.request.get('last_name')
password = self.request.get('password')
confirm_password = self.request.get('confirm_password')
device_token = self.request.get('token_hex')
logging.info('Sign Up:: ')
logging.info(email)
if password == confirm_password:
user = User.get_by_key_name(email)
if user:
response = {"success": False, "error": "Email already in use."}
else:
User.create(email, first_name, last_name, device_token, password)
util.set_session(email)
response = {"success": True}
else:
response = {"success": False, "error": "Passwords don't match."}
self.response.write(json.dumps(response))
示例4: setup
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def setup():
user_1 = User.create('email1', 'firstname1', 'lastname1', 'password1')
tp_user_1 = ThirdPartyUser(key_name='FB', parent=user_1)
tp_user_1.network_id = '359059317608175'
tp_user_1.put()
user_2 = User.create('email2', 'firstname2', 'lasstname2', 'password2')
tp_user_2 = ThirdPartyUser(key_name='FB', parent=user_2)
tp_user_2.network_id = '359059317608175'
tp_user_2.put()
bout_1 = Bout.create(user_1, 'bout1', 'desc1', 1, 1)
util.schedule_end(bout_1)
photo_1 = Photo.create(bout_1, user_1, 'image_blob_key_1')
photo_2 = Photo.create(bout_1, user_2, 'image_blob_key_2')
bout_2 = Bout.create(user_2, 'bout2', 'desc2', 1, 2)
util.schedule_end(bout_2)
Vote.create('email1', photo_1)
Vote.create('email2', photo_1)
Vote.create('email2', photo_2)
#photo_add, photo_vote, comment_add, winner, invited
Notification.create('photo_add', bout_1.owner, user_2.email, bout_1)
Notification.create('photo_vote', bout_1.owner, user_2.email, bout_1)
Notification.create('comment_add', bout_1.owner, user_2.email, bout_1)
Notification.create('winner', user_1, user_2.email, bout_1)
Notification.create('invited', user_1, user_2.email, bout_1)
#Winner.create(user_1, bout_1)
Comment(parent=photo_1, user=user_1, message='message1', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_1, user=user_2, message='message2', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_1, message='message3', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_1, message='message4', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_2, message='message5', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_1, message='message6', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_2, message='message7', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_2, message='message8', timestamp=datetime.datetime.now()).put()
Comment(parent=photo_2, user=user_2, message='message9', timestamp=datetime.datetime.now()).put()
Follower.create('email1', user_2)
Following.create(user_1, 'email2')
示例5: _on_auth
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def _on_auth(self, user):
if not user:
raise tornado.web.HTTPError(500, 'Twitter auth failed')
instance = User.get(user['id'])
if not instance:
access_key = user['access_token']['key']
access_secret = user['access_token']['secret']
instance = User.create(user['id'], xhtml_escape(user['name']),
user['profile_image_url_https'], access_key,
access_secret, user['username'])
if not instance:
raise RuntimeError('Uhm.. yeah.. about that..')
self.set_login(instance)
self.redirect('/')
示例6: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def post(self):
email = self.get_argument('email','')
user_name = self.get_argument('user_name','')
password = self.get_argument('password','')
password_confirm = self.get_argument('password_confirm','')
user = User()
user.email = email
user.name = user_name
user.password = password
user.password_confirm = password_confirm
user_id = user.create()
if not user_id:
return self.render('register.html', user_name="", user=user, errors=user.errors)
#return self.send_error_json(user.errors)
else:
self.redirect('/login')
示例7: reload
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
# coding=utf-8
from model.user import User
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def connect_db():
import transwarp.db as dbutil
dbutil.create_engine('sonic513', 'sonic513', 'tobacco_monitor', port=3306)
if __name__=="__main__":
connect_db()
if len(sys.argv)!=6:
print "usage: python script/setting_add_user.py email password confirm_password permission(0,1) name"
email = sys.argv[1]
password = sys.argv[2]
confirm_password = sys.argv[3]
permission = sys.argv[4]
name = sys.argv[5]
usr = User(email = email, password=password, password_confirm = confirm_password, permission=permission, name=name)
id= usr.create()
if id:
print "add user %s OK!" % name
else:
print usr.errors
示例8: jack
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def jack(request):
# TODO: we should create user table at first and clean all data in user table at last
# hint: request.addfinalizer
# hint: call `User.create_table()` to create table `user`
# hint: call `User.drop_table()` to drop table `user`
return User.create(name='jack')
示例9: post_register
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import create [as 别名]
def post_register():
""" Registers a new user. """
error = ''
user_full_name = request.form['full_name']
username = request.form['username']
password = request.form['password']
password_confirm = request.form['password_confirm']
email = request.form['email']
# User is already logged in.
if 'user_id' in session:
return redirect(url_for('home'))
# No more users can register.
elif settings.get('single_user_mode') \
and len(settings.get('registered_users')) > 0:
error = 'No more users can register at this time.'
# Username is alredy registered.
users = settings.get('registered_users')
username_taken = True if \
len([uid for uid, ud, in users.iteritems() if ud.get('username') == username]) > 0 \
else False
if username_taken:
return redirect(url_for('get_login'))
# Register the new user.
if username is None:
error = 'No username provided.'
elif len(username) < 8 or len(username) > 25:
error = 'Username is not the correct length. \
Please enter a username between 8-25 characters.'
elif re.search('[^a-zA-Z0-9\_]', username) is not None:
error = 'Usernames can only contain letters an numbers.'
elif re.search('\b[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}\b', email) is not None:
error = 'Please enter a valid email address.'
elif password is None or password_confirm is None:
error = 'You must fill in your password.'
elif password != request.form['password_confirm']:
error = 'Passwords do not match.'
elif len(password) < 8 or re.search('[a-zA-Z0-9]', password) is None:
error = 'Your password must be at least 8 characters long and \
must be a combination of numbers and letters. Special\
characters are allowed and encouraged.'
else:
new_user, feed_location, blocks_location, follows_location = User.create(username)
if settings.get('single_user_mode'):
settings.add('single_user_id', new_user.user_id)
domain = settings.get('domain')
new_user.profile = 'http://{0}/{1}'.format(domain, new_user.username)
new_user.link = 'http://{0}/{1}/feed.xml'.format(domain, new_user.username)
new_user.follows_url = 'http://{0}/{1}/follows.xml'.format(domain, new_user.username)
new_user.blocks_url = 'http://{0}/{1}/blocks.xml'.format(domain, new_user.username)
new_user.message_url = 'http://{0}/{1}/message.'.format(domain, new_user.username)
new_user.language = 'en'
# Update the settings.
pwd_hash = generate_password_hash(password)
settings.add_user(username=new_user.username,
pwd_hash=pwd_hash,
user_id=new_user.user_id,
feed_location=feed_location,
blocks_location=blocks_location,
follows_location=follows_location)
session['user_id'] = new_user.user_id
return redirect(url_for('home'))
return render_template('registration.html', error=error)