# Path: channels/app.py
# def init_database(app):
# def init_disqus(app):
# def init_publisher(app):
# def get_client(key):


import functools
import simplejson
import urllib
import urllib2
from disqusapi import InvalidAccessToken
from flask import url_for, request, redirect, session, render_template
from channels.app import app, disqusapi
    from channels.models import User
def login_required(func):
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        if 'auth' not in session:
            session['postauth'] = {
                'url': request.url,
                'form': request.form
            }
            return redirect(url_for('oauth_authorize'))
        return func(*args, **kwargs)
    return wrapped


@app.route('/logout', methods=['GET'])
def logout():
    if 'auth' in session:
        del session['auth']
    return redirect('/')


@app.route('/oauth/authorize/')
def oauth_authorize():
    return redirect('https://disqus.com/api/oauth/2.0/authorize/?%s' % (urllib.urlencode({
        'client_id': disqusapi.public_key,
        'scope': 'read,write',
        'response_type': 'code',
        'redirect_uri': url_for('oauth_callback', _external=True),
    }),))



# Path: channels/app.py
# def init_database(app):
# def init_disqus(app):
# def init_publisher(app):
# def get_client(key):


# Path: channels/oauth.py
import functools
import simplejson
import urllib
import urllib2
from disqusapi import InvalidAccessToken
from flask import url_for, request, redirect, session, render_template
from channels.app import app, disqusapi
    from channels.models import User

def login_required(func):
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        if 'auth' not in session:
            session['postauth'] = {
                'url': request.url,
                'form': request.form
            }
            return redirect(url_for('oauth_authorize'))
        return func(*args, **kwargs)
    return wrapped


@app.route('/logout', methods=['GET'])
def logout():
    if 'auth' in session:
        del session['auth']
    return redirect('/')


@app.route('/oauth/authorize/')
def oauth_authorize():
    return redirect('https://disqus.com/api/oauth/2.0/authorize/?%s' % (urllib.urlencode({
        'client_id': disqusapi.public_key,
        'scope': 'read,write',
        'response_type': 'code',
        'redirect_uri': url_for('oauth_callback', _external=True),
    }),))



@app.route('/oauth/error/')