aiohttp.web.HTTPFound

Here are the examples of the python api aiohttp.web.HTTPFound taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

25 Examples 7

Example 1

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def kcv(self, request):
        """适配KanColleViewer或者74EO中进行游戏的页面,提供一个iframe,在iframe中载入游戏FLASH。该页面会检查会话中是否有api_token、
        api_starttime和world_ip三个参数,缺少其中任意一个都不能进行游戏,跳转回登录页面。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            return aiohttp_jinja2.render_template('kcv.html', request, context={})
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/')

Example 2

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def connector(self, request):
        """适配登录器直连模式结果页面,提供osapi.dmm.com的链接。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        osapi_url = session.get('osapi_url', None)
        if osapi_url:
            context = {'osapi_url': osapi_url}
            return aiohttp_jinja2.render_template('connector.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/')

Example 3

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def logout(self, request):
        """ 注销已登录的用户。
        清除所有的session,返回首页。

        :return: aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        self.clear_session(session)
        return aiohttp.web.HTTPFound('/')

Example 4

Project: dcos
License: View license
Source File: async_server.py
def redirect_to_root(request):
    """Return the redirect from /api/v1 to /

    :param request: a web requeest object.
    :type request: request | None
    """
    log.warning("/api/v{} -> redirecting -> /".format(VERSION))
    return web.HTTPFound('/'.format(VERSION))

Example 5

Project: dcos
License: View license
Source File: async_server.py
def logs_handler(request):
    """Return the log file on disk.

    :param request: a web requeest object.
    :type request: request | None
    """
    log.info("Request for logs endpoint made.")
    complete_log_path = 'genconf/state/complete.log'
    json_files = glob.glob('genconf/state/*.json')
    complete_log = []
    for f in json_files:
        log.debug('Adding {} to complete log file.'.format(f))
        with open(f) as blob:
            complete_log.append(json.loads(blob.read()))

    with open(complete_log_path, 'w') as f:
        f.write(json.dumps(complete_log, indent=4, sort_keys=True))

    return web.HTTPFound('/download/log/complete.log'.format(VERSION))

Example 6

Project: aiohttp-security
License: View license
Source File: handlers.py
    @asyncio.coroutine
    def login(self, request):
        response = web.HTTPFound('/')
        form = yield from request.post()
        login = form.get('login')
        password = form.get('password')
        db_engine = request.app.db_engine
        if (yield from check_credentials(db_engine, login, password)):
            yield from remember(request, response, login)
            return response

        return web.HTTPUnauthorized(
            body=b'Invalid username/password combination')

Example 7

Project: gns3-server
License: View license
Source File: response.py
    def redirect(self, url):
        """
        Redirect to url

        :params url: Redirection URL
        """
        raise aiohttp.web.HTTPFound(url)

Example 8

Project: aiohttp
License: View license
Source File: test_web_exceptions.py
@asyncio.coroutine
def test_HTTPFound(buf, request):
    resp = web.HTTPFound(location='/redirect')
    assert '/redirect' == resp.location
    assert '/redirect' == resp.headers['location']
    yield from resp.prepare(request)
    yield from resp.write_eof()
    txt = buf.decode('utf8')
    assert re.match('HTTP/1.1 302 Found\r\n'
                    'Content-Type: text/plain; charset=utf-8\r\n'
                    'Content-Length: 10\r\n'
                    'Location: /redirect\r\n'
                    'Date: .+\r\n'
                    'Server: .+\r\n\r\n'
                    '302: Found', txt)

Example 9

Project: aiohttp
License: View license
Source File: test_web_exceptions.py
def test_HTTPFound_empty_location():
    with pytest.raises(ValueError):
        web.HTTPFound(location='')

    with pytest.raises(ValueError):
        web.HTTPFound(location=None)

Example 10

Project: aiohttp
License: View license
Source File: test_web_functional.py
@asyncio.coroutine
def test_redirect_url(loop, test_client):

    @asyncio.coroutine
    def redirector(request):
        raise web.HTTPFound(location=URL('/redirected'))

    @asyncio.coroutine
    def redirected(request):
        return web.Response()

    app = web.Application(loop=loop)
    app.router.add_get('/redirector', redirector)
    app.router.add_get('/redirected', redirected)

    client = yield from test_client(app)
    resp = yield from client.get('/redirector')
    assert resp.status == 200

Example 11

Project: aioauth-client
License: View license
Source File: app.py
@asyncio.coroutine
def github(request):
    github = GithubClient(
        client_id='b6281b6fe88fa4c313e6',
        client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
    )
    if 'code' not in request.GET:
        return web.HTTPFound(github.get_authorize_url(scope='user:email'))

    # Get access token
    code = request.GET['code']
    token, _ = yield from github.get_access_token(code)
    assert token

    # Get a resource `https://api.github.com/user`
    response = yield from github.request('GET', 'user')
    body = yield from response.read()
    return web.Response(body=body, content_type='application/json')

Example 12

Project: sky
License: View license
Source File: test.py
    def add_redirect(self, url, link):
        @asyncio.coroutine
        def handler(_):
            raise web.HTTPFound(link)

        self.add_handler(url, handler)
        return self.app_url + url

Example 13

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def login(self, request):
        """接受登录表单提交的数据,登录后跳转或登录失败后展示错误信息。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.HTTPFound or aiohttp.web.Response
        """
        post = yield from request.post()
        session = yield from get_session(request)

        login_id = post.get('login_id', None)
        password = post.get('password', None)
        mode = int(post.get('mode', 1))

        session['mode'] = mode

        if login_id and password:
            kancolle = KancolleAuth(login_id, password)
            if mode in (1, 2, 3):
                try:
                    yield from kancolle.get_flash()
                    session['api_token'] = kancolle.api_token
                    session['api_starttime'] = kancolle.api_starttime
                    session['world_ip'] = kancolle.world_ip
                    if mode == 2:
                        return aiohttp.web.HTTPFound('/kcv')
                    elif mode == 3:
                        return aiohttp.web.HTTPFound('/poi')
                    else:
                        return aiohttp.web.HTTPFound('/kancolle')

                except OOIAuthException as e:
                    context = {'errmsg': e.message, 'mode': mode}
                    return aiohttp_jinja2.render_template('form.html', request, context)
            elif mode == 4:
                try:
                    osapi_url = yield from kancolle.get_osapi()
                    session['osapi_url'] = osapi_url
                    return aiohttp.web.HTTPFound('/connector')
                except OOIAuthException as e:
                    context = {'errmsg': e.message, 'mode': mode}
                    return aiohttp_jinja2.render_template('form.html', request, context)
            else:
                raise aiohttp.web.HTTPBadRequest()
        else:
            context = {'errmsg': '请输入完整的登录ID和密码', 'mode': mode}
            return aiohttp_jinja2.render_template('form.html', request, context)

Example 14

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def normal(self, request):
        """适配浏览器中进行游戏的页面,该页面会检查会话中是否有api_token、api_starttime和world_ip三个参数,缺少其中任意一个都不能进行
        游戏,跳转回登录页面。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            context = {'scheme': request.scheme,
                       'host': request.host,
                       'token': token,
                       'starttime': starttime}
            return aiohttp_jinja2.render_template('normal.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/')

