当前位置: 首页>>代码示例>>Python>>正文


Python bottle.redirect方法代码示例

本文整理汇总了Python中bottle.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.redirect方法的具体用法?Python bottle.redirect怎么用?Python bottle.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bottle的用法示例。


在下文中一共展示了bottle.redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def login():
    """Prompt user to authenticate."""
    auth_state = str(uuid.uuid4())
    SESSION.auth_state = auth_state

    # For this sample, the user selects an account to authenticate. Change
    # this value to 'none' for "silent SSO" behavior, and if the user is
    # already authenticated they won't need to re-authenticate.
    prompt_behavior = 'select_account'

    params = urllib.parse.urlencode({'response_type': 'code',
                                     'client_id': config.CLIENT_ID,
                                     'redirect_uri': config.REDIRECT_URI,
                                     'state': auth_state,
                                     'resource': config.RESOURCE,
                                     'prompt': prompt_behavior})

    return bottle.redirect(config.AUTHORITY_URL + '/oauth2/authorize?' + params) 
开发者ID:microsoftgraph,项目名称:python-sample-auth,代码行数:20,代码来源:sample_adal_bottle.py

示例2: authorized

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def authorized():
    """Handler for the application's Redirect Uri."""
    code = bottle.request.query.code
    auth_state = bottle.request.query.state
    if auth_state != SESSION.auth_state:
        raise Exception('state returned to redirect URL does not match!')
    auth_context = adal.AuthenticationContext(config.AUTHORITY_URL, api_version=None)
    token_response = auth_context.acquire_token_with_authorization_code(
        code, config.REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET)
    SESSION.headers.update({'Authorization': f"Bearer {token_response['accessToken']}",
                            'User-Agent': 'adal-sample',
                            'Accept': 'application/json',
                            'Content-Type': 'application/json',
                            'SdkVersion': 'sample-python-adal',
                            'return-client-request-id': 'true'})
    return bottle.redirect('/graphcall') 
开发者ID:microsoftgraph,项目名称:python-sample-auth,代码行数:18,代码来源:sample_adal_bottle.py

示例3: redirect_uri_handler

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def redirect_uri_handler(self):
        """Redirect URL handler for AuthCode workflow. Uses the authorization
        code received from auth endpoint to call the token endpoint and obtain
        an access token.
        """
        # Verify that this authorization attempt came from this app, by checking
        # the received state against what we sent with our authorization request.
        if self.authstate != bottle.request.query.state:
            raise ValueError(f"STATE MISMATCH: {self.authstate} sent, "
                             f"{bottle.request.query.state} received")
        self.authstate = '' # clear state to prevent re-use
        data = {
            'client_id': self.config['client_id'],
            'client_secret': self.config['client_secret'],
            'grant_type': 'authorization_code',
            'code': bottle.request.query.code,
            'redirect_uri': self.config['redirect_uri']
        }
        token_response = requests.post(self.config['token_endpoint'],
                                       data=data)
        self.token_save(token_response)

        if token_response and token_response.ok:
            self.state_manager('save')
        return bottle.redirect(self.login_redirect) 
开发者ID:microsoftgraph,项目名称:python-sample-auth,代码行数:27,代码来源:graphrest.py

示例4: shortcut_delete

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def shortcut_delete():
    name = sanitize(request.forms.get('name'))
    platform = sanitize(request.forms.get('platform'))

    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(shortcuts_dir=SHORTCUT_DIR, platform=platform)
    shortcuts = load_shortcuts(platform)

    matches = [e for e in shortcuts if e['name'] == name and e['cmd'] == platform]
    shortcut = matches[0]

    delete_file(CONTENT_DIR, platform, name)
    delete_file(BANNER_DIR, platform, name)

    shortcuts.remove(shortcut)
    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}'.format(platform=platform)) 
开发者ID:gamer-os,项目名称:steam-buddy,代码行数:19,代码来源:server.py

示例5: flathub_install

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def flathub_install(flatpak_id):
    platform = "flathub"
    application = FLATHUB_HANDLER.get_application(flatpak_id)
    if not application:
        abort(404, '{} not found in Flathub'.format(flatpak_id))
    application.install()

    shortcuts = load_shortcuts(platform)
    shortcut = {
        'name': application.name,
        'hidden': False,
        'banner': application.get_image(os.path.join(BANNER_DIR, platform)),
        'params': application.flatpak_id,
        'cmd': "flatpak run",
        'tags': ["Flathub"],
    }
    shortcuts.append(shortcut)
    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(shortcuts_dir=SHORTCUT_DIR, platform=platform)
    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}/edit/{name}'.format(platform=platform, name=flatpak_id)) 
开发者ID:gamer-os,项目名称:steam-buddy,代码行数:23,代码来源:server.py

示例6: flathub_uninstall

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def flathub_uninstall(flatpak_id):
    platform = "flathub"
    application = FLATHUB_HANDLER.get_application(flatpak_id)
    if not application:
        abort(404, '{} not found in Flathub'.format(flatpak_id))
    application.uninstall()

    shortcuts = load_shortcuts(platform)
    for shortcut in shortcuts:
        if application.name == shortcut['name']:
            shortcuts.remove(shortcut)
            break
    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(shortcuts_dir=SHORTCUT_DIR, platform=platform)
    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}/edit/{name}'.format(platform=platform, name=flatpak_id)) 
开发者ID:gamer-os,项目名称:steam-buddy,代码行数:18,代码来源:server.py

