async def handle_terms_accepted(self, request: Request, session_id: str, terms_version: str): """Handle a request to the new-user 'consent' endpoint Will serve an HTTP response to the request. Args: request: HTTP request session_id: ID of the username mapping session, extracted from a cookie terms_version: the version of the terms which the user viewed and consented to """ logger.info( "[session %s] User consented to terms version %s", session_id, terms_version, ) try: session = self.get_mapping_session(session_id) except SynapseError as e: self.render_error(request, "bad_session", e.msg, code=e.code) return session.terms_accepted_version = terms_version # we're done; now we can register the user respond_with_redirect(request, b"/_synapse/client/sso_register")
async def handle_submit_username_request( self, request: SynapseRequest, session_id: str, localpart: str, use_display_name: bool, emails_to_use: Iterable[str], ) -> None: """Handle a request to the username-picker 'submit' endpoint Will serve an HTTP response to the request. Args: request: HTTP request localpart: localpart requested by the user session_id: ID of the username mapping session, extracted from a cookie use_display_name: whether the user wants to use the suggested display name emails_to_use: emails that the user would like to use """ try: session = self.get_mapping_session(session_id) except SynapseError as e: self.render_error(request, "bad_session", e.msg, code=e.code) return # update the session with the user's choices session.chosen_localpart = localpart session.use_display_name = use_display_name emails_from_idp = set(session.emails) filtered_emails = set() # type: Set[str] # we iterate through the list rather than just building a set conjunction, so # that we can log attempts to use unknown addresses for email in emails_to_use: if email in emails_from_idp: filtered_emails.add(email) else: logger.warning( "[session %s] ignoring user request to use unknown email address %r", session_id, email, ) session.emails_to_use = filtered_emails # we may now need to collect consent from the user, in which case, redirect # to the consent-extraction-unit if self._consent_at_registration: redirect_url = b"/_synapse/client/new_user_consent" # otherwise, redirect to the completion page else: redirect_url = b"/_synapse/client/sso_register" respond_with_redirect(request, redirect_url)