Fix username change [WIP]

This is an attempt to fix https://github.com/owncloud/core/issues/9358 by backporting the pull requests mentioned in there.

However this doesn’t seem to fully work. Can you check @MorrisJobke @wakeup?