예제 #1
0
def cancelled():
    """Endpoint for cancelled payments."""
    if request.args.get("is_donation") == "True":
        flash.info("We're sorry to see that you won't be donating today. We hope that "
                   "you'll change your mind!")
        return redirect(url_for('payments.donate'))
    else:
        flash.info("We're sorry to see that you won't be paying today. We hope that "
                   "you'll change your mind!")
        return redirect(url_for('financial_reports.index'))
예제 #2
0
    def approve(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_ACTIVE)
        flash.info("User #%s has been approved." % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            return redirect(url_for('.index'))
예제 #3
0
    def wait(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_WAITING)
        flash.info("User #%s has been put into the waiting list." % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info("No more pending users.")
            return redirect(url_for('.index'))
예제 #4
0
    def wait(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_WAITING)
        flash.info('User #%s has been put into the waiting list.' % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info('No more pending users.')
            return redirect(url_for('.index'))
예제 #5
0
def cancelled():
    """Endpoint for cancelled payments."""
    if request.args.get("is_donation") == "True":
        flash.info(
            "We're sorry to see that you won't be donating today. We hope that "
            "you'll change your mind!")
        return redirect(url_for('payments.donate'))
    else:
        flash.info(
            "We're sorry to see that you won't be paying today. We hope that "
            "you'll change your mind!")
        return redirect(url_for('financial_reports.index'))
예제 #6
0
    def reject(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_REJECTED)
        flash.warning('User #%s has been rejected.' % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info('No more pending users.')
            return redirect(url_for('.index'))
예제 #7
0
    def approve(self):
        user_id = request.args.get('user_id')
        if request.args.get('limited'):
            User.get(id=user_id).set_state(STATE_LIMITED)
        else:
            User.get(id=user_id).set_state(STATE_ACTIVE)
        flash.info('User #%s has been approved.' % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info('No more pending users.')
            return redirect(url_for('.index'))
예제 #8
0
    def approve(self):
        user_id = request.args.get('user_id')
        if request.args.get('limited'):
            User.get(id=user_id).set_state(STATE_LIMITED)
        else:
            User.get(id=user_id).set_state(STATE_ACTIVE)
        flash.info('User #%s has been approved.' % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info('No more pending users.')
            return redirect(url_for('.index'))
예제 #9
0
def signup_noncommercial():
    """Sign up endpoint for non-commercial users."""
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(
            **{
                SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_NONCOMMERCIAL,
            })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = NonCommercialSignUpForm(default_email=mb_email)
    if form.validate_on_submit():
        # Checking if this user already exists
        new_user = User.get(musicbrainz_id=mb_username)
        if not new_user:
            new_user = User.add(
                is_commercial=False,
                musicbrainz_id=mb_username,
                contact_name=form.contact_name.data,
                contact_email=form.contact_email.data,
                data_usage_desc=form.usage_desc.data,
            )
            flash.success(gettext("Thanks for signing up!"))
            try:
                send_mail(
                    subject="[MetaBrainz] Sign up confirmation",
                    text=
                    'Dear %s,\n\nThank you for signing up!\n\nYou can now generate '
                    'an access token for the MetaBrainz API on your profile page.'
                    % new_user.contact_name,
                    recipients=[new_user.contact_email],
                )
            except MailException as e:
                logging.error(e)
                flash.warn(
                    gettext(
                        "Failed to send welcome email to you. We are looking into it. "
                        "Sorry for inconvenience!"))
        else:
            flash.info(gettext("You already have a MetaBrainz account!"))
        login_user(new_user)
        return redirect(url_for('.profile'))

    return render_template("users/signup-non-commercial.html",
                           form=form,
                           mb_username=mb_username)
예제 #10
0
def signup():
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if mb_username is None:
        # Show template with a link to MusicBrainz OAuth page
        return render_template('users/mb-signup.html')

    account_type = session.fetch_data(SESSION_KEY_ACCOUNT_TYPE)
    if not account_type:
        flash.info("Please select account type to sign up.")
        return redirect(url_for(".account_type"))

    if account_type == ACCOUNT_TYPE_COMMERCIAL:
        tier_id = session.fetch_data(SESSION_KEY_TIER_ID)
        if not tier_id:
            flash.info("Please select account type to sign up.")
            return redirect(url_for(".account_type"))
        return redirect(url_for(".signup_commercial", tier_id=tier_id))
    else:
        return redirect(url_for(".signup_noncommercial"))
예제 #11
0
def signup():
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if mb_username is None:
        # Show template with a link to MusicBrainz OAuth page
        return render_template('users/mb-signup.html')

    account_type = session.fetch_data(SESSION_KEY_ACCOUNT_TYPE)
    if not account_type:
        flash.info(gettext("Please select account type to sign up."))
        return redirect(url_for(".account_type"))

    if account_type == ACCOUNT_TYPE_COMMERCIAL:
        tier_id = session.fetch_data(SESSION_KEY_TIER_ID)
        if not tier_id:
            flash.info(gettext("Please select account type to sign up."))
            return redirect(url_for(".account_type"))
        return redirect(url_for(".signup_commercial", tier_id=tier_id))
    else:
        return redirect(url_for(".signup_noncommercial"))
예제 #12
0
def signup_noncommercial():
    """Sign up endpoint for non-commercial users."""
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_NONCOMMERCIAL,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = NonCommercialSignUpForm(default_email=mb_email)
    if form.validate_on_submit():
        # Checking if this user already exists
        new_user = User.get(musicbrainz_id=mb_username)
        if not new_user:
            new_user = User.add(
                is_commercial=False,
                musicbrainz_id=mb_username,
                contact_name=form.contact_name.data,
                contact_email=form.contact_email.data,
                data_usage_desc=form.usage_desc.data,
            )
            flash.success(gettext("Thanks for signing up!"))
            try:
                send_mail(
                    subject="[MetaBrainz] Sign up confirmation",
                    text='Dear %s,\n\nThank you for signing up!\n\nYou can now generate '
                         'an access token for the MetaBrainz API on your profile page.'
                         % new_user.contact_name,
                    recipients=[new_user.contact_email],
                )
            except MailException as e:
                logging.error(e)
                flash.warning(gettext(
                    "Failed to send welcome email to you. We are looking into it. "
                    "Sorry for inconvenience!"
                ))
        else:
            flash.info(gettext("You already have a MetaBrainz account!"))
        login_user(new_user)
        return redirect(url_for('.profile'))

    return render_template("users/signup-non-commercial.html", form=form, mb_username=mb_username)
예제 #13
0
def musicbrainz_post():
    """MusicBrainz OAuth2 callback endpoint."""
    if not musicbrainz_login.validate_post_login():
        raise BadRequest(gettext("Login failed!"))
    code = request.args.get('code')
    if not code:
        raise InternalServerError(gettext("Authorization code is missing!"))
    mb_username, mb_email = musicbrainz_login.get_user(code)
    session.persist_data(**{
        SESSION_KEY_MB_USERNAME: mb_username,
        SESSION_KEY_MB_EMAIL: mb_email,
    })
    user = User.get(musicbrainz_id=mb_username)
    if user:  # Checking if user is already signed up
        login_user(user)
        next = session.session.get('next')
        return redirect(next) if next else redirect(url_for('.profile'))
    else:
        flash.info("This is the first time you've signed into metabrainz.org, please sign up!")
        return redirect(url_for('.signup'))
예제 #14
0
 def revoke_token(self):
     token_value = request.args.get('token_value')
     token = Token.get(value=token_value)
     token.revoke()
     flash.info('Token %s has been revoked.' % token_value)
     return redirect(url_for('.details', user_id=token.owner_id))
예제 #15
0
 def revoke_token(self):
     token_value = request.args.get('token_value')
     token = Token.get(value=token_value)
     token.revoke()
     flash.info('Token %s has been revoked.' % token_value)
     return redirect(url_for('.details', user_id=token.owner_id))
예제 #16
0
def signup_commercial():
    """Sign up endpoint for commercial users.

    Commercial users need to choose support tier before filling out the form.
    `tier_id` argument with ID of a tier of choice is required there.
    """
    tier_id = request.args.get('tier_id')
    if not tier_id:
        flash.warn("You need to choose support tier before signing up!")
        return redirect(url_for('.account_type'))
    selected_tier = Tier.get(id=tier_id)
    if not selected_tier or not selected_tier.available:
        flash.error("You need to choose existing tier before signing up!")
        return redirect(url_for(".account_type"))

    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_COMMERCIAL,
            SESSION_KEY_TIER_ID: selected_tier.id,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = CommercialSignUpForm(default_email=mb_email)

    def custom_validation(f):
        if f.amount_pledged.data < selected_tier.price:
            flash.warning("Custom amount must be more than threshold amount"
                          "for selected tier or equal to it!")
            return False
        return True

    if form.validate_on_submit() and custom_validation(form):
        # Checking if this user already exists
        new_user = User.get(musicbrainz_id=mb_username)
        if not new_user:
            new_user = User.add(
                is_commercial=True,
                musicbrainz_id=mb_username,
                contact_name=form.contact_name.data,
                contact_email=form.contact_email.data,
                data_usage_desc=form.usage_desc.data,

                org_name=form.org_name.data,
                org_desc=form.org_desc.data,
                website_url=form.website_url.data,
                org_logo_url=form.logo_url.data,
                api_url=form.api_url.data,

                address_street=form.address_street.data,
                address_city=form.address_city.data,
                address_state=form.address_state.data,
                address_postcode=form.address_postcode.data,
                address_country=form.address_country.data,

                tier_id=tier_id,
                amount_pledged=form.amount_pledged.data,
            )
            flash.success("Thanks for signing up! Your application will be reviewed "
                          "soon. We will send you updates via email.")
            send_mail(
                subject="[MetaBrainz] Sign up confirmation",
                text='Dear %s,\n\nThank you for signing up!\n\nYour application'
                     ' will be reviewed soon. We will send you updates via email.'
                     % new_user.contact_name,
                recipients=[new_user.contact_email],
            )
        else:
            flash.info("You already have a MetaBrainz account!")
        login_user(new_user)
        return redirect(url_for('.profile'))

    return render_template("users/signup-commercial.html", form=form, tier=selected_tier, mb_username=mb_username)
예제 #17
0
def signup_commercial():
    """Sign up endpoint for commercial users.

    Commercial users need to choose support tier before filling out the form.
    `tier_id` argument with ID of a tier of choice is required there.
    """
    tier_id = request.args.get('tier_id')
    if not tier_id:
        flash.warn(
            gettext("You need to choose support tier before signing up!"))
        return redirect(url_for('.account_type'))
    selected_tier = Tier.get(id=tier_id)
    if not selected_tier or not selected_tier.available:
        flash.error(
            gettext("You need to choose existing tier before signing up!"))
        return redirect(url_for(".account_type"))

    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(
            **{
                SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_COMMERCIAL,
                SESSION_KEY_TIER_ID: selected_tier.id,
            })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = CommercialSignUpForm(default_email=mb_email)

    def custom_validation(f):
        if f.amount_pledged.data < selected_tier.price:
            flash.warning(
                gettext("Custom amount must be more than threshold amount"
                        "for selected tier or equal to it!"))
            return False
        return True

    if form.validate_on_submit() and custom_validation(form):
        # Checking if this user already exists
        new_user = User.get(musicbrainz_id=mb_username)
        if not new_user:
            new_user = User.add(
                is_commercial=True,
                musicbrainz_id=mb_username,
                contact_name=form.contact_name.data,
                contact_email=form.contact_email.data,
                data_usage_desc=form.usage_desc.data,
                org_name=form.org_name.data,
                org_desc=form.org_desc.data,
                website_url=form.website_url.data,
                org_logo_url=form.logo_url.data,
                api_url=form.api_url.data,
                address_street=form.address_street.data,
                address_city=form.address_city.data,
                address_state=form.address_state.data,
                address_postcode=form.address_postcode.data,
                address_country=form.address_country.data,
                tier_id=tier_id,
                amount_pledged=form.amount_pledged.data,
            )
            flash.success(
                gettext(
                    "Thanks for signing up! Your application will be reviewed "
                    "soon. We will send you updates via email."))
            try:
                send_mail(
                    subject="[MetaBrainz] Sign up confirmation",
                    text=
                    'Dear %s,\n\nThank you for signing up!\n\nYour application'
                    ' will be reviewed soon. We will send you updates via email.'
                    % new_user.contact_name,
                    recipients=[new_user.contact_email],
                )
            except MailException as e:
                logging.error(e)
                flash.warn(
                    gettext(
                        "Failed to send welcome email to you. We are looking into it. "
                        "Sorry for inconvenience!"))
        else:
            flash.info(gettext("You already have a MetaBrainz account!"))
        login_user(new_user)
        return redirect(url_for('.profile'))

    return render_template("users/signup-commercial.html",
                           form=form,
                           tier=selected_tier,
                           mb_username=mb_username)