本文整理汇总了Python中users.User.createUser方法的典型用法代码示例。如果您正苦于以下问题:Python User.createUser方法的具体用法?Python User.createUser怎么用?Python User.createUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.User
的用法示例。
在下文中一共展示了User.createUser方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signup
# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
def signup():
''' User Sign up page: Very basic email + password sign up form that will also login users. '''
## Data is used throughout for the jinja2 templates
data={
'active': "signup", # Sets the current page
'loggedin': False # Don't show the logout link
}
## Define the SignupForm
form = SignupForm(request.form)
## Validate and then create userdata
if request.method == "POST":
if form.validate():
## Take form data
email = form.email.data
password = form.password.data
company = form.company.data
contact = form.contact.data
userdata = {
'username': email,
'email': email,
'password': password,
'company': company,
'contact': contact
}
## Create user
user = User()
result = user.createUser(userdata, g.rdb_conn)
## Check results for success or failure
if result == "exists":
data['error'] = True
data['msg'] = 'User already exists'
elif result is not False:
stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' User Signup', 1)
print("/signup - New user created")
cdata = cookies.genCdata(result, app.config['SECRET_KEY'])
data['loggedin'] = True
data['msg'] = 'You are signed up'
data['error'] = False
## Build response
resp = make_response(redirect(url_for('dashboard_page')))
timeout = int(time.time()) + int(app.config['COOKIE_TIMEOUT'])
## Set the cookie secure as best as possible
resp.set_cookie('loggedin', cdata, expires=timeout, httponly=True)
return resp
else:
stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Failed User Signup', 1)
print("/signup - Failed user creation")
data['msg'] = 'Form is not valid'
data['error'] = True
## Return Signup Page
return render_template('signup.html', data=data, form=form)
示例2: signup
# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
def signup():
"""
User Sign up page: Very basic email + password
sign up form that will also login users.
"""
# Data is used throughout for the jinja2 templates
data = {"active": "signup", "loggedin": False} # Sets the current page # Don't show the logout link
# Define the SignupForm
form = SignupForm(request.form)
# Validate and then create userdata
if request.method == "POST":
if form.validate():
# Take form data
email = form.email.data
password = form.password.data
company = form.company.data
contact = form.contact.data
userdata = {"username": email, "email": email, "password": password, "company": company, "contact": contact}
# Create user
user = User()
user.config = app.config
result = user.createUser(userdata, g.rdb_conn)
# Check results for success or failure
if result == "exists":
flash("User already exists.", "danger")
elif result is not False:
try:
stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " User Signup", 1)
except:
pass
print("/signup - New user created")
cdata = cookies.genCdata(result, app.config["SECRET_KEY"])
data["loggedin"] = True
flash("You are signed up.", "success")
# Generate confirmation token
generate_confirmation_token(email, result, time.time())
# Build response
resp = make_response(redirect(url_for("member.dashboard_page")))
timeout = int(time.time()) + int(app.config["COOKIE_TIMEOUT"])
# Set the cookie secure as best as possible
resp.set_cookie("loggedin", cdata, expires=timeout, httponly=True)
return resp
else:
stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " False User Signup", 1)
print("/signup - False user creation")
flash("Form is not valid.", "danger")
# Return Signup Page
return render_template("user/signup.html", data=data, form=form)
示例3: setUp
# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
def setUp(self):
try:
g.rdb_conn = r.connect(
host=app.config['DBHOST'], port=app.config['DBPORT'],
auth_key=app.config['DBAUTHKEY'], db=app.config['DATABASE'])
userdata = {
'username': '[email protected]',
'email': '[email protected]',
'password': 'password456',
'company': 'company',
'contact': 'tester'
}
# Create test user
user = User()
user.createUser(userdata, g.rdb_conn)
except RqlDriverError:
# If no connection possible throw 503 error
abort(503, "No Database Connection Could be Established.")
示例4: setUp
# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
def setUp(self):
try:
g.rdb_conn = r.connect(
host=app.config["DBHOST"],
port=app.config["DBPORT"],
auth_key=app.config["DBAUTHKEY"],
db=app.config["DATABASE"],
)
userdata = {
"username": "[email protected]",
"email": "[email protected]",
"password": "password456",
"company": "company",
"contact": "tester",
}
# Create test user
user = User()
user.createUser(userdata, g.rdb_conn)
except RqlDriverError:
# If no connection possible throw 503 error
abort(503, "No Database Connection Could be Established.")