本文整理汇总了Python中larper.UserSession类的典型用法代码示例。如果您正苦于以下问题:Python UserSession类的具体用法?Python UserSession怎么用?Python UserSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
def authenticate(self, request=None, assertion=None):
"""Authentication based on BrowserID assertion.
``django.contrib.auth`` backend that is SASL and BrowserID
savy. Uses session to maintain assertion over multiple
requests.
"""
if not (request and assertion):
return None
store_assertion(request, assertion)
directory = UserSession(request)
with statsd.timer('larper.sasl_bind_time'):
(registered, details) = _get_registered_user(directory, request)
if registered:
person = directory.get_by_unique_id(details)
defaults = dict(username=person.username,
first_name=person.first_name,
last_name=person.last_name,
email=person.username)
user, created = User.objects.get_or_create(username=person.username,
defaults=defaults)
if created:
user.set_unusable_password()
user.save()
return user
return None
示例2: _edit_profile
def _edit_profile(request, unique_id, new_account):
ldap = UserSession.connect(request)
person = ldap.get_by_unique_id(unique_id)
del_form = forms.DeleteForm(
initial=dict(unique_id=unique_id))
if person:
if request.method == 'POST':
form = forms.ProfileForm(request.POST, request.FILES)
if form.is_valid():
ldap = UserSession.connect(request)
ldap.update_person(unique_id, form.cleaned_data)
ldap.update_profile_photo(unique_id, form.cleaned_data)
if new_account:
return redirect('confirm_register')
else:
return redirect('profile', unique_id)
else:
initial = dict(first_name=person.first_name,
last_name=person.last_name,
biography=person.biography,)
initial.update(_get_services_fields(ldap, unique_id))
form = forms.ProfileForm(initial)
return jingo.render(request, 'phonebook/edit_profile.html', dict(
form=form,
delete_form=del_form,
person=person,
registration_flow=new_account,
))
else:
raise Http404
示例3: _view
def _view(request, *args, **kwargs):
(asst_hsh, assertion) = get_assertion(request)
if not asst_hsh or not assertion:
log.info("No assertion in session")
return _redirect(request, login_url, redirect_field_name)
try:
directory = UserSession(request)
(registered, unique_id) = directory.registered_user()
except ldap.OTHER:
statsd.incr('browserid.session_timedout')
log.info("Backend session timed out, clearing session assertion")
return _redirect(request, login_url, redirect_field_name)
return view_func(request, *args, **kwargs)
示例4: _profile
def _profile(request, person, use_master):
vouch_form = None
ldap = UserSession.connect(request)
if person.voucher_unique_id:
try:
# Stale data okay
person.voucher = ldap.get_by_unique_id(person.voucher_unique_id)
except NO_SUCH_PERSON:
# Bug#688788 Invalid voucher is okay
person.voucher = BAD_VOUCHER
elif request.user.unique_id != person.unique_id:
voucher = request.user.unique_id
vouch_form = forms.VouchForm(initial=dict(
voucher=voucher,
vouchee=person.unique_id))
services = ldap.profile_service_ids(person.unique_id, use_master)
person.irc_nickname = None
if MOZILLA_IRC_SERVICE_URI in services:
person.irc_nickname = services[MOZILLA_IRC_SERVICE_URI]
del services[MOZILLA_IRC_SERVICE_URI]
return jingo.render(request, 'phonebook/profile.html',
dict(absolutify=absolutify,
person=person,
vouch_form=vouch_form,
services=services))
示例5: photo
def photo(request, unique_id):
ldap = UserSession.connect(request)
image = ldap.profile_photo(unique_id)
if image:
return HttpResponse(image, mimetype="image/jpeg")
else:
return redirect('/media/img/unknown.png')
示例6: f
def f():
if not hasattr(user, 'person'):
directory = UserSession.connect(request)
# Stale data okay
user.person = directory.get_by_unique_id(user.unique_id)
# Presence of voucher DN is enough, don't validate
return bool(user.person.voucher_unique_id)
示例7: vouch_person
def vouch_person(self, new_unique_id):
request = _mock_request('/en-US/', username='[email protected]')
directory = self.d = UserSession.connect(request)
ok_(directory.record_vouch('7f3a67u000001', new_unique_id))
newbie = directory.get_by_unique_id(new_unique_id)
eq_('7f3a67u000001', newbie.voucher_unique_id)
示例8: _profile
def _profile(request, person, use_master):
vouch_form = None
ldap = UserSession.connect(request)
if person.voucher_unique_id or cache.get('vouched_' + person.unique_id):
try:
# Stale data okay
person.voucher = ldap.get_by_unique_id(person.voucher_unique_id)
except NO_SUCH_PERSON:
# Bug#688788 Invalid voucher is okay
person.voucher = BAD_VOUCHER
elif request.user.unique_id != person.unique_id:
voucher = request.user.unique_id
vouch_form = forms.VouchForm(initial=dict(
vouchee=person.unique_id))
services = ldap.profile_service_ids(person.unique_id, use_master)
person.irc_nickname = None
if MOZILLA_IRC_SERVICE_URI in services:
person.irc_nickname = services[MOZILLA_IRC_SERVICE_URI]
del services[MOZILLA_IRC_SERVICE_URI]
# Get user groups from their profile.
groups = person.get_profile().groups.all()
data = dict(person=person, vouch_form=vouch_form, services=services,
groups=groups)
return render(request, 'phonebook/profile.html', data)
示例9: _with_temp_user
def _with_temp_user(fn):
"""
Runs a function in the context of a newly created user.
It will cleanup the user after fn is run, unless it
has already been deleted.
fn - A callable function. First parameter should be
a unique_id string.
"""
regi = RegistrarSession.connect(
_mock_request('/en-US/search?q=David'))
username = '%[email protected]' % str(uuid4())[0:8]
data = dict(first_name='Jane', last_name='Doe',
email=username, password='secret password',
biography='Keeping it real.',
irc_nickname='',
irc_nickname_unique_id='')
new_unique_id = regi.create_person(data)
fn(new_unique_id)
directory = UserSession.connect(_mock_request('/en-US/search?q=David'))
try:
directory.get_by_unique_id(new_unique_id)
admin = AdminSession.connect(_mock_request('/en-US/search?q=David'))
admin.delete_person(new_unique_id)
except:
pass
finally:
pass
示例10: test_update_person
def test_update_person(self):
unique_id = '7f3a67u000098'
username = '[email protected]'
request = _mock_request('/en-US/search?q=David',
username=username,
unique_id='7f3a67u000098')
directory = self.d = UserSession.connect(request)
amandeep = directory.get_by_unique_id(unique_id)
first_name = amandeep.first_name
last_name = amandeep.last_name
eq_('Amandeep', first_name)
eq_('McIlrath', last_name)
eq_('Amandeep McIlrath', amandeep.full_name)
form_data = dict(first_name='Deep',
last_name=last_name,
biography='',
irc_nickname='',
irc_nickname_unique_id='',)
ok_(directory.update_person(unique_id, form_data))
amandeep = directory.get_by_unique_id(unique_id)
eq_('Deep', amandeep.first_name, 'First name edit worked')
eq_(last_name, amandeep.last_name, 'No change')
form_data['first_name'] = first_name
ok_(directory.update_person(unique_id, form_data))
amandeep = directory.get_by_unique_id(unique_id)
eq_(first_name, amandeep.first_name)
示例11: test_search_by_irc_nick
def test_search_by_irc_nick(self):
request = _mock_request('/en-US/')
directory = UserSession.connect(request)
rs = directory.search("andrew_f")
eq_(1, len(rs))
person = rs[0]
eq_('Andrew Findlay', person.full_name)
eq_('8', person.unique_id)
示例12: vouch
def vouch(request):
form = forms.VouchForm(request.POST)
if form.is_valid():
ldap = UserSession.connect(request)
data = form.cleaned_data
vouchee = data.get('vouchee')
ldap.record_vouch(data.get('voucher'), vouchee)
return redirect(reverse('profile', args=[vouchee]))
示例13: test_person_with_no_given_name
def test_person_with_no_given_name(self):
request = _mock_request('/en-US/')
directory = self.d = UserSession.connect(request)
matt = directory.get_by_unique_id("7f3a67u000002")
eq_('[email protected]', matt.username)
eq_('7f3a67u000002', matt.unique_id)
eq_('', matt.first_name)
示例14: test_search_is_fun
def test_search_is_fun(self):
request = _mock_request('/en-US/search?q=David')
directory = self.d = UserSession.connect(request)
rs = directory.search("Bridget Hill")
eq_(1, len(rs))
rs = directory.search("[email protected]")
eq_(1, len(rs))
示例15: photo
def photo(request, unique_id):
needs_master = (request.user.unique_id == unique_id)
ldap = UserSession.connect(request)
image = ldap.profile_photo(unique_id, use_master=needs_master)
if image:
return HttpResponse(image, mimetype="image/jpeg")
else:
return redirect('/media/img/unknown.png')