'Registers a new client on the server.
Args:
localpart : The local part of the user ID to register. If None,
one will be generated.
password (str) : The password to assign to this user so they can
login again. This can be None which means they cannot login again
via a password (e.g. the user is an application service user).
generate_token (bool): Whether a new access token should be
generated. Having this be True should be considered deprecated,
since it offers no means of associating a device_id with the
access_token. Instead you should call auth_handler.issue_access_token
after registration.
Returns:
A tuple of (user_id, access_token).
Raises:
RegistrationError if there was a problem registering.'

@defer.inlineCallbacks
def register(self, localpart=None, password=None, generate_token=True, guest_access_token=None, make_guest=False, admin=False):

    (yield run_on_reactor())
    password_hash = None
    if password:
        password_hash = self.auth_handler().hash(password)
    if localpart:
        (yield self.check_username(localpart, guest_access_token=guest_access_token))
        was_guest = (guest_access_token is not None)
        if (not was_guest):
            try:
                int(localpart)
                raise RegistrationError(400, 'Numeric    user    IDs    are    reserved    for    guest    users.')
            except ValueError:
                pass
        user = UserID(localpart, self.hs.hostname)
        user_id = user.to_string()
        token = None
        if generate_token:
            token = self.macaroon_gen.generate_access_token(user_id)
        (yield self.store.register(user_id=user_id, token=token, password_hash=password_hash, was_guest=was_guest, make_guest=make_guest, create_profile_with_localpart=(None if was_guest else user.localpart), admin=admin))
    else:
        attempts = 0
        token = None
        user = None
        while (not user):
            localpart = (yield self._generate_user_id((attempts > 0)))
            user = UserID(localpart, self.hs.hostname)
            user_id = user.to_string()
            (yield self.check_user_id_not_appservice_exclusive(user_id))
            if generate_token:
                token = self.macaroon_gen.generate_access_token(user_id)
            try:
                (yield self.store.register(user_id=user_id, token=token, password_hash=password_hash, make_guest=make_guest, create_profile_with_localpart=user.localpart))
            except SynapseError:
                user = None
                user_id = None
                token = None
                attempts += 1
    defer.returnValue((user_id, token))
