Beispiel #1
0
    def login_with_session(self, request, session):
        # Based on
        # https://github.com/openmicroscopy/openmicroscopy/blob/v5.4.10/components/tools/OmeroWeb/omeroweb/webgateway/views.py#L2943
        username = session
        password = session
        server_id = 1
        is_secure = settings.SECURE
        connector = Connector(server_id, is_secure)

        compatible = True
        if settings.CHECK_VERSION:
            compatible = connector.check_version(USERAGENT)
        if compatible:
            conn = connector.create_connection(USERAGENT,
                                               username,
                                               password,
                                               userip=get_client_ip(request))
            if conn is not None:
                try:
                    request.session['connector'] = connector
                    # UpgradeCheck URL should be loaded from the server or
                    # loaded omero.web.upgrades.url allows to customize web
                    # only
                    try:
                        upgrades_url = settings.UPGRADES_URL
                    except AttributeError:
                        upgrades_url = conn.getUpgradesUrl()
                    upgradeCheck(url=upgrades_url)
                    # super.handle_logged_in does some connection preparation
                    # as wel as redirecting to the main page. We just want
                    # the preparation, so discard the response
                    self.handle_logged_in(request, conn, connector)
                    return HttpResponseRedirect(reverse('oauth_confirm'))
                finally:
                    conn.close(hard=False)

            raise Exception('Failed to login with session %s', session)
        raise Exception('Incompatible server')