synapse/handlers/register.py
def register(
        self,
        localpart=None,
        password=None,
        generate_token=True,
        guest_access_token=None,
        make_guest=False,
        admin=False,
    ):
        """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.
        """
        yield run_on_reactor()
        password_hash = None
        if password:
            password_hash = yield 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=(
                    # If the user was a guest then they already have a profile
                    None if was_guest else user.localpart
                ),
                admin=admin,
            )

            if self.hs.config.user_directory_search_all_users:
                profile = yield self.store.get_profileinfo(localpart)
                yield self.user_directory_handler.handle_local_profile_change(
                    user_id, profile
                )

        else:
            # autogen a sequential user ID
            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:
                    # if user id is taken, just generate another
                    user = None
                    user_id = None
                    token = None
                    attempts += 1

        # auto-join the user to any rooms we're supposed to dump them into
        fake_requester = create_requester(user_id)
        for r in self.hs.config.auto_join_rooms:
            try:
                yield self._join_user_to_room(fake_requester, r)
            except Exception as e:
                logger.error("Failed to join new user to %r: %r", r, e)

        # We used to generate default identicons here, but nowadays
        # we want clients to generate their own as part of their branding
        # rather than there being consistent matrix-wide ones, so we don't.
        defer.returnValue((user_id, token))
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.
        
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 .
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.
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 . 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 .
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 = yield 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,
            )
            if self.hs.config.user_directory_search_all_users:
                profile = yield self.store.get_profileinfo(localpart)
                yield self.user_directory_handler.handle_local_profile_change(
                    user_id, profile
                )
        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
        fake_requester = create_requester(user_id)
        for r in self.hs.config.auto_join_rooms:
            try:
                yield self._join_user_to_room(fake_requester, r)
            except Exception as e:
                logger.error("Failed to join new user to %r: %r", r, e)
        defer.returnValue((user_id, token))
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 = yield 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 , ) if self . hs . config . user_directory_search_all_users : profile = yield self . store . get_profileinfo ( localpart ) yield self . user_directory_handler . handle_local_profile_change ( user_id , profile ) 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 fake_requester = create_requester ( user_id ) for r in self . hs . config . auto_join_rooms : try : yield self . _join_user_to_room ( fake_requester , r ) except Exception as e : logger . error ( "Failed to join new user to %r: %r" , r , e ) defer . returnValue ( ( user_id , token ) )
Registers a new client on the server.
Registers a new client on the server .
"""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.
        """ # If the user was a guest then they already have a profile # autogen a sequential user ID # if user id is taken, just generate another # auto-join the user to any rooms we're supposed to dump them into # We used to generate default identicons here, but nowadays # we want clients to generate their own as part of their branding # rather than there being consistent matrix-wide ones, so we don't.
self
localpart
password
generate_token
guest_access_token
make_guest
admin