Ran my self around in circles for a hour because I could not find a user with system.user.getUser() although it most certainly existed in my user source!
Long story short it appears that this function is case-sensitive for the user name. Is there any workarounds to get around this? Unfortunately for this specific user source, I have no control over the case of the username.
I think you’ll need to iterate over the userList. Here’s an example with two users with varying username capitalization:
def matchUser(userIn):
# get all users
users = system.user.getUsers('')
foundFlag = 0
# compare each user by lowercase
for user in users:
username = user.get(user.Username)
if username.lower() == userIn.lower():
foundFlag = 1
break
if foundFlag == 1:
return system.user.getUser('',username)
else:
return 'User not found.'
user2find = 'JoRdAnC'
print matchUser(user2find)
user2find = 'gailw'
print matchUser(user2find)
I was afraid that was the answer. I have 5K+ users in some sources, so trying to avoid the iteration if possible, but this will certainly work. Thanks.
users = system.user.getUsers('')
usernames = [u.get('username').lower() for u in users]
user2find ='myuser'
if user2find in usernames:
return True # or do something else
def getUserIgnoreCase(user2find):
users = system.user.getUsers('')
usernames = [u.get('username').lower() for u in users]
usersdict = dict(zip(usernames, users))
if user2find.lower() in usersdict:
return usersdict[user2find.lower()]
else:
return False
Just checking in on this. Seems like this is a bug on the Ignition side since a user can login without having to match case. Are there plans to make this not case sensitive?
I think case sensitivity must be maintained because whether or not that matters is a detail of the underlying UserSourceProfile. The internal one, for example, prevents you from creating duplicate users in a case insensitive manner, but that is only enforced in the UI.
That some profiles will authenticate a user in a case insensitive manner is also a detail of that type of profile.
None of these things ignore case sensitivity - they pass the credentials as provided to the underlying user source implementation, which may choose to ignore case sensitivity.