本文整理汇总了Python中bespin.database.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_data
def _init_data():
global macgyver, someone_else, murdoc
config.activate_profile()
fsroot = config.c.fsroot
if fsroot.exists() and fsroot.basename() == "testfiles":
fsroot.rmtree()
fsroot.makedirs()
app.reset()
Base.metadata.drop_all(bind=config.c.dbengine)
Base.metadata.create_all(bind=config.c.dbengine)
s = config.c.session_factory()
someone_else = User.create_user("SomeoneElse", "", "[email protected]")
murdoc = User.create_user("Murdoc", "", "[email protected]")
otherproject = get_project(someone_else, someone_else,
"otherproject", create=True)
otherproject.save_file('foo', 'Just a file to reserve a project')
app.post("/register/new/MacGyver",
dict(password="richarddean", email="[email protected]"))
macgyver = User.find_user("MacGyver")
示例2: lost
def lost(request, response):
"""Generates lost password email messages"""
email = request.POST.get('email')
username = request.POST.get('username')
if username:
user = User.find_user(username)
if not user:
raise BadRequest("Unknown user: " + username)
verify_code = _get_password_verify_code(user)
change_url = c.base_url + "?pwchange=%s;%s" % (username, verify_code)
context = dict(username=username, base_url=c.base_url,
change_url=change_url)
send_email_template(user.email, "Requested password change for " + c.base_url,
"lost_password.txt", context)
elif email:
users = User.find_by_email(email)
context = dict(email=email,
usernames=[dict(username=user.username) for user in users],
base_url=c.base_url)
send_email_template(email, "Your username for " + c.base_url,
"lost_username.txt", context)
else:
raise BadRequest("Username or email is required.")
return response()
示例3: _reset
def _reset():
Base.metadata.drop_all(bind=config.c.dbengine)
Base.metadata.create_all(bind=config.c.dbengine)
fsroot = config.c.fsroot
if fsroot.exists() and fsroot.basename() == "testfiles":
fsroot.rmtree()
fsroot.makedirs()
global session
session = config.c.session_factory()
num_users = session.query(User).count()
assert_equals(num_users, 0)
session.commit()
global mattb, zuck, tom, ev, joe
mattb = User.create_user("mattb", "mattb", "mattb")
zuck = User.create_user("zuck", "zuck", "zuck")
tom = User.create_user("tom", "tom", "tom")
ev = User.create_user("ev", "ev", "ev")
joe = User.create_user("joe", "joe", "joe")
group = joe.add_group("group")
group.add_member(mattb)
group.add_member(zuck)
group.add_member(tom)
group.add_member(ev)
global app
app = controllers.make_app()
app = BespinTestApp(app)
app.post("/register/login/joe", dict(password="joe"))
示例4: test_bad_login_yields_401
def test_bad_login_yields_401():
s = _get_session(True)
User.create_user("BillBixby", "hulkrulez", "[email protected]")
app = controllers.make_app()
app = BespinTestApp(app)
resp = app.post("/register/login/BillBixby",
dict(password="NOTHULK"), status=401)
示例5: check_access
def check_access(self, name, handle):
"""Check to see what level of access user has over an owner's project.
Returns one of: Access.Denied, Access.ReadOnly or Access.ReadWrite
Note that if user==owner then no check of project_name is performed, and
Access.ReadWrite is returned straight away"""
try:
(user_name, project_name, path) = name.split("/", 2)
requester = get_username_from_handle(handle)
user = User.find_user(requester)
owner = User.find_user(user_name)
if user == owner:
return Access.ReadWrite
if user != owner:
if owner.is_project_shared(project_name, user, require_write=True):
return Access.ReadWrite
if owner.is_project_shared(project_name, user, require_write=False):
return Access.ReadOnly
else:
return Access.Denied
except:
log.exception("Error in Persister.check_access() for name=%s, handle=%s",
name, handle)
return Access.Denied
示例6: test_delete_setting
def test_delete_setting():
resp = app.post('/settings/', {'newone' : 'hi there'})
resp = app.delete('/settings/newone')
user = User.find_user('BillBixby')
session.expunge(user)
user = User.find_user('BillBixby')
assert 'newone' not in user.settings
示例7: test_login_without_cookie
def test_login_without_cookie():
s = _get_session(True)
User.create_user("BillBixby", "hulkrulez", "[email protected]")
app = controllers.make_app()
app = BespinTestApp(app)
resp = app.post("/register/login/BillBixby",
dict(password="hulkrulez"))
assert resp.cookies_set['auth_tkt']
示例8: test_setup
def test_setup(request, response):
for name in test_users:
user = User.find_user(name)
if (user == None):
user = User.create_user(name, name, name)
response.body = ""
response.content_type = "text/plain"
return response()
示例9: test_create_new_user
def test_create_new_user():
s = _get_session(True)
num_users = s.query(User).count()
assert num_users == 0
user = User.create_user("BillBixby", "hulkrulez", "[email protected]")
assert len(user.uuid) == 36
num_users = s.query(User).count()
assert num_users == 1
users = User.find_by_email("[email protected]")
assert users[0].username == "BillBixby"
示例10: setup_module
def setup_module(module):
global app, session
config.set_profile('test')
config.activate_profile()
Base.metadata.drop_all(bind=config.c.dbengine)
Base.metadata.create_all(bind=config.c.dbengine)
session = config.c.session_factory()
User.create_user("BillBixby", "", "[email protected]")
app = controllers.make_app()
app = BespinTestApp(app)
app.post("/register/login/BillBixby", dict(password=""))
示例11: password_change
def password_change(request, response):
"""Changes a user's password."""
username = request.kwargs.get('username')
user = User.find_user(username)
if not user:
raise BadRequest("Unknown user: " + username)
verify_code = _get_password_verify_code(user)
code = request.POST.get('code')
if verify_code != code:
raise BadRequest("Invalid verification code for password change.")
user.password = User.generate_password(request.POST['newPassword'])
return response()
示例12: get_user
def get_user(name):
user = User.find_user(name)
if user == None:
user = User.create_user(name, name, name + "@foo.com")
session.commit()
info("Created user called '" + name + "'")
try:
filesystem.get_project(user, user, "BespinSettings")
except:
settings = filesystem.get_project(user, user, "BespinSettings", create=True)
settings.install_template('usertemplate')
info("Created BespinSettings project for '" + name + "'")
return user
示例13: test_create_duplicate_user
def test_create_duplicate_user():
s = _get_session(True)
u = User.create_user("BillBixby", "somepass", "[email protected]")
s.commit()
original_password = u.password
try:
User.create_user("BillBixby", "otherpass", "[email protected]")
assert False, "Should have gotten a ConflictError"
except ConflictError:
s.rollback()
s = _get_session(False)
user = User.find_user("BillBixby")
assert user.password == original_password, "Password should not have changed"
示例14: _split_path
def _split_path(self, path, handle):
"""Extract user, owner, project name, and path and return it as a tuple."""
requester = get_username_from_handle(handle)
user = User.find_user(requester)
if path[0] == "/":
path = path[1:]
result = path.split('/', 1)
parts = result[0].partition('+')
if parts[1] == '':
result.insert(0, user)
else:
result.insert(0, User.find_user(parts[0]))
result[1] = parts[2]
result.insert(0, user)
return result
示例15: check_access
def check_access(self, name):
from bespin.database import User, get_project
(user_name, project_name, path) = name.split("/", 2)
user = User.find_user(user_name)
parts = project_name.partition('+')
if parts[1] == '':
owner = user
else:
owner = User.find_user(parts[0])
project_name = parts[2]
project = get_project(user, owner, project_name)
return (project, path)