本文整理匯總了Python中pyshop.models.User類的典型用法代碼示例。如果您正苦於以下問題:Python User類的具體用法?Python User怎麽用?Python User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render
def render(self):
login_url = resource_url(self.request.context, self.request, 'login')
referrer = self.request.url
# never use the login form itself as came_from
if referrer == login_url:
referrer = '/'
came_from = self.request.params.get('came_from', referrer)
login = self.request.params.get('user.login', '')
if 'form.submitted' in self.request.params:
password = self.request.params.get('user.password', u'')
if password:
if User.by_ldap_credentials(
self.session, login, password,
self.request.registry.settings) is not None:
log.info('login %r succeed', login)
headers = remember(self.request, login)
return HTTPFound(location=came_from,
headers=headers)
if User.by_credentials(
self.session, login, password) is not None:
log.info('login %r succeed', login)
headers = remember(self.request, login)
return HTTPFound(location=came_from,
headers=headers)
return {'came_from': came_from,
'user': User(login=login),
}
示例2: authenticated_userid
def authenticated_userid(self, request):
auth = request.environ.get('HTTP_AUTHORIZATION')
try:
authmeth, auth = auth.split(' ', 1)
except AttributeError: # not enough values to unpack
return None
if authmeth.lower() != 'basic':
return None
try:
# Python 3's string is already unicode
auth = base64.b64decode(auth.strip())
except binascii.Error: # can't decode
return None
if not isinstance(auth, unicode):
auth = auth.decode('utf-8')
try:
login, password = auth.split(':', 1)
except ValueError: # not enough values to unpack
return None
if User.by_credentials(DBSession(), login, password):
return login
if User.by_ldap_credentials(DBSession(), login, password,request.registry.settings):
return login
return None
示例3: render
def render(self):
package = Package.by_name(self.session, self.request.matchdict["package_name"])
if not package:
raise HTTPNotFound()
if "form.refresh_package" in self.request.params:
package.update_at = None
self.session.add(package)
owners = dict((usr.login, usr) for usr in package.owners)
can_edit_role = self.login in owners.keys() and package.local
if "form.add_role" in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params["login"])
if user and user.has_permission("upload_releasefile"):
if self.request.params["role"] == "owner":
if user.login not in owners:
package.owners.append(user)
else:
maintainers = [usr.login for usr in package.owners]
if user.login not in maintainers:
package.maintainers.append(user)
self.session.add(package)
if "form.remove_maintainer" in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params["login"])
if user:
maintainers = dict((usr.login, usr) for usr in package.maintainers)
if user.login in maintainers:
package.maintainers.remove(maintainers[user.login])
self.session.add(package)
if "form.remove_owner" in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params["login"])
if user:
if user.login in owners:
package.owners.remove(owners[user.login])
self.session.add(package)
if "release_version" in self.request.matchdict:
release = Release.by_version(self.session, package.name, self.request.matchdict["release_version"])
else:
release = package.sorted_releases[0]
return {u"package": package, u"release": release, u"can_edit_role": can_edit_role}
示例4: authenticated_userid
def authenticated_userid(self, request):
auth = request.environ.get('HTTP_AUTHORIZATION')
try:
authmeth, auth = auth.split(' ', 1)
except AttributeError as ValueError: # not enough values to unpack
return None
if authmeth.lower() != 'basic':
return None
try:
# Python 3's string is already unicode
auth = auth.strip().decode('base64')
if sys.version_info[0] == 2:
auth = unicode(auth)
except binascii.Error: # can't decode
return None
try:
login, password = auth.split(':', 1)
except ValueError: # not enough values to unpack
return None
if User.by_credentials(DBSession(), login, password):
return login
return None
示例5: test_update_post_ok
def test_update_post_ok(self):
from pyshop.models import User
from pyshop.views.user import Edit
view = Edit(
self.create_request(
{
"form.submitted": u"1",
"user.login": u"root",
"user.firstname": u"Admin",
"user.lastname": u"Istrator",
}
)
)()
self.assertIsRedirect(view)
self.session.flush()
admin = User.by_credentials(self.session, u"root", u"changeme")
self.assertIsInstance(admin, User)
self.assertEqual(admin.login, u"root")
self.assertEqual(admin.firstname, u"Admin")
self.assertEqual(admin.lastname, u"Istrator")
admin.login = u"admin"
admin.password = u"changeme"
admin.firstname = None
admin.lastname = None
self.session.add(admin)
示例6: _create_release
def _create_release(self, package, data):
release = Release(package=package,
summary=data.get('summary'),
version=data.get('version'),
stable_version=data.get('stable_version'),
home_page=data.get('home_page'),
license=data.get('license'),
description=data.get('description'),
keywords=data.get('keywords'),
platform=data.get('platform'),
download_url=data.get('download_url'),
bugtrack_url=data.get('bugtrack_url'),
docs_url=data.get('docs_url'),
)
if data.get('author'):
author = User.by_login(self.session, data['author'], local=False)
if not author:
author = User(login=data['author'],
local=False,
email=data.get('author_email'))
self.session.add(author)
release.author = author
self.session.flush()
if data.get('maintainer'):
maintainer = User.by_login(self.session, data['maintainer'],
local=False)
if not maintainer:
maintainer = User(login=data['maintainer'],
local=False,
email=data.get('maintainer_email'))
self.session.add(maintainer)
release.maintainer = maintainer
self.session.flush()
for name in data.get('classifiers', []):
classifier = Classifier.by_name(self.session, name)
while classifier:
release.classifiers.append(classifier)
if classifier not in package.classifiers:
package.classifiers.append(classifier)
classifier = classifier.parent
self.session.flush()
return release
示例7: test_post_delete_ok
def test_post_delete_ok(self):
from pyshop.views.account import Delete
from pyshop.models import User
view = Delete(self.create_request({'form.submitted': '1',
},
matchdict={'user_id': self.account_id
},))()
self.assertIsRedirect(view)
account = User.by_id(self.session, self.account_id)
self.assertIsNone(account)
self.account_todelete = []
示例8: test_change_password_post_ok
def test_change_password_post_ok(self):
from pyshop.models import User
from pyshop.views.user import ChangePassword as ChangePwd
view = ChangePwd(self.create_request({'form.submitted': u'1',
'current_password': u'changeme',
'user.password': u'newpassw',
'confirm_password': u'newpassw',
}))()
admin = User.by_credentials(self.session, u'admin', u'newpassw')
self.assertIsInstance(admin, User)
admin.password = u'changeme'
self.session.add(admin)
示例9: authbasic
def authbasic(request):
"""
Authentification basic, Upload pyshop repository access
"""
if len(request.environ.get('HTTP_AUTHORIZATION','')) > 0:
auth = request.environ.get('HTTP_AUTHORIZATION')
scheme, data = auth.split(None, 1)
assert scheme.lower() == 'basic'
data = base64.b64decode(data)
if not isinstance(data, unicode):
data = data.decode('utf-8')
username, password = data.split(':', 1)
if User.by_ldap_credentials(DBSession(), username, password, request.registry.settings):
return HTTPFound(location=request.url)
if User.by_credentials(DBSession(), username, password):
return HTTPFound(location=request.url)
return Response(status=401,
headerlist=[(b'WWW-Authenticate',
b'Basic realm="pyshop repository access"'
)],
)
示例10: test_change_password_post_ko_unchanged
def test_change_password_post_ko_unchanged(self):
from pyshop.models import User
from pyshop.views.user import ChangePassword as ChangePwd
view = ChangePwd(self.create_request({'form.submitted': u'1',
'current_password': u'changeme',
'user.password': u'changeme',
'confirm_password': u'changeme',
}))()
self.assertEqual(view['errors'],
[u'password is inchanged'])
admin = User.by_credentials(self.session, u'admin', u'changeme')
self.assertIsInstance(admin, User)
示例11: test_change_password_post_ko_not_matched
def test_change_password_post_ko_not_matched(self):
from pyshop.models import User
from pyshop.views.user import ChangePassword as ChangePwd
view = ChangePwd(self.create_request({'form.submitted': u'1',
'current_password': u'CHANGEME',
'user.password': u'newpassw',
'confirm_password': u'NEWPASSW',
}))()
self.assertEqual(view['errors'],
[u'current password is not correct',
u'passwords do not match'])
admin = User.by_credentials(self.session, u'admin', u'changeme')
self.assertIsInstance(admin, User)
示例12: validate
def validate(self, model, errors):
r = self.request
if not User.by_credentials(self.session, model.login,
r.params['current_password']):
errors.append(_(u'current password is not correct'))
elif r.params['user.password'] == r.params['current_password']:
errors.append(_(u'password is inchanged'))
if r.params['user.password'] != r.params['confirm_password']:
errors.append(_(u'passwords do not match'))
return len(errors) == 0
示例13: test_post_create_ok
def test_post_create_ok(self):
from pyshop.views.account import Create
from pyshop.models import User, Group
view = Create(self.create_request({'form.submitted': u'1',
'user.login': u'dummy_new',
'user.password': u'secret',
'user.firstname': u'',
'user.lastname': u'',
'user.email': u'[email protected]',
'confirm_password': u'secret',
'groups': [u'1', u'2']
}))()
self.assertIsRedirect(view)
self.account_todelete.append(User.by_login(self.session,
u'dummy_new').id)
示例14: authbasic
def authbasic(request):
"""
Authentification basic, Upload pyshop repository access
"""
if len(request.environ.get('HTTP_AUTHORIZATION','')) > 0:
auth = request.environ.get('HTTP_AUTHORIZATION')
scheme, data = auth.split(None, 1)
assert scheme.lower() == 'basic'
username, password = data.decode('base64').split(':', 1)
if User.by_credentials(DBSession(), username, password):
return HTTPFound(location=request.url)
return Response(status=401,
headerlist=[('WWW-Authenticate',
('Basic realm="%s"' %
_('pyshop repository access')).encode('utf-8')
)],
)
示例15: test_change_password_post_ko_unchanged
def test_change_password_post_ko_unchanged(self):
from pyshop.models import User
from pyshop.views.user import ChangePassword as ChangePwd
view = ChangePwd(
self.create_request(
{
"form.submitted": u"1",
"current_password": u"changeme",
"user.password": u"changeme",
"confirm_password": u"changeme",
}
)
)()
self.assertEqual(view["errors"], [u"password is inchanged"])
admin = User.by_credentials(self.session, u"admin", u"changeme")
self.assertIsInstance(admin, User)