'Creates a new user if the user does not exist,
else revokes all previous access tokens and generates a new one.
Args:
localpart : The local part of the user ID to register. If None,
one will be randomly generated.
Returns:
A tuple of (user_id, access_token).
Raises:
RegistrationError if there was a problem registering.'

@defer.inlineCallbacks
def get_or_create_user(self, requester, localpart, displayname, password_hash=None):

    (yield run_on_reactor())
    if (localpart is None):
        raise SynapseError(400, 'Request    must    include    user    id')
    need_register = True
    try:
        (yield self.check_username(localpart))
    except SynapseError as e:
        if (e.errcode == Codes.USER_IN_USE):
            need_register = False
        else:
            raise
    user = UserID(localpart, self.hs.hostname)
    user_id = user.to_string()
    token = self.macaroon_gen.generate_access_token(user_id)
    if need_register:
        (yield self.store.register(user_id=user_id, token=token, password_hash=password_hash, create_profile_with_localpart=user.localpart))
    else:
        (yield self.store.user_delete_access_tokens(user_id=user_id))
        (yield self.store.add_access_token_to_user(user_id=user_id, token=token))
    if (displayname is not None):
        logger.info('setting    user    display    name:    %s    ->    %s', user_id, displayname)
        profile_handler = self.hs.get_handlers().profile_handler
        (yield profile_handler.set_displayname(user, requester, displayname, by_admin=True))
    defer.returnValue((user_id, token))
