本文整理汇总了Python中User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: import User [as 别名]
# 或者: from User import create [as 别名]
def register():
"""Register new user."""
form = RegisterForm(request.form, csrf_enabled=False)
if form.validate_on_submit():
User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True)
flash('Thank you for registering. You can now log in.', 'success')
return redirect(url_for('public.home'))
else:
flash_errors(form)
return render_template('public/register.html', form=form)
示例2: register
# 需要导入模块: import User [as 别名]
# 或者: from User import create [as 别名]
def register():
form = RegisterForm(request.form, csrf_enabled=False)
if form.validate_on_submit():
new_user = User.create(username=form.username.data,
first_name=form.first_name.data,
last_name=form.last_name.data,
email=form.email.data,
password=form.password.data,
active=True)
flash("Thank you for registering. You can now log in.", 'success')
return redirect(url_for('public.home'))
else:
flash_errors(form)
return render_extensions('public/register.html', form=form)
示例3: test_check_password
# 需要导入模块: import User [as 别名]
# 或者: from User import create [as 别名]
def test_check_password(self):
user = User.create(username="foo", email="[email protected]",
password="foobarbaz123")
assert user.check_password('foobarbaz123') is True
assert user.check_password("barfoobaz") is False
示例4: do_token_dance
# 需要导入模块: import User [as 别名]
# 或者: from User import create [as 别名]
def do_token_dance (self, **args) :
"""
This is the method you should call from your 'auth' handler; that
is the URL that you tell the Flickr API Auth flow to redirect to
once a user has authed your application (in magic Flickr land).
It will check for a 'frob' parameter and then call the Flickr API
and exchange it for a valid Flickr Auth token.
If something goes wrong it will return False, otherwise it will
redirect the user to your application's root URL (where presumably
you are calling 'checked_logged_in').
For example:
class TokenFrobHandler (FlickrApp) :
# Assume __init__ here
def get (self):
try :
new_users = True
self.do_token_dance(allow_new_users=new_users)
except FlickrApp.FlickrAppNewUserException, e :
self.assign('error', 'no_new_users')
except FlickrApp.FlickrAppAPIException, e :
self.assign('error', 'api_error')
except FlickrApp.FlickrAppException, e :
self.assign('error', 'app_error')
self.assign('error_message', e)
except Exception, e:
self.assign('error', 'unknown')
self.assign('error_message', e)
self.display("token_dance.html")
return
"""
frob = self.request.get('frob')
if not frob or frob == '' :
raise FlickrAppException('Missing frob!')
extra = self.request.get('extra')
e_params = {}
if extra and extra != '' :
extra = urlparse(extra)
e_params = dict([part.split('=') for part in extra[2].split('&')])
crumb = urllib.unquote(e_params['crumb'])
if not self.validate_crumb(None, 'flickrauth', crumb) :
raise FlickrAppCrumbException('Invalid crumb')
api_args = {'frob': frob, 'check_response' : True}
rsp = self.api_call('flickr.auth.getToken', api_args)
if not rsp :
raise FlickrAppAPIException('Failed to get token')
token = rsp['auth']['token']['_content']
name = rsp['auth']['user']['username']
nsid = rsp['auth']['user']['nsid']
perms = rsp['auth']['perms']['_content']
user_perms = self.perms_map[perms]
user = User.get_user_by_nsid(nsid)
if not user :
if args.has_key('allow_new_users') and not args['allow_new_users'] :
raise FlickrAppNewUserException()
if not user :
args = {
'password' : self.generate_password(),
'token' : token,
'username' : name,
'nsid' : nsid,
'perms' : user_perms,
}
user = User.create(args)
else :
#.........这里部分代码省略.........
示例5: test_check_password
# 需要导入模块: import User [as 别名]
# 或者: from User import create [as 别名]
def test_check_password(self):
"""Check password."""
user = User.create(username='foo', email='[email protected]',
password='foobarbaz123')
assert user.check_password('foobarbaz123') is True
assert user.check_password('barfoobaz') is False