Ejemplo n.º 1
0
def custom_username():
    next_url = request.form.get('next')
    site_id = request.form.get('site')
    site = Facebook.query.get(site_id)
    if not site or not util.is_authed(site):
        flash('Please authenticate with this service', 'warning')
    else:
        site.account.username = request.form.get('username')
        db.session.commit()
        flash('Updated username to ' + site.account.username)
    return redirect(next_url)
Ejemplo n.º 2
0
def custom_username():
    next_url = request.form.get('next')
    site_id = request.form.get('site')
    site = Facebook.query.get(site_id)
    if not site or not util.is_authed(site):
        flash('Please authenticate with this service', 'warning')
    else:
        site.account.username = request.form.get('username')
        db.session.commit()
        flash('Updated username to ' + site.account.username)
    return redirect(next_url)
Ejemplo n.º 3
0
def setup_micropub():
    service = request.args.get('service')
    domain = request.args.get('domain')
    site = Site.query.filter_by(
        service=service, domain=domain).first()
    if not site:
        abort(404)

    auth_endpt = None
    token_endpt = None
    upub_endpt = None

    if service in ('wordpress', 'tumblr', 'blogger'):
        r = requests.get(site.url)
        if r.status_code // 100 != 2:
            flash('Error fetching your homepage ({}): {}'.format(
                r.status_code, r.text))
        else:
            soup = BeautifulSoup(r.text)

            auth = soup.find_all(['a', 'link'], rel='authorization_endpoint')
            token = soup.find_all(['a', 'link'], rel='token_endpoint')
            upub = soup.find_all(['a', 'link'], rel='micropub')

            auth_endpt = next(
                (a.get('href') for a in auth if a.get('href')), None)
            token_endpt = next(
                (a.get('href') for a in token if a.get('href')), None)
            upub_endpt = next(
                (a.get('href') for a in upub if a.get('href')), None)

    token = None
    if util.is_authed(site):
        token = Token.create_or_update(site, 'post', 'https://silo.pub/')

    return render_template(
        ['micropub_{}.jinja2'.format(site.service), 'micropub.jinja2'],
        site=site, authorization_endpoint=auth_endpt,
        token_endpoint=token_endpt,
        micropub=upub_endpt, access_token=token and token.token,
        authed=util.is_authed(site))