1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    def wild_signed_cookie_session_factory(request):
        """
        Hack SignedCookieSessionFactory to have `wild_domain`.
        Pyramid devs do not want to support this.

        In addition the domain is determined per request!

        This means a single deployment of this app can support managing a
        `wild_domain` cookie for any domain (likely using CNAMES)
        """
        if not is_ipv4(request.domain):
            if request.domain.count(".") >= 2:
                session_settings["domain"] = ".".join(request.domain.split(".")[-2:])

        factory = SignedCookieSessionFactory(**session_settings)
        return factory(request)

    # setup session factory to use unencrypted but signed cookies
    # session_factory = SignedCookieSessionFactory(**session_settings)
    session_factory = wild_signed_cookie_session_factory

    # build app config object from ini.
    config = Configurator(settings=settings, session_factory=session_factory)