def isuser(self, username):
     """
     Check if the user exists.
     
     :param username: The username.
     
     :return: True if the user exists and is in the specified group, False otherwise.
     """
     if self.group is None:
         try:
             # just check if user exists
             restauth_user.get(self.connection, username)
             return True
         except:
             # did not exist / error
             return False
         
     else:
         # check if user in group
         user = restauth_user.User(self.connection, username)
         try:
             return user.in_group(self.group)
         except:
             # user or group did not exist
             return False
         
     pass
Пример #2
0
except restauth_user.UserExists:
	pass

# verify that we still have 10 users?
user_list = restauth_user.get_all( conn ) 
if not len( user_list ) == 10:
	print( 'FAILED - We no longer have 10 users in RestAuth!' )
	sys.exit(1)
# verify that the old password still checks out?
if not user0.verify_password( 'password0' ):
	print( 'FAILED - It seems like the password was changed?' )
	sys.exit(1)
print( 'Ok.' )

print( 'Trying to get some users... ', end='' )
user0 = restauth_user.get( conn, 'user0' )
user1 = restauth_user.get( conn, 'user1' )
print( 'Ok.' )
try:
	print( 'Trying to get nonexistent user... ', end='' )
	user99 = restauth_user.get( conn, 'user99' )
	print( 'FAILED - GOT A USER???' )
	sys.exit(1)
except ResourceNotFound:
	print( 'Ok.' )
	
print( 'Updating some passwords... ', end='' )
user1.set_password( 'new password' )
if not user1.verify_password( 'new password' ):
	print( 'FAILED - new password does not verify...' )
	sys.exit(1)
Пример #3
0
# username, because this does not work on XMPP, email, ...
# The factory-methods for creating users guarantee that the user exist:
managed_user = restauth_user.create( conn, 'managed_user', 'password' )

# handle the password:
if managed_user.verify_password( 'password' ):
	pass
else:
	# password is not correct
	print( "Error: The password is not correct?" )

managed_user.set_password( 'new password' )

# Now we want to get a user from the service - this again guarantees that the
# user exists:
managed_user = restauth_user.get( conn, 'managed_user' )

# You can always just construct your own object, i.e. if you know that the user
# exists and do not want to hit the service. Here we create an instance of a
# user that does not in fact exist:
wrong_user = restauth_user.User( conn, 'wrong_user' )

# if performing any action on it, this will throw an error:
try:
	wrong_user.set_password( 'foobar' )
	print( "Error: wrong_user.set_password should throw an error!" )
except restauth_user.UserNotFound:
	pass

# of course, verify_password just returns false:
if wrong_user.verify_password( 'foobar' ):