本文整理汇总了Python中libnemesis.User.create_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.create_user方法的具体用法?Python User.create_user怎么用?Python User.create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libnemesis.User
的用法示例。
在下文中一共展示了User.create_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_helper
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def form_helper(rq_user, rq_pass, new_fname, new_lname):
new_email = "[email protected]"
params = {"username":rq_user,
"password":rq_pass,
"first_name":new_fname,
"last_name":new_lname,
"email":new_email,
"team":"team-ABC",
"college":"college-1"}
r,data = test_helpers.server_post("/registrations", params)
status = r.status
assert status == 202, data
created = User.create_user('1_rt1')
assert created.email == ''
pending = PendingUser('1_rt1')
assert pending.email == "[email protected]"
assert pending.team == "team-ABC"
assert pending.college == "college-1"
email_datas = test_helpers.last_n_emails(2)
student_ps = email_datas[0]
template = student_ps.template_name
assert template == 'new_user'
to = student_ps.toaddr
assert to == new_email
vars = student_ps.template_vars
assert new_fname == vars['name']
vcode = pending.verify_code
assert vcode in vars['activation_url']
test_helpers.assert_load_template(template, vars)
teacher = User.create_user(rq_user)
teacher_ps = email_datas[1]
template = teacher_ps.template_name
assert template == 'user_requested'
to = teacher_ps.toaddr
assert to == teacher.email
vars = teacher_ps.template_vars
assert new_fname == vars['pu_first_name']
assert new_lname == vars['pu_last_name']
assert new_email == vars['pu_email']
assert '1_rt1' == vars['pu_username']
assert 'team-ABC' == vars['pu_team']
assert 'college the first' == vars['pu_college']
vars_str = teacher_ps.template_vars_json
assert vcode not in vars_str, "Should not contain the verification code."
test_helpers.assert_load_template(template, vars)
示例2: test_registration_rq_from_blueshirt
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_registration_rq_from_blueshirt():
new_email = "[email protected]"
params = {
"username": "blueshirt",
"password": "blueshirt",
"first_name": NEW_USER_FNAME,
"last_name": NEW_USER_LNAME,
"email": new_email,
"team": "team-ABC",
"college": "college-1",
}
r, data = test_helpers.server_post("/registrations", params)
status = r.status
assert status == 202, data
created = User.create_user("1_rt1")
assert created.email == ""
pending = PendingUser("1_rt1")
assert pending.email == "[email protected]"
assert pending.team == "team-ABC"
assert pending.college == "college-1"
email_datas = test_helpers.last_n_emails(2)
student_ps = email_datas[0]
template = student_ps.template_name
assert template == "new_user"
to = student_ps.toaddr
assert to == new_email
vars = student_ps.template_vars
assert NEW_USER_FNAME == vars["name"]
vcode = pending.verify_code
assert vcode in vars["activation_url"]
teacher = User.create_user("blueshirt")
teacher_ps = email_datas[1]
template = teacher_ps.template_name
assert template == "user_requested"
to = teacher_ps.toaddr
assert to == teacher.email
vars = teacher_ps.template_vars
assert NEW_USER_FNAME == vars["pu_first_name"]
assert NEW_USER_LNAME == vars["pu_last_name"]
assert new_email == vars["pu_email"]
assert "1_rt1" == vars["pu_username"]
assert "team-ABC" == vars["pu_team"]
assert "college the first" == vars["pu_college"]
vars_str = teacher_ps.template_vars_json
assert vcode not in vars_str, "Should not contain the verification code."
示例3: set_user_details
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def set_user_details(requesting_user, userid):
user_to_update = User.create_user(userid)
can_admin = requesting_user.can_administrate(user_to_update)
if request.form.get("media_consent") == 'true' and requesting_user.can_record_media_consent:
if not user_to_update.has_media_consent:
user_to_update.got_media_consent()
notify_ticket_available(user_to_update)
user_to_update.save()
if not can_admin:
return '{}', 200
elif not can_admin:
return AUTHORIZATION_DENIED
assert can_admin
user_to_update = User.create_user(userid)
if request.form.has_key("new_email") and not requesting_user.is_blueshirt:
new_email = request.form["new_email"]
request_new_email(user_to_update, new_email)
# Students aren't allowed to update their own names
# at this point, if the requesting_user is valid, we know it's a self-edit
if not requesting_user.is_student:
fname = request.form.get("new_first_name")
if fname:
user_to_update.set_first_name(fname)
lname = request.form.get("new_last_name")
if lname:
user_to_update.set_last_name(lname)
if request.form.has_key("new_team"):
team = request.form["new_team"]
if (not user_to_update.is_blueshirt) and requesting_user.manages_team(team):
user_to_update.set_team(team)
if request.form.has_key("new_type") and requesting_user.is_teacher and user_to_update != requesting_user:
if request.form["new_type"] == 'student':
user_to_update.make_student()
elif request.form["new_type"] == 'team-leader':
user_to_update.make_teacher()
if request.form.get("withdrawn") == 'true' and not user_to_update.has_withdrawn \
and requesting_user.can_withdraw(user_to_update):
user_to_update.withdraw()
user_to_update.save()
# Do this separately and last because it makes an immediate change
# to the underlying database, rather than waiting for save().
if request.form.has_key("new_password"):
user_to_update.set_password(request.form["new_password"])
return '{}', 200
示例4: test_registration_rq_from_student
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_registration_rq_from_student():
test_helpers.delete_db()
params = {
"username": "student_coll1_1",
"password": "cows",
"first_name": "register",
"last_name": "this.user",
"email": "[email protected]",
"team": "team-ABC",
"college": "college-1",
}
r, data = test_helpers.server_post("/registrations", params)
status = r.status
assert status == 403
assert "YOU_CANT_REGISTER_USERS" in data
assert len(test_helpers.get_registrations()) == 0
try:
created = User.create_user("2_rt1")
assert False, "Should not have created user"
except:
pass
pending = PendingUser("2_rt1")
assert not pending.in_db
test_helpers.assert_no_emails()
示例5: test_registration_email_in_use
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_registration_email_in_use():
params = {
"username": "teacher_coll1",
"password": "facebees",
"first_name": NEW_USER_FNAME,
"last_name": NEW_USER_LNAME,
"email": "[email protected]", # student_coll2_2
"team": "team-ABC",
"college": "college-1",
}
r, data = test_helpers.server_post("/registrations", params)
assert r.status == 403
assert "DETAILS_ALREADY_USED" in data
assert len(test_helpers.get_registrations()) == 0
try:
created = User.create_user("1_rt1")
assert False, "Should not have created user"
except:
pass
pending = PendingUser("1_rt1")
assert not pending.in_db
test_helpers.assert_no_emails()
示例6: test_registration_bad_frist_name
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_registration_bad_frist_name():
params = {"username":"teacher_coll1",
"password":"facebees",
"first_name":NEW_USER_FNAME,
"last_name":'2'+NEW_USER_LNAME,
"email":"[email protected]",
"team":"team-ABC",
"college":"college-1"}
r,data = test_helpers.server_post("/registrations", params)
assert r.status == 403
assert 'BAD_LAST_NAME' in data
assert len(test_helpers.get_registrations()) == 0
try:
created = User.create_user('1_rt1')
assert False, "Should not have created user"
except:
pass
pending = PendingUser('1_rt1')
assert not pending.in_db
test_helpers.assert_no_emails()
示例7: test_registration_name_in_use
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_registration_name_in_use():
params = {"username":"teacher_coll1",
"password":"facebees",
"first_name":'student2', # student_coll1_2
"last_name":'student',
"email":"[email protected]",
"team":"team-ABC",
"college":"college-1"}
r,data = test_helpers.server_post("/registrations", params)
status = r.status
assert status == 403, data
assert 'DETAILS_ALREADY_USED' in data
assert len(test_helpers.get_registrations()) == 0
try:
created = User.create_user('1_ss1')
assert False, "Should not have created user"
except:
pass
pending = PendingUser('1_ss1')
assert not pending.in_db
test_helpers.assert_no_emails()
示例8: test_college_set_in_user
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_college_set_in_user():
u = User.create_user('st_user1')
u.set_college(NEW_COLLEGE_NAME)
u.save()
u_colleges = u.colleges
assert set(u_colleges) == set([NEW_COLLEGE_NAME])
示例9: test_team_set_in_user
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_team_set_in_user():
u = User.create_user('st_user1')
u.set_team(NEW_TEAM_NAME)
u.save()
u_teams = [t.name for t in u.teams]
assert set(u_teams) == set([NEW_TEAM_NAME])
示例10: test_college_set_in_db
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_college_set_in_db():
u = User.create_user('st_user1')
u.set_college(NEW_COLLEGE_NAME)
u.save()
sru = srusers.user('st_user1')
sru_groups = sru.groups()
assert set(sru_groups) == set([NEW_COLLEGE_NAME, 'st_other_group'])
示例11: test_team_set_in_db
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_team_set_in_db():
u = User.create_user('st_user1')
u.set_team(NEW_TEAM_NAME)
u.save()
sru = srusers.user('st_user1')
sru_groups = sru.groups()
assert set(sru_groups) == set([NEW_TEAM_NAME, 'st_other_group'])
示例12: activate_account
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def activate_account(username, code):
"""
Verifies to the system that an email address exists, and that the related
account should be made into a full account.
Expected to be used only by users clicking links in account-activation emails.
Not part of the documented API.
"""
pu = PendingUser(username)
if not pu.in_db:
return "No such user account", 404
if pu.age > timedelta(days = 2):
return "Request not valid", 410
if pu.verify_code != code:
return "Invalid verification code", 403
log_action('activating user', pu)
from libnemesis import srusers
new_pass = srusers.users.GenPasswd()
u = User(username)
u.set_email(pu.email)
u.set_team(pu.team)
u.set_college(pu.college)
u.set_password(new_pass)
u.make_student()
u.save()
# let the team-leader know
rq_user = User.create_user(pu.teacher_username)
email_vars = { 'name': rq_user.first_name,
'au_username': username,
'au_first_name': u.first_name,
'au_last_name': u.last_name
}
mailer.email_template(rq_user.email, 'user_activated_team_leader', email_vars)
pu.delete()
html = open(PATH + "/templates/activate.html").read()
replacements = { 'first_name': u.first_name
, 'last_name': u.last_name
, 'password': new_pass
, 'email': u.email
, 'username': username
, 'root': url_for('.index')
}
html = html.format(**replacements)
return html, 200
示例13: test_make_student
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_make_student():
u = User.create_user('st_user1')
u.make_student()
u.save()
assert not u.is_teacher
students = srusers.group('students').members
assert 'st_user1' in students
teachers = srusers.group('teachers').members
assert 'st_user1' not in teachers
示例14: test_details_dictionary_for_team_leader_member
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def test_details_dictionary_for_team_leader_member():
u = User.create_user("teacher_coll1", "facebees")
data = assert_college_1_details_dictionary_for(u)
expected_users = [
"teacher_coll1",
"student_coll1_1",
"student_coll1_2",
"withdrawn_student",
]
actual_users = data["users"]
assert actual_users == expected_users
示例15: user_details
# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import create_user [as 别名]
def user_details(userid):
ah = AuthHelper(request)
if ah.auth_will_succeed and ah.user.can_administrate(userid):
user = User.create_user(userid)
details = user.details_dictionary_for(ah.user)
email_change_rq = PendingEmail(userid)
if email_change_rq.in_db:
new_email = email_change_rq.new_email
if new_email != details['email']:
details['new_email'] = new_email
return json.dumps(details), 200
else:
return ah.auth_error_json, 403