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.
    """
    if request.method == 'POST':
        if request.form.get('token') == current_user.auth_token:
            try:
                delete_user(current_user.musicbrainz_id)
            except Exception as e:
                current_app.logger.error('Error while deleting %s: %s', current_user.musicbrainz_id, str(e))
                flash.error('Error while deleting user %s, please try again later.' % current_user.musicbrainz_id)
                return redirect(url_for('profile.info'))
            return redirect(url_for('index.index'))
        else:
            flash.error('Cannot delete user due to error during authentication, please try again later.')
            return redirect('profile.info')
    else:
        return render_template(
            'profile/delete.html',
            user=current_user,
        )
Exemple #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.
    """
    if request.method == 'POST':
        if request.form.get('token') == current_user.auth_token:
            try:
                delete_user(current_user.musicbrainz_id)
            except Exception as e:
                current_app.logger.error('Error while deleting %s: %s',
                                         current_user.musicbrainz_id, str(e))
                flash.error(
                    'Error while deleting user %s, please try again later.' %
                    current_user.musicbrainz_id)
                return redirect(url_for('profile.info'))
            return redirect(url_for('index.index'))
        else:
            flash.error(
                'Cannot delete user due to error during authentication, please try again later.'
            )
            return redirect('profile.info')
    else:
        return render_template(
            'profile/delete.html',
            user=current_user,
        )
Exemple #3
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)
 def delete_model(self, model):
     try:
         delete_user(model.id)
         return True
     except OperationalError or DatabaseError as err:
         current_app.logger.error(err, exc_info=True)
         return False
def mb_user_deleter(musicbrainz_row_id):
    """ This endpoint is used by MusicBrainz to delete accounts once they
    are deleted on MusicBrainz too.

    See https://tickets.metabrainz.org/browse/MBS-9680 for details.

    Args: musicbrainz_row_id (int): the MusicBrainz row ID of the user to be deleted.

    Returns: 200 if the user has been successfully found and deleted from LB

    Raises:
        NotFound if the user is not found in the LB database
        Unauthorized if the MusicBrainz access token provided with the query is invalid
    """
    _authorize_mb_user_deleter(request.args.get('access_token', ''))
    user = db_user.get_by_mb_row_id(musicbrainz_row_id)
    if user is None:
        raise NotFound('Could not find user with MusicBrainz Row ID: %d' % musicbrainz_row_id)
    delete_user(user['musicbrainz_id'])
    return jsonify({'status': 'ok'}), 200