本文整理汇总了Python中ckan.model.User.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_name方法的具体用法?Python User.by_name怎么用?Python User.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.model.User
的用法示例。
在下文中一共展示了User.by_name方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
if not ('login' in identity and 'password' in identity):
return None
login = identity['login']
user = User.by_name(login)
## HDX HACK ##
if user is None:
users = User.by_email(login)
try:
user = users[0]
except:
user = None
## END HDX HACK ##
if user is None:
log.debug('Login failed - username %r not found', login)
elif not user.is_active():
log.debug('Login as %r failed - user isn\'t active', login)
elif not user.validate_password(identity['password']):
log.debug('Login as %r failed - password not valid', login)
else:
return user.name
return None
示例2: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
'''
Authenticate and extract identity from OAuth2 tokens
'''
request = Request(environ)
log.debug('Repoze OAuth authenticate')
if 'oauth2.token' in identity:
oauth = OAuth2Session(
self.client_id,
token=identity['oauth2.token'])
profile_response = oauth.get(self.profile_api_url)
profile_data = profile_response.json()
if not profile_data['authenticated']:
return None
user_data = profile_data['principal']
user = User.by_name(user_data['username'])
if user is None:
user = User()
user.name = user_data['username']
user.email = user_data['email']
user.fullname = u"{} {}".format(
user_data['name'], user_data['surname'])
user.save()
user.activate()
user.save()
identity.update({'repoze.who.userid': user.name})
self._redirect_from_callback(request, identity)
return user.name
return None
示例3: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
if not 'login' in identity or not 'password' in identity:
return None
user = User.by_name(identity.get('login'))
if user is None:
return None
if user.validate_password(identity.get('password')):
return user.name
return None
示例4: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
'''Fetch the user given its username in identity'''
if 'username' in identity:
user = User.by_name(identity['username'])
if user is None:
return None
else:
identity.update({'repoze.who.userid': user.name})
return user.name
return None
示例5: test_authenticate_step_two
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def test_authenticate_step_two(self):
plugin = self._makeOne()
environ = {"REQUEST_METHOD": "GET", "QUERY_STRING": "oauth_token=foo", "ckan.who.oauth.challenge": "1"}
identity = plugin.identify(environ)
username = identity.get("repoze.who.userid")
self.assertEqual(username, "boz")
user = User.by_name("boz")
self.assertEqual(user.email, "[email protected]")
groups = Session.query(AuthorizationGroup).filter(AuthorizationGroup.users.contains(user))
self.assertEqual(groups.count(), 1)
示例6: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
if not 'login' in identity or not 'password' in identity:
return None
user = User.by_name(identity.get('login'))
if user is None:
log.debug('Login failed - username %r not found', identity.get('login'))
return None
if user.validate_password(identity.get('password')):
return user.name
log.debug('Login as %r failed - password not valid', identity.get('login'))
return None
示例7: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
if 'repoze.who.plugins.openid.userid' in identity:
openid = identity.get('repoze.who.plugins.openid.userid')
user = User.by_openid(openid)
if user is None:
# TODO: Implement a mask to ask for an alternative user
# name instead of just using the OpenID identifier.
name = identity.get('repoze.who.plugins.openid.nickname')
if not User.check_name_available(name):
name = openid
if User.by_name(name):
name = openid
user = User(openid=openid, name=name,
fullname=identity.get('repoze.who.plugins.openid.fullname'),
email=identity.get('repoze.who.plugins.openid.email'))
Session.add(user)
Session.commit()
Session.remove()
return user.name
return None
示例8: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
def authenticate(self, environ, identity):
if not 'login' in identity or not 'password' in identity:
return None
user = User.by_name(identity.get('login'))
if user is None:
log.debug('Login failed - username %r not found', identity.get('login'))
return None
qgovUser = Session.query(QGOVUser).filter_by(name = identity.get('login')).first()
if qgovUser.login_attempts >= 10:
log.debug('Login as %r failed - account is locked', identity.get('login'))
elif user.validate_password(identity.get('password')):
# reset attempt count to 0
qgovUser.login_attempts = 0
Session.commit()
return user.name
else:
log.debug('Login as %r failed - password not valid', identity.get('login'))
qgovUser.login_attempts += 1
Session.commit()
return None