本文整理汇总了Python中libnemesis.User.create_new_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.create_new_user方法的具体用法?Python User.create_new_user怎么用?Python User.create_new_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libnemesis.User
的用法示例。
在下文中一共展示了User.create_new_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_user
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_new_user [as 别名]
def register_user(requesting_user):
if not requesting_user.can_register_users:
return json.dumps({"error":"YOU_CANT_REGISTER_USERS"}), 403
teacher_username = requesting_user.username
college_group = request.form["college"].strip()
first_name = request.form["first_name"].strip()
last_name = request.form["last_name"].strip()
email = request.form["email"].strip()
team = request.form["team"].strip()
if College(college_group) not in requesting_user.colleges:
return json.dumps({"error":"BAD_COLLEGE"}), 403
if team not in [t.name for t in College(college_group).teams]:
return json.dumps({"error":"BAD_TEAM"}), 403
if not helpers.is_email_valid(email):
return json.dumps({"error":"BAD_EMAIL"}), 403
if not helpers.is_name_valid(first_name):
return json.dumps({"error":"BAD_FIRST_NAME"}), 403
if not helpers.is_name_valid(last_name):
return json.dumps({"error":"BAD_LAST_NAME"}), 403
if User.name_used(first_name, last_name) or helpers.email_used(email):
return json.dumps({"error":"DETAILS_ALREADY_USED"}), 403
u = User.create_new_user(requesting_user, college_group, first_name, last_name)
verify_code = helpers.create_verify_code(u.username, email)
pu = PendingUser(u.username)
pu.teacher_username = teacher_username
pu.college = college_group
pu.email = email
pu.team = team
pu.verify_code = verify_code
pu.save()
log_action('registering user', pu)
url = url_for('activate_account', username=u.username, code=verify_code, _external=True)
pu.send_welcome_email(first_name, url)
rqu_email_vars = { 'name': requesting_user.first_name,
'activation_days': ACTIVATION_DAYS,
'pu_first_name': first_name,
'pu_last_name': last_name,
'pu_username': pu.username,
'pu_college': College(pu.college).name,
'pu_email': pu.email,
'pu_team': pu.team
}
mailer.email_template(requesting_user.email, 'user_requested', rqu_email_vars)
return "{}", 202
示例2: register_user
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_new_user [as 别名]
def register_user():
ah = AuthHelper(request)
if ah.auth_will_succeed:
requesting_user = ah.user
if requesting_user.can_register_users:
teacher_username = requesting_user.username
college_group = request.form["college"].strip()
first_name = request.form["first_name"].strip()
last_name = request.form["last_name"].strip()
email = request.form["email"].strip()
team = request.form["team"].strip()
if College(college_group) not in requesting_user.colleges:
return json.dumps({"error":"BAD_COLLEGE"}), 403
if team not in [t.name for t in College(college_group).teams]:
return json.dumps({"error":"BAD_TEAM"}), 403
if User.name_used(first_name, last_name) or helpers.email_used(email):
return json.dumps({"error":"DETAILS_ALREADY_USED"}), 403
u = User.create_new_user(requesting_user, college_group, first_name, last_name)
verify_code = helpers.create_verify_code(u.username, email)
pu = PendingUser(u.username)
pu.teacher_username = teacher_username
pu.college = college_group
pu.email = email
pu.team = team
pu.verify_code = verify_code
pu.save()
url = url_for('activate_account', username=u.username, code=verify_code, _external=True)
pu.send_welcome_email(first_name, url)
rqu_email_vars = { 'name': requesting_user.first_name,
'pu_first_name': first_name,
'pu_last_name': last_name,
'pu_username': pu.username,
'pu_college': College(pu.college).name,
'pu_email': pu.email,
'pu_team': pu.team
}
mailer.email_template(requesting_user.email, 'user_requested', rqu_email_vars)
return "{}", 202
else:
return json.dumps({"error":"YOU_CANT_REGISTER_USERS"}),403
else:
return ah.auth_error_json, 403
示例3: test_activate_success
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_new_user [as 别名]
def test_activate_success():
username = '1_ja1'
rq_user = User.create_user("teacher_coll1", "facebees")
cu = User.create_new_user(rq_user, 'college-1', 'James', 'Activate')
assert cu.username == username
pu = create_pending_user(username)
pu.save()
r,data = test_helpers.server_get("/activate/" + username + "/bibble")
status = r.status
assert status == 200, data
u = User(username)
email = u.email
assert pu.email == email
teams = [t.name for t in u.teams]
assert pu.team in teams
colleges = u.colleges
assert pu.college in colleges
students = srusers.group('students').members
assert username in students
pu = PendingUser(username)
assert not pu.in_db, "registration DB entry should have been removed"
# ensure we sent the team-leader a confirmation
ps = test_helpers.last_email()
toaddr = ps.toaddr
tl_email = rq_user.email
assert toaddr == tl_email
vars = ps.template_vars
tl_name = rq_user.first_name
assert tl_name == vars['name']
first_name = cu.first_name
assert first_name == vars['au_first_name']
last_name = cu.last_name
assert last_name == vars['au_last_name']
assert username == vars['au_username']
template = ps.template_name
assert template == 'user_activated_team_leader'