Beispiel #1
0
def music_services_disconnect(service_name: str):
    service = _get_service_or_raise_404(service_name)
    user = service.get_user(current_user.id)
    # this is to support the workflow of changing permissions in a single step
    # we delete the current permissions and then try to authenticate with new ones
    # we should try to delete the current permissions only if the user has connected previously
    if user:
        service.remove_user(current_user.id)

    action = request.form.get(service_name)
    if not action or action == 'disable':
        flash.success('Your %s account has been unlinked.' %
                      service_name.capitalize())
        return redirect(url_for('profile.music_services_details'))
    else:
        if service_name == 'spotify':
            permissions = None
            if action == 'both':
                permissions = SPOTIFY_LISTEN_PERMISSIONS + SPOTIFY_IMPORT_PERMISSIONS
            elif action == 'import':
                permissions = SPOTIFY_IMPORT_PERMISSIONS
            elif action == 'listen':
                permissions = SPOTIFY_LISTEN_PERMISSIONS
            if permissions:
                return redirect(service.get_authorize_url(permissions))
        elif service_name == 'youtube':
            action = request.form.get('youtube')
            if action:
                return redirect(service.get_authorize_url(YOUTUBE_SCOPES))

    return redirect(url_for('profile.music_services_details'))
Beispiel #2
0
def delete():
    """ Delete currently logged-in user from ListenBrainz.

    If POST request, this view checks for the correct authorization token and
    deletes the user. If deletion is successful, redirects to home page, else
    flashes an error and redirects to user's info page.

    If GET request, this view renders a page asking the user to confirm
    that they wish to delete their ListenBrainz account.
    """
    form = FlaskForm()
    if form.validate_on_submit():
        try:
            delete_user(current_user.musicbrainz_id)
            flash.success("Successfully deleted account for %s." %
                          current_user.musicbrainz_id)
            return redirect(url_for('index.index'))
        except Exception:
            current_app.logger.error('Error while deleting user: %s',
                                     current_user.musicbrainz_id,
                                     exc_info=True)
            flash.error(
                'Error while deleting user %s, please try again later.' %
                current_user.musicbrainz_id)
            return redirect(url_for('profile.info'))

    if form.csrf_token.errors:
        flash.error(
            'Cannot delete user due to error during authentication, please try again later.'
        )
        return redirect(url_for('profile.info'))

    return render_template('profile/delete.html', user=current_user, form=form)
Beispiel #3
0
def music_services_callback(service_name: str):
    service = _get_service_or_raise_404(service_name)
    code = request.args.get('code')
    if not code:
        raise BadRequest('missing code')
    token = service.fetch_access_token(code)
    service.add_new_user(current_user.id, token)
    flash.success('Successfully authenticated with %s!' %
                  service_name.capitalize())
    return redirect(url_for('profile.music_services_details'))
Beispiel #4
0
def connect_spotify_callback():
    code = request.args.get('code')
    if not code:
        raise BadRequest('missing code')

    try:
        token = spotify.get_access_token(code)
        spotify.add_new_user(current_user.id, token)
        flash.success('Successfully authenticated with Spotify!')
    except spotipy.oauth2.SpotifyOauthError as e:
        current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True)
        flash.warn('Unable to authenticate with Spotify (error {})'.format(e.args[0]))

    return redirect(url_for('profile.connect_spotify'))
def connect_spotify_callback():
    code = request.args.get('code')
    if not code:
        raise BadRequest('missing code')
    sp_oauth = spotify.get_spotify_oauth()

    try:
        token = sp_oauth.get_access_token(code)
        spotify.add_new_user(current_user.id, token)
        flash.success('Successfully authenticated with Spotify!')
    except spotipy.oauth2.SpotifyOauthError as e:
        current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True)
        flash.warn('Unable to authenticate with Spotify (error {})'.format(e.args[0]))

    return redirect(url_for('profile.connect_spotify'))
def connect_spotify():
    if request.method == 'POST' and request.form.get('delete') == 'yes':
        spotify.remove_user(current_user.id)
        flash.success('Your Spotify account has been unlinked')

    user = spotify.get_user(current_user.id)
    spotify_url = None
    if not user:
        sp_oauth = spotify.get_spotify_oauth()
        spotify_url = sp_oauth.get_authorize_url()

    return render_template(
        'user/spotify.html',
        account=user,
        last_updated=user.last_updated_iso if user else None,
        latest_listened_at=user.latest_listened_at_iso if user else None,
        spotify_login_url=spotify_url)
def connect_spotify():
    if request.method == 'POST' and request.form.get('delete') == 'yes':
        spotify.remove_user(current_user.id)
        flash.success('Your Spotify account has been unlinked')

    user = spotify.get_user(current_user.id)
    spotify_url = None
    if not user:
        sp_oauth = spotify.get_spotify_oauth()
        spotify_url = sp_oauth.get_authorize_url()

    return render_template(
        'user/spotify.html',
        account=user,
        last_updated=user.last_updated_iso if user else None,
        latest_listened_at=user.latest_listened_at_iso if user else None,
        spotify_login_url=spotify_url
    )
Beispiel #8
0
def connect_spotify():
    if request.method == 'POST' and request.form.get('delete') == 'yes':
        spotify.remove_user(current_user.id)
        flash.success('Your Spotify account has been unlinked')

    user = spotify.get_user(current_user.id)
    only_listen_sp_oauth = spotify.get_spotify_oauth(spotify.SPOTIFY_LISTEN_PERMISSIONS)
    only_import_sp_oauth = spotify.get_spotify_oauth(spotify.SPOTIFY_IMPORT_PERMISSIONS)
    both_sp_oauth = spotify.get_spotify_oauth(spotify.SPOTIFY_LISTEN_PERMISSIONS + spotify.SPOTIFY_IMPORT_PERMISSIONS)

    return render_template(
        'user/spotify.html',
        account=user,
        last_updated=user.last_updated_iso if user else None,
        latest_listened_at=user.latest_listened_at_iso if user else None,
        only_listen_url=only_listen_sp_oauth.get_authorize_url(),
        only_import_url=only_import_sp_oauth.get_authorize_url(),
        both_url=both_sp_oauth.get_authorize_url(),
    )