示例7: authenticate_route_handler

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def authenticate_route_handler():
    AUTHENTICATOR.kill()
    password = request.forms.get('password')
    session = request.environ.get('beaker.session')
    keep_password = SETTINGS_HANDLER.get_setting('keep_password') or False
    stored_hash = SETTINGS_HANDLER.get_setting('password')
    if AUTHENTICATOR.matches_password(password) or keep_password and bcrypt.checkpw(password.encode('utf-8'), stored_hash.encode('utf-8')):
        session['User-Agent'] = request.headers.get('User-Agent')
        session['Logged-In'] = True
        session.save()
        redirect('/')
    else:
        if session.get('Logged-In', True):
            session['Logged-In'] = False
            session.save()
        if not keep_password:
            AUTHENTICATOR.reset_password()
            AUTHENTICATOR.launch()
        return template('login', keep_password=keep_password, failed=True) 
开发者ID:gamer-os,项目名称:steam-buddy,代码行数:21,代码来源:server.py

示例8: logout

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def logout(self, success_redirect='/login', fail_redirect='/login'):
        """Log the user out, remove cookie

        :param success_redirect: redirect the user after logging out
        :type success_redirect: str.
        :param fail_redirect: redirect the user if it is not logged in
        :type fail_redirect: str.
        """
        try:
            session = self._beaker_session
            session.delete()
        except Exception as e:
            log.debug("Exception %s while logging out." % repr(e))
            self._redirect(fail_redirect)

        self._redirect(success_redirect) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:18,代码来源:cork.py

示例9: make_auth_decorator

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def make_auth_decorator(self, username=None, role=None, fixed_role=False, fail_redirect='/login'):
        '''
        Create a decorator to be used for authentication and authorization

        :param username: A resource can be protected for a specific user
        :param role: Minimum role level required for authorization
        :param fixed_role: Only this role gets authorized
        :param fail_redirect: The URL to redirect to if a login is required.
        '''
        session_manager = self
        def auth_require(username=username, role=role, fixed_role=fixed_role,
                         fail_redirect=fail_redirect):
            def decorator(func):
                import functools
                @functools.wraps(func)
                def wrapper(*a, **ka):
                    session_manager.require(username=username, role=role, fixed_role=fixed_role,
                        fail_redirect=fail_redirect)
                    return func(*a, **ka)
                return wrapper
            return decorator
        return(auth_require)


    ## Private methods 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:27,代码来源:cork.py

示例10: generate_robots

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def generate_robots(host):
    if host.startswith('robotsdenyall'):
        return 'User-Agent: *\nDisallow: /\n'
    if host.startswith('404'):
        abort(404, 'No robots.txt here')
    if host.startswith('500'):
        abort(500, 'I don\'t know what I\'m doing!')
    if host.startswith('302loop'):
        redirect('http://127.0.0.1:8080/robots.txt.302loop')  # infinite loop
    if host.startswith('302'):
        # unfortunately, we can't use a fake hostname here.
        # XXX figure out how to get this constant out of here... header?
        redirect('http://127.0.0.1:8080/robots.txt.302')
    if host.startswith('pdfrobots'):
        return '%PDF-1.3\n'
    return 'User-Agent: *\nDisallow: /denied/\n' 
开发者ID:cocrawler,项目名称:cocrawler,代码行数:18,代码来源:mock-webserver.py

示例11: file

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def file():
    print('[bottle] url: /upload')
    

    print('[bottle] query:', request.query.keys())
    print('[bottle] forms:', request.forms.keys())
    print('[bottle] files:', request.files.keys())
    
    files = request.files.getall('file')
    print('[bottle] files:', files)
    
    save_path = "./save_file"
    if not os.path.exists(save_path):
        os.mkdir(save_path)
    
    File(files).start()

    print('[bottle] redirect: /')
    redirect('/')
    # print('after redirect') # never executed 
开发者ID:furas,项目名称:python-examples,代码行数:22,代码来源:main.py

示例12: editar

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def editar(slug):
    """Edita un slug"""
    if not 'REMOTE_USER' in bottle.request.environ:
        bottle.abort(401, "Sorry, access denied.")
    usuario = bottle.request.environ['REMOTE_USER'].decode('utf8')

    # Solo el dueño de un atajo puede editarlo
    a = Atajo.get(slug)
    # Atajo no existe o no sos el dueño
    if not a or a.user != usuario:
        bottle.abort(404, 'El atajo no existe')

    if 'url' in bottle.request.GET:
        # El usuario mandó el form
        a.url = bottle.request.GET['url'].decode('utf-8')
        a.activo = 'activo' in bottle.request.GET
        a.test = bottle.request.GET['test'].decode('utf-8')
        a.save()
        bottle.redirect('/')

    return {'atajo':a,
            'mensaje':'',
            } 
开发者ID:rst2pdf,项目名称:rst2pdf,代码行数:25,代码来源:pyurl3.py

示例13: server_index

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def server_index():
    """Needed to redirect / to index.html"""
    return redirect('index.html') 
开发者ID:cea-sec,项目名称:ivre,代码行数:5,代码来源:httpd.py

示例14: server_doc_index

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def server_doc_index():
    """Needed to redirect / to index.html"""
    return redirect('doc/index.html') 
开发者ID:cea-sec,项目名称:ivre,代码行数:5,代码来源:httpd.py

示例15: server_doc_subindex

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import redirect [as 别名]
def server_doc_subindex(subdir):
    """Needed to redirect / to index.html"""
    return redirect('%s/index.html' % subdir) 
开发者ID:cea-sec,项目名称:ivre,代码行数:5,代码来源:httpd.py


注:本文中的bottle.redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。