Don't throw an error if the user has no username set.

If the User object with a custom username gets saved, but no username is set an exception is thrown.
This changes checks first if username is not undefined before it calls the toLowerCase method.