Example 15

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def flash(self, request):
        """适配KanColleViewer或者74EO中进行游戏的页面,展示,该页面会检查会话中是否有api_token、api_starttime和world_ip三个参数,
        缺少其中任意一个都不能进行游戏,跳转回登录页面。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            context = {'scheme': request.scheme,
                       'host': request.host,
                       'token': token,
                       'starttime': starttime}
            return aiohttp_jinja2.render_template('flash.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/')

Example 16

Project: ooi3
License: View license
Source File: frontend.py
    @asyncio.coroutine
    def poi(self, request):
        """适配poi中进行游戏的页面,显示FLASH。该页面会检查会话中是否有api_token、api_starttime和world_ip三个参数,缺少其中任意一个
        都不能进行游戏,跳转回登录页面。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            context = {'scheme': request.scheme,
                       'host': request.host,
                       'token': token,
                       'starttime': starttime}
            return aiohttp_jinja2.render_template('poi.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/')

Example 17

Project: aiohttp-security
License: View license
Source File: test_dict_autz.py
@asyncio.coroutine
def test_authorized_userid(loop, test_client):

    @asyncio.coroutine
    def login(request):
        response = web.HTTPFound(location='/')
        yield from remember(request, response, 'UserID')
        return response

    @asyncio.coroutine
    def check(request):
        userid = yield from authorized_userid(request)
        assert 'Andrew' == userid
        return web.Response(text=userid)

    app = web.Application(loop=loop)
    _setup(app, CookiesIdentityPolicy(), Autz())
    app.router.add_route('GET', '/', check)
    app.router.add_route('POST', '/login', login)
    client = yield from test_client(app)

    resp = yield from client.post('/login')
    assert 200 == resp.status
    txt = yield from resp.text()
    assert 'Andrew' == txt
    yield from resp.release()

