コード例 #1
0
ファイル: turbo_views.py プロジェクト: ffsit/turbo-sticks
def rules_view(env, get_vars, post_vars, csrf_clerk, session, user):
    page_data = basic_page_data('rules')
    page_data['nav'] = turbo_nav.generate_html('rules', user)
    status = '200 OK'
    response_body = templates.render('rules', page_data)
    response_headers = util.basic_response_header(response_body)
    return response_body, response_headers, status
コード例 #2
0
ファイル: turbo_views.py プロジェクト: ffsit/turbo-sticks
def account_view(env, get_vars, post_vars, csrf_clerk, session, user):
    page_data = basic_page_data('account')
    # Reset app_password if requested
    if post_vars.get('reset_app_password', [0])[0] == '1':
        csrf_token = post_vars.get('csrf_token', [''])[0]
        if csrf_clerk.validate(session, csrf_token):
            # silently failing on an invalid token is fine here
            user.reset_app_password()
    status = '200 OK'
    page_data['nav'] = turbo_nav.generate_html('account', user, expanded=True)
    page_data['form_action'] = turbo_views['account'].path
    page_data['username'] = user.username
    page_data['avatar_src'] = user.account.get('avatar', '')
    page_data['app_password'] = user.app_password_plain
    page_data['csrf_token'] = csrf_clerk.register(session)
    discord_member = discord.get_member(user.discord_id)
    discord_user = discord.get_user(discord_member)
    redirect_uri = turbo_views['discord-callback'].uri
    oauth = turbo_session.OAuth2Session(config.discord.client_id,
                                        redirect_uri=redirect_uri,
                                        scope=config.discord.scope)
    authorization_url, state = oauth.authorization_url(
        config.discord.authorize_url,
        turbo_session.generate_state(env, csrf_clerk))
    page_data['discord_username'] = discord.render_username(discord_user)
    page_data['discord_roles'] = discord.render_roles(discord_member)
    page_data['discord_avatar_src'] = discord.get_avatar_url(discord_user)
    page_data['authorization_url'] = authorization_url
    response_body = templates.render('account', page_data)
    response_headers = util.basic_response_header(response_body)
    return response_body, response_headers, status
コード例 #3
0
ファイル: turbo_views.py プロジェクト: ffsit/turbo-sticks
def error_view(title,
               detail,
               nav='error',
               status='200 OK',
               headless=False,
               access_level=ACL.guest):
    try:
        page_data = basic_page_data(nav)
        page_data['error_title'] = title
        page_data['error_detail'] = detail
        page_data['nav'] = turbo_nav.generate_html(nav,
                                                   access_level=access_level)

        if headless:
            response_body = templates.render('error_headless', page_data)
        else:
            response_body = templates.render('error', page_data)

        response_headers = util.basic_response_header(response_body)
        return response_body, response_headers, status

    # In case we encounter an error in rendering the error view
    # we'd like to report it
    except Exception:
        logger.exception('Unexpected Error occured.')
        return '', '', '500 Internal Server Error'
コード例 #4
0
ファイル: turbo_views.py プロジェクト: ffsit/turbo-sticks
def theatre_view(env, get_vars, post_vars, csrf_clerk, session, user):
    page_data = basic_page_data('theatre')
    page_data['nav'] = turbo_nav.generate_html('theatre', user)
    page_data['theatre_uri'] = turbo_views['theatre-headless'].path
    status = '200 OK'
    response_body = templates.render('theatre', page_data)
    response_headers = util.basic_response_header(response_body)
    return response_body, response_headers, status
コード例 #5
0
ファイル: turbo_views.py プロジェクト: ffsit/turbo-sticks
def theatre_admin_view(env, get_vars, post_vars, csrf_clerk, session, user):
    page_data = basic_page_data('theatre-admin')
    page_data['nav'] = turbo_nav.generate_html('theatre-admin', user)
    theatre_password = post_vars.get('theatre_password',
                                     [get_property('theatre_password')])[0]
    youtube_stream_id = post_vars.get('youtube_stream_id',
                                      [get_property('theatre_stream_id')])[0]
    set_property('theatre_password', theatre_password)
    set_property('theatre_stream_id', youtube_stream_id)
    page_data['form_action'] = turbo_views['theatre-admin'].path
    page_data['theatre_password'] = theatre_password
    page_data['youtube_stream_id'] = youtube_stream_id
    page_data['csrf_token'] = csrf_clerk.register(session)
    status = '200 OK'
    response_body = templates.render('theatre_admin', page_data)
    response_headers = util.basic_response_header(response_body)
    return response_body, response_headers, status
コード例 #6
0
def main_view(env, csrf_clerk):
    page_data = basic_page_data('main')
    response_body = 'Template Render Error.'
    response_headers = util.basic_response_header(response_body)
    status = '200 OK'

    session = turbo_session.get_session(env)
    account = turbo_session.retrieve_oauth_account(session)

    # Couldn't auth based on session. Start fresh OAuth 2.0 handshake
    if(account is None):
        if(session is not None):
            redirect_uri = turbo_views['oauth-callback'].uri
            oauth = turbo_session.OAuth2Session(
                config.mastodon.client_id,
                redirect_uri=redirect_uri,
                scope=config.mastodon.scope
            )
            authorization_url, state = oauth.authorization_url(
                config.mastodon.authorize_url,
                turbo_session.generate_state(env, csrf_clerk)
            )

            status = '307 Temporary Redirect'
            response_body = ''
            response_headers = [('Location', str(authorization_url))]

        # Not yet authenticated and no old session
        else:
            page_data['nav'] = turbo_nav.generate_html('main')
            page_data['login_uri'] = turbo_views['login'].path
            response_body = templates.render('main', page_data)
            response_headers = util.basic_response_header(response_body)

    # Display Account Information
    else:
        status = '307 Temporary Redirect'
        response_body = ''
        response_headers = [
            ('Location', turbo_views['account'].uri)
        ]
    return response_body, response_headers, status