def mastodon_login(): form = MastodonIDForm() if form.validate_on_submit(): user_id = form.mastodon_id.data if "@" not in user_id: flash('Invalid Mastodon ID') return redirect(url_for('index')) if user_id[0] == '@': user_id = user_id[1:] try: username, host = user_id.split('@') except ValueError: flash('Invalid Mastodon ID') return redirect(url_for('index')) session['mastodon_host'] = host api = mastodon_api(host) if api: return redirect( api.auth_request_url(scopes=['read', 'write'], redirect_uris=url_for( "mastodon_oauthorized", _external=True))) else: flash(f"There was a problem connecting to the mastodon server.") else: flash("Invalid Mastodon ID") return redirect(url_for('index'))
def index(): if app.config['MAINTENANCE_MODE']: return render_template('maintenance.html.j2') mform = MastodonIDForm() settings = TSettings() enabled = True form = SettingsForm(obj=settings) if 'bridge_id' in session: bridge = db.session.query(Bridge).filter_by( id=session['bridge_id']).first() if bridge: g.bridge = bridge settings = bridge.t_settings app.logger.debug( f"Existing settings found: {enabled} {settings.__dict__}") form = SettingsForm(obj=settings) if not bridge.mastodon_access_code or not bridge.twitter_oauth_token: form.remove_masto_and_twitter_fields() return render_template( 'index.html.j2', form=form, mform=mform, )
def index(): mform = MastodonIDForm() settings = Settings() enabled = True found_settings = False if 'twitter' in session and 'mastodon' in session: # look up settings bridge = db.session.query(Bridge).filter_by( mastodon_user=session['mastodon']['username'], twitter_handle=session['twitter']['screen_name'], ).first() if bridge: found_settings = True settings = bridge.settings enabled = bridge.enabled g.bridge = bridge app.logger.debug( f"Existing settings found: {enabled} {settings.__dict__}") form = SettingsForm(obj=settings) return render_template('index.html.j2', form=form, mform=mform, enabled=enabled, found_settings=found_settings)