本文整理汇总了Python中models.User.register方法的典型用法代码示例。如果您正苦于以下问题:Python User.register方法的具体用法?Python User.register怎么用?Python User.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.register方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# should all return None, because this is simply creating data and is all meant to be correct
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'teacher', 't'))
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'teachertwo', 'ttwo'))
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'student', 's'))
self.teacher = User.all().filter('email =', '[email protected]').get()
self.teacher2 = User.all().filter('email =', '[email protected]').get()
self.student = User.all().filter('email =', '[email protected]' ).get()
self.assertIsNotNone(self.teacher)
self.assertIsNone(self.teacher.make_teacher())
self.assertIsNotNone(self.teacher2)
self.assertIsNone(self.teacher2.make_teacher())
self.assertIsNone(Course.create(self.teacher, 'public', ''))
self.public = Course.all().filter('name =', 'Public').get()
self.assertIsNotNone(self.public)
self.assertIsNone(Course.create(self.teacher, 'private', 'on'))
self.private = Course.all().filter('name =', 'Private').get()
self.assertIsNotNone(self.private)
示例2: add_new_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def add_new_user():
data = request.get_json()
new_user = {}
invalid_fields = []
require_fields = ["username", "password", "usertype"]
for field in require_fields:
value = data.get(field)
if value is None:
invalid_fields.append(field)
new_user[field] = value
if invalid_fields:
return (
jsonify(
status="error",
message="Please enter valid value for '{}' fields".format(
",".join(invalid_fields)
),
),
400,
)
try:
new_user["usertype"] = int(new_user["usertype"])
except (ValueError, TypeError) as e:
return jsonify(status="error", message=str(e)), 400
try:
User.register(
username=new_user["username"],
password=new_user["password"],
usertype=new_user["usertype"],
)
activity.logger.info(
"'{}' user added by '{}' user.".format(
new_user["username"], g.user.username
)
)
return jsonify(status="success", message="User added")
except Exception as e:
print(e)
activity.logger.error(
"'{}' username is not available for creating new user.".format(
new_user["username"]
)
)
return (
jsonify(
status="error",
message="'{}' username is not available. Please select different username".format(
new_user["username"]
),
),
400,
)
示例3: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def register():
"""Registers the user."""
if g.user:
return redirect(url_for('timeline'))
error = None
if request.method == 'POST':
if not request.form['username']:
error = 'You have to enter a username'
elif not request.form['email'] or \
'@' not in request.form['email']:
error = 'You have to enter a valid email address'
elif not request.form['password']:
error = 'You have to enter a password'
elif request.form['password'] != request.form['password2']:
error = 'The two passwords do not match'
elif get_user_id(request.form['username']) is not None:
error = 'The username is already taken'
else:
user = User.register(username=request.form['username'],
email=request.form['email'],
password=generate_password_hash(request.form['password']))
"""
db = get_db()
db.execute('''insert into user (
username, email, pw_hash) values (?, ?, ?)''',
[request.form['username'], request.form['email'],
generate_password_hash(request.form['password'])])
db.commit()
"""
flash('You were successfully registered and can login now')
return redirect(url_for('login'))
return render_template('register.html', error=error)
示例4: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
username = self.request.get("username")
password = self.request.get("password")
verify = self.request.get("verify")
email = self.request.get("email")
error_username = ""
error_password = ""
error_verify = ""
error_email = ""
error = False
if not(username and self.valid_username(username)):
error_username = "That's not a valid username"
error = True
if not(password and self.valid_password(password)):
error_password = "That's not a valid password"
error = True
elif not(verify and self.valid_verify(password, verify)):
error_verify = "Passwords don't match"
error = True
if email and not self.valid_email(email):
error_email = "That's not a valid email"
error = True
if error:
self.render_signup(error_username, error_password, error_verify, error_email, username, email)
elif self.exists_username(username):
error_username = "Username already exists"
self.render_signup(error_username, error_password, error_verify, error_email, username, email)
else:
user = User.register(username, password, email)
user.put()
self.login(user)
self.redirect("/blog/welcome")
示例5: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
have_error = False
self.username = self.request.get('username')
self.password = self.request.get('password')
self.verify = self.request.get('verify')
self.email = self.request.get('email')
params = dict(username=self.username, email=self.email)
if not valid_username(self.username):
params['error_username'] = "That's not a valid username."
have_error = True
elif User.by_name(self.username):
params['error_username'] = 'That user already exists.'
have_error = True
if not valid_password(self.password):
params['error_password'] = "That wasn't a valid password."
have_error = True
elif self.password != self.verify:
params['error_verify'] = "Your passwords didn't match."
have_error = True
if not valid_email(self.email):
params['error_email'] = "That's not a valid email."
have_error = True
if have_error:
self.render('signup.html', **params)
else:
u = User.register(self.username, self.password, self.email)
u.put()
self.login(u)
self.redirect('/blogs')
示例6: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
#imports json object and places it in data dictionary
data = request.json
#init varibles contining user data
uid = data['uid']
name = data['name']
email = data['email']
gender = data['gender']
city = data['city']
state = data['state']
cards = 0
#creates data store user object
u = User.register(uid, name, email, gender, city, state, cards)
#pushes response out to client
if u.put():
message = {
'uid': uid,
'message': 'success',
'num_cards': cards
}
resp = jsonify(message)
resp.status_code = 200
return resp
else:
message = {
'status': 404,
'message': 'bad data',
}
resp = jsonify(message)
resp.status_code = 404
return resp
示例7: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
username = self.request.get('username')
password = self.request.get('password')
password_verify = self.request.get('verify')
email = self.request.get('email')
params = dict(username=username, email=email)
have_error = False
if valid_username(username):
user = User.by_name(username)
if user:
params['error_username'] = "That user already exists."
have_error = True
else:
params['error_username'] = "That's not a valid username."
have_error = True
if not valid_password(password):
params['error_password'] = "That's not a valid password."
have_error = True
elif password != password_verify:
params['error_verify'] = "Your passwords didn't match."
have_error = True
if not valid_email(email):
params['error_email'] = "That's not a valid email."
have_error = True
if have_error:
self.render('signup-form.html', **params)
else:
user = User.register(username, password, email)
user.put()
self.login(user)
self.redirect('/')
示例8: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
print('[POST]', self.request)
username = self.request.get('username')
password = self.request.get('password')
verify = self.request.get('verify')
email = self.request.get('email')
# Signup on any page and get redirected to that page when complete.
next_url = str(self.request.get('referer'))
if not next_url or next_url.startswith('/login'):
next_url = '/'
if username and password and verify:
existing_user = User.by_name(username)
# Make sure user doesnt already exists
if existing_user:
error = 'Error, user already exists: ' + username
self.render_page(username, password, verify, email, error)
else:
new_user = User.register(username, password, email)
new_user.put()
self.set_secure_cookie('userId', str(new_user.key().id()))
# Redirect to the referring page
self.redirect(next_url)
else:
error = 'Error, you need to fill in all values.'
self.render_page(username, password, verify, email, error, next_url=next_url)
示例9: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
"""
Post method to signup
"""
_username = self.request.get("username")
_pwd = self.request.get("password")
_verify_pwd = self.request.get("verify_password")
_email = self.request.get("email")
username_error = "Please enter Username"
pw_error = "Please enter password"
verify_pw_error = "Please verify password"
email_error = "Please enter email"
if _username and _pwd and _verify_pwd and _email:
if _pwd == _verify_pwd:
_user = User.query(User.name == _username).get()
print _user
if _user is None:
_newUser = User.register(_username, _pwd, _email)
newUserKey = _newUser.put()
newUser = newUserKey.id()
self.login(newUser)
self.render('welcome.html', user=_username)
else:
self.render('signup.html', username_error="User already exist")
else:
self.render('signup.html', verify_pw_error=verify_pw_error)
if _username == "" or _pwd == "" or _verify_pwd == "" or _email == "":
self.render('signup.html', username_error=username_error, pw_error=pw_error,
verify_pw_error=verify_pw_error, email_error=email_error)
示例10: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
# get all the required params
username = self.request.get('username')
password = self.request.get('password')
email = self.request.get('email')
verify = self.request.get('verify')
# build an array of errors
# if there is any error set return_error to true
errors = []
return_error = False
if not username or not password or not email or not verify:
return_error = True
errors.append('All fields are required.')
if password != verify:
return_error = True
errors.append('Passwords did not match.')
if username:
# check if username exists
u = User.by_name(username)
if u:
errors.append('That username is already taken.')
return_error = True
if return_error == True:
self.render_form(username, email, errors)
else:
user = User.register(username, password, email)
user.put()
self.set_login_cookie(user)
self.redirect(HOME_PATH + '/welcome/')
示例11: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def post(self):
username = self.request.get("username")
password = self.request.get("password")
verify = self.request.get("verify")
email = self.request.get("email")
params = {"username":username, "email":email}
error = False
if not(username and self.valid_username(username)):
params["error_username"] = "That's not a valid username"
error = True
if not(password and self.valid_password(password)):
params["error_password"] = "That's not a valid password"
error = True
elif not(verify and self.valid_verify(password, verify)):
params["error_verify"] = "Passwords don't match"
error = True
if email and not self.valid_email(email):
params["error_email"] = "That's not a valid email"
error = True
if error:
self.render("wiki_signup.html", **params)
elif self.exists_username(username):
params["error_username"] = "Username already exists"
self.render("wiki_signup.html", **params)
else:
user = User.register(username, password, email)
user.put()
self.login(user)
self.redirect("/wiki/welcome")
示例12: save
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def save(self, language='en', commit=True):
from models import User
try:
return User.register(email=self.cleaned_data['email'], password=self.cleaned_data['password'], language=language)
except User.UniqueEmailConstraint, e:
fail = _('Cuenta de correo en uso')
self._errors['email'] = self.error_class([fail])
示例13: check_database
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def check_database():
try:
### Create Tables
db.create_all()
### Add Admin User
admin_user = User.register(username="admin", password="admin", usertype=0)
except Exception as e:
print(e)
示例14: done
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def done(self, *a, **kw):
u = User.by_name(self.username)
if u:
msg = 'That user already exists'
self.render('signup.html', error_username=msg)
else:
u = User.register(self.username, self.password, self.email)
u.put()
self.login(u)
self.redirect('/welcome')
示例15: done
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import register [as 别名]
def done(self):
u = User.by_name(self.username)
if u:
msg = 'That user already exists.'
self.render('signup-form.html', error_username=msg)
else:
u = User.register(self.username, self.password, self.email)
u.put()
self.login(u)
self.redirect(self.next_url)