本文整理汇总了Python中placard.client.LDAPClient.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python LDAPClient.get_user方法的具体用法?Python LDAPClient.get_user怎么用?Python LDAPClient.get_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类placard.client.LDAPClient
的用法示例。
在下文中一共展示了LDAPClient.get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_activate_user
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def test_delete_activate_user(self):
logged_in = self.client.login(username='kgsuper', password='aq12ws')
user = Person.objects.get(user__username='kgtestuser3')
self.assertEqual(user.is_active, True)
self.assertEqual(user.project_set.count(), 1)
self.assertEqual(user.useraccount_set.count(), 1)
self.assertEqual(user.useraccount_set.all()[0].date_deleted, None)
lcon = LDAPClient()
luser = lcon.get_user('uid=kgtestuser3')
self.assertEqual(luser.givenName, 'Test')
response = self.client.get(reverse('admin_delete_user', args=[user.username]))
self.failUnlessEqual(response.status_code, 200)
# Test deleting
response = self.client.post(reverse('admin_delete_user', args=[user.username]))
self.failUnlessEqual(response.status_code, 302)
user = Person.objects.get(user__username='kgtestuser3')
self.assertEqual(user.is_active, False)
self.assertEqual(user.project_set.count(), 0)
self.assertEqual(user.useraccount_set.count(), 1)
self.assertEqual(user.useraccount_set.all()[0].date_deleted, datetime.date.today())
self.failUnlessRaises(placard_exceptions.DoesNotExistException, lcon.get_user, 'uid=kgtestuser3')
# Test activating
response = self.client.post(reverse('admin_activate_user', args=[user.username]))
self.failUnlessEqual(response.status_code, 302)
user = Person.objects.get(user__username='kgtestuser3')
self.assertEqual(user.is_active, True)
luser = lcon.get_user('uid=kgtestuser3')
self.assertEqual(luser.givenName, 'Test')
示例2: user_exists
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def user_exists(self, username):
conn = LDAPClient()
try:
conn.get_user('uid=%s' % username)
return True
except DoesNotExistException:
return False
示例3: is_locked
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def is_locked(self, person):
super(PersonalDataStore, self).is_locked(person)
conn = LDAPClient()
try:
conn.get_user('uid=%s' % person.username)
except DoesNotExistException:
return True
output = conn.ldap_search(settings.LDAP_USER_BASE,
'uid=%s' % person.username,
retrieve_attributes=['nsAccountLock'])
if output[0][1]:
return True
return False
示例4: test_add_remove_user_to_project
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def test_add_remove_user_to_project(self):
lcon = LDAPClient()
luser = lcon.get_user('uid=kgtestuser2')
self.client.login(username='kgsuper', password='aq12ws')
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.users.count(), 1)
response = self.client.get(reverse('kg_project_detail', args=[project.pid]))
self.failUnlessEqual(response.status_code, 200)
ldap_members = LDAPClient().get_group_members('cn=%s' % project.pid)
self.assertFalse(luser in ldap_members)
new_user = Person.objects.get(user__username='kgtestuser2')
response = self.client.post(reverse('kg_project_detail', args=[project.pid]), { 'person': new_user.id} )
self.failUnlessEqual(response.status_code, 302)
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.users.count(), 2)
ldap_members = LDAPClient().get_group_members('cn=%s' % project.pid)
self.assertTrue(luser in ldap_members)
# remove user
response = self.client.post(reverse('kg_remove_project_member', args=[project.pid, new_user.username]))
self.failUnlessEqual(response.status_code, 302)
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.users.count(), 1)
ldap_members = LDAPClient().get_group_members('cn=%s' % project.pid)
self.assertFalse(luser in ldap_members)
示例5: create_account
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def create_account(self, person, default_project):
ua = super(AccountDataStore, self).create_account(person, default_project)
conn = LDAPClient()
ldap_attrs = __import__(settings.LDAP_ATTRS, {}, {}, [''])
data = conn.get_user('sAMAccountName=%s' % person.username).__dict__
data['cluster_account'] = True
data['objectClass'] = settings.ACCOUNT_OBJECTCLASS
data['default_project'] = default_project
data['person'] = person
conn.update_user(
'sAMAccountName=%s' % person.username,
objectClass=settings.ACCOUNT_OBJECTCLASS,
uidNumber=ldap_attrs.GENERATED_USER_ATTRS['uidNumber'](data),
gidNumber=ldap_attrs.GENERATED_USER_ATTRS['gidNumber'](data),
unixHomeDirectory=ldap_attrs.GENERATED_USER_ATTRS['unixHomeDirectory'](data),
loginShell=ldap_attrs.GENERATED_USER_ATTRS['loginShell'](data),
uid=person.username,
msSFU30Name=person.username,
msSFU30NisDomain=settings.LDAP_NISDOMAIN,
unixUserPassword='ABCD!efgh12345$67890',
)
del(conn)
return ua
示例6: loginShell
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def loginShell(self):
conn = LDAPClient()
try:
ldap_user = conn.get_user('uid=%s' % self.username)
except:
return ''
try:
return ldap_user.loginShell
except:
return ''
示例7: is_locked
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def is_locked(self, person):
super(ldap_datastore.PersonalDataStore, self).is_locked(person)
conn = LDAPClient()
try:
ldap_user = conn.get_user('uid=%s' % person.username)
except DoesNotExistException:
return True
return conn.is_locked('uid=%s' % person.username)
示例8: is_locked
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def is_locked(self, person):
super(PersonalDataStore, self).is_locked(person)
conn = LDAPClient()
try:
ldap_user = conn.get_user('sAMAccountName=%s' % person.username)
except DoesNotExistException:
return True
if ldap_user.userAccountControl != '512':
return True
return False
示例9: stest_admin_approve_account
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def stest_admin_approve_account(self):
from karaage.datastores import create_new_user
logged_in = self.client.login(username='kgsuper', password='aq12ws')
self.failUnlessEqual(logged_in, True)
project = Project.objects.get(pid='TestProject1')
p_users = project.users.count()
institute = Institute.objects.get(pk=1)
person_data = {
'title' : 'Mr',
'first_name': 'Jim',
'last_name': 'Bob',
'position': 'Researcher',
'institute': institute,
'department': 'Maths',
'email': '[email protected]',
'country': 'AU',
'telephone': '4444444',
'username': 'jimbob',
'password1': 'Exaiquouxei0',
'password2': 'Exaiquouxei0',
}
person = create_new_user(person_data)
join_request = ProjectJoinRequest.objects.create(
person=person,
project=project,
leader_approved=True,
)
lcon = LDAPClient()
self.failUnlessRaises(placard_exceptions.DoesNotExistException, lcon.get_user, 'uid=jimbob')
self.failUnlessEqual(person.is_active, False)
response = self.client.get(reverse('kg_account_request_detail', args=[join_request.id]))
self.failUnlessEqual(response.status_code, 200)
self.assertEquals(len(mail.outbox), 0)
response = self.client.post(reverse('kg_account_approve', args=[join_request.id]))
self.failUnlessEqual(response.status_code, 302)
self.assertEquals(len(mail.outbox), 1)
self.assertEquals(mail.outbox[0].subject, 'TestOrg Account approval')
self.assertEquals(mail.outbox[0].from_email, settings.ACCOUNTS_EMAIL)
self.assertEquals(mail.outbox[0].to[0], '[email protected].com')
self.failUnlessRaises(ProjectJoinRequest.DoesNotExist, ProjectJoinRequest.objects.get, pk=join_request.id)
person = Person.objects.get(user__username='jimbob')
self.failUnlessEqual(person.is_active, True)
luser = lcon.get_user('uid=jimbob')
self.assertEqual(luser.givenName, 'Jim')
示例10: test_admin_update_user
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def test_admin_update_user(self):
logged_in = self.client.login(username='kgsuper', password='aq12ws')
self.failUnlessEqual(logged_in, True)
person = Person.objects.get(user__username='kgtestuser3')
lcon = LDAPClient()
luser = lcon.get_user('uid=kgtestuser3')
self.failUnlessEqual(person.mobile, '')
self.failUnlessEqual(luser.gidNumber, '500')
self.failUnlessEqual(luser.o, 'Example')
self.failUnlessEqual(luser.gecos, 'Test User3 (Example)')
response = self.client.get(reverse('kg_user_edit', args=['kgtestuser3']))
self.failUnlessEqual(response.status_code, 200)
form_data = {
'title' : 'Mr',
'first_name': 'Test',
'last_name': 'User3',
'position': 'Sys Admin',
'institute': 2,
'department': 'eddf',
'email': '[email protected]',
'country': 'AU',
'telephone': '4444444',
'mobile': '555666',
}
response = self.client.post(reverse('kg_user_edit', args=['kgtestuser3']), form_data)
self.failUnlessEqual(response.status_code, 302)
person = Person.objects.get(user__username='kgtestuser3')
lcon = LDAPClient()
luser = lcon.get_user('uid=kgtestuser3')
self.failUnlessEqual(person.mobile, '555666')
self.failUnlessEqual(luser.gidNumber, '501')
self.failUnlessEqual(luser.o, 'OtherInst')
self.failUnlessEqual(luser.gecos, 'Test User3 (OtherInst)')
示例11: update_account
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def update_account(self, ua):
super(AccountDataStore, self).update_account(ua)
conn = LDAPClient()
ldap_attrs = __import__(settings.LDAP_ATTRS, {}, {}, [''])
data = conn.get_user('uid=%s' % ua.username).__dict__
data['default_project'] = ua.default_project
data['person'] = ua.user
conn.update_user(
'uid=%s' % ua.username,
homeDirectory=ldap_attrs.GENERATED_USER_ATTRS['homeDirectory'](data),
gecos=ldap_attrs.GENERATED_USER_ATTRS['gecos'](data),
gidNumber=ldap_attrs.GENERATED_USER_ATTRS['gidNumber'](data),
)
del(conn)
示例12: test_add_useraccount
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def test_add_useraccount(self):
response = self.client.get(reverse('kg_add_useraccount', args=['samtest2']))
self.failUnlessEqual(response.status_code, 200)
form_data = {
'machine_category': 1,
'default_project': 'TestProject1',
}
response = self.client.post(reverse('kg_add_useraccount', args=['samtest2']), form_data)
self.failUnlessEqual(response.status_code, 302)
person = Person.objects.get(user__username="samtest2")
lcon = LDAPClient()
luser = lcon.get_user('uid=samtest2')
self.assertEqual(luser.objectClass, settings.ACCOUNT_OBJECTCLASS)
self.assertTrue(person.has_account(MachineCategory.objects.get(pk=1)))
示例13: test_admin_create_user_with_account
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def test_admin_create_user_with_account(self):
users = Person.objects.count()
project = Project.objects.get(pid='TestProject1')
p_users = project.users.count()
logged_in = self.client.login(username='kgsuper', password='aq12ws')
self.failUnlessEqual(logged_in, True)
response = self.client.get(reverse('kg_add_user'))
self.failUnlessEqual(response.status_code, 200)
form_data = {
'title' : 'Mr',
'first_name': 'Sam',
'last_name': 'Morrison',
'position': 'Sys Admin',
'institute': 1,
'department': 'eddf',
'email': '[email protected]',
'country': 'AU',
'telephone': '4444444',
'username': 'samtest',
'password1': 'Exaiquouxei0',
'password2': 'Exaiquouxei0',
'project': 'TestProject1',
'needs_account': True,
'machine_category': 1,
}
response = self.client.post(reverse('kg_add_user'), form_data)
self.failUnlessEqual(response.status_code, 302)
self.assertEqual(Person.objects.count(), users+1)
users = users + 1
person = Person.objects.get(pk=users)
self.assertEqual(person.is_active, True)
self.assertEqual(person.user.username, 'samtest')
self.assertEqual(UserAccount.objects.count(), 2)
self.assertEqual(project.users.count(), p_users+1)
lcon = LDAPClient()
luser = lcon.get_user('uid=samtest')
self.assertEqual(luser.givenName, 'Sam')
self.assertEqual(luser.objectClass, settings.ACCOUNT_OBJECTCLASS)
self.assertEqual(luser.homeDirectory, '/vpac/TestProject1/samtest/')
示例14: create_account
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def create_account(self, person, default_project):
ua = super(AccountDataStore, self).create_account(person, default_project)
conn = LDAPClient()
ldap_attrs = __import__(settings.LDAP_ATTRS, {}, {}, [''])
data = conn.get_user('uid=%s' % person.username).__dict__
data['objectClass'] = settings.ACCOUNT_OBJECTCLASS
data['default_project'] = default_project
data['person'] = person
conn.update_user(
'uid=%s' % person.username,
gecos=ldap_attrs.GENERATED_USER_ATTRS['gecos'](data),
uidNumber=ldap_attrs.GENERATED_USER_ATTRS['uidNumber'](data),
gidNumber=ldap_attrs.GENERATED_USER_ATTRS['gidNumber'](data),
homeDirectory=ldap_attrs.GENERATED_USER_ATTRS['homeDirectory'](data),
loginShell=ldap_attrs.GENERATED_USER_ATTRS['loginShell'](data),
objectClass=settings.ACCOUNT_OBJECTCLASS
)
del(conn)
return ua
示例15: get_shell
# 需要导入模块: from placard.client import LDAPClient [as 别名]
# 或者: from placard.client.LDAPClient import get_user [as 别名]
def get_shell(self, ua):
super(AccountDataStore, self).get_shell(ua)
conn = LDAPClient()
luser = conn.get_user('uid=%s' % ua.username)
return luser.loginShell