Example 18

Project: aiohttp-security
License: View license
Source File: test_dict_autz.py
@asyncio.coroutine
def test_permits(loop, test_client):

    @asyncio.coroutine
    def login(request):
        response = web.HTTPFound(location='/')
        yield from remember(request, response, 'UserID')
        return response

    @asyncio.coroutine
    def check(request):
        ret = yield from permits(request, 'read')
        assert ret
        ret = yield from permits(request, 'write')
        assert ret
        ret = yield from permits(request, 'unknown')
        assert not ret
        return web.Response()

    app = web.Application(loop=loop)
    _setup(app, CookiesIdentityPolicy(), Autz())
    app.router.add_route('GET', '/', check)
    app.router.add_route('POST', '/login', login)
    client = yield from test_client(app)
    resp = yield from client.post('/login')
    assert 200 == resp.status
    yield from resp.release()

Example 19

Project: aiohttp-session
License: View license
Source File: test_http_exception.py
@asyncio.coroutine
def test_exceptions(test_client):

    @asyncio.coroutine
    def save(request):
        session = yield from get_session(request)
        session['message'] = 'works'
        raise web.HTTPFound('/show')

    @asyncio.coroutine
    def show(request):
        session = yield from get_session(request)
        message = session.get('message')
        return web.Response(text=str(message))

    client = yield from test_client(create_app,
                                    ('/save', save),
                                    ('/show', show))

    resp = yield from client.get('/save')
    assert resp.status == 200
    assert resp.url[-5:] == '/show'
    text = yield from resp.text()
    assert text == 'works'

Example 20

Project: aiohttp_admin
License: View license
Source File: utils.py
def redirect(request, name, **kw):
    router = request.app.router
    location = router[name].url(**kw)
    return web.HTTPFound(location=location)

Example 21

Project: aiohttp_admin
License: View license
Source File: views.py
    async def timeline(self, request):
        session = await get_session(request)
        user_id = session.get('user_id')

        if user_id is None:
            router = request.app.router
            location = router['public_timeline'].url()
            raise web.HTTPFound(location=location)
        user = await self.mongo.user.find_one({'_id': ObjectId(user_id)})

        query = {'who_id': ObjectId(user_id)}
        filter = {'whom_id': 1}
        followed = await self.mongo.follower.find_one(query, filter)
        if followed is None:
            followed = {'whom_id': []}

        query = {'$or': [{'author_id': ObjectId(user_id)},
                         {'author_id': {'$in': followed['whom_id']}}]}
        messages = await (self.mongo.message
                          .find(query)
                          .sort('pub_date', -1)
                          .to_list(30))
        endpoint = request.match_info.route.name
        return {"messages": messages,
                "user": user,
                "endpoint": endpoint,
                "endpoint": request.match_info.route.name}

Example 22

Project: aiohttp
License: View license
Source File: web_cookies.py
@asyncio.coroutine
def login(request):
    resp = web.HTTPFound(location='/')
    resp.set_cookie('AUTH', 'secret')
    return resp

Example 23

Project: aiohttp
License: View license
Source File: web_cookies.py
@asyncio.coroutine
def logout(request):
    resp = web.HTTPFound(location='/')
    resp.del_cookie('AUTH')
    return resp

Example 24

Project: mblog
License: View license
Source File: api.py
async def oauth2(code):
    url = 'https://api.weibo.com/oauth2/access_token'
    payload = {
        'client_id': '366603916',
        'client_secret': 'b418efbd77094585d0a7f9ccac98a706',
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': 'http://www.qiangtaoli.com'
    }
    with ClientSession() as session:
        async with session.post(url, data=payload) as resp:
            params = await resp.json()
        async with session.get('https://api.weibo.com/2/users/show.json', params=params) as resp:
            info = await resp.json()
        o = await Oauth.find('weibo-' + info['idstr'])
        if not o:
            return 'redirect:/bootstrap/register?oid=weibo-%s&name=%s&image=%s' % (info['idstr'], info['name'], info['avatar_large'])
        user = await User.find(o.user_id)
        if not user:
            return 'oauth user was deleted.'
        return user.signin(web.HTTPFound('/'))

Example 25

Project: mblog
License: View license
Source File: api.py
@get('/signout')
def signout(request):
    logging.info('user sign out')
    return User.signout(web.HTTPFound(request.headers.get('Referer') or '/'))