Beispiel #1
0
def emails():
    """Main email settings.
    """
    if current_user.has_role('protected'):
        return abort(404)  # TODO: make this 403, handle template properly
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    # Force creation of settings for the user (safely remove this code once
    # implemented on account creation level, and after adding settings to all
    # existing users)
    if not user.settings:
        user.settings = dict(email_communications=1)
        user.update(api=api)

    if user.settings.email_communications is None:
        user.settings.email_communications = 1
        user.update(api=api)

    # Generate form
    form = forms.UserSettingsEmailsForm(
        email_communications=user.settings.email_communications)

    if form.validate_on_submit():
        try:
            user.settings.email_communications = form.email_communications.data
            user.update(api=api)
            flash("Profile updated", 'success')
        except sdk_exceptions.ResourceInvalid as e:
            message = json.loads(e.content)
            flash(message)

    return render_template('users/settings/emails.html',
                           form=form,
                           title='emails')
Beispiel #2
0
def profile():
    """Profile view and edit page. This is a temporary implementation.
    """
    if current_user.has_role('protected'):
        return abort(404)  # TODO: make this 403, handle template properly
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    form = forms.UserProfileForm(username=user.username)

    if form.validate_on_submit():
        try:
            response = user.set_username(form.username.data, api=api)
            log.info('updated username of %s: %s', current_user, response)
            flash("Profile updated", 'success')
        except sdk_exceptions.ResourceInvalid as ex:
            log.warning('unable to set username %s to %r: %s', current_user,
                        form.username.data, ex)
            message = json.loads(ex.content)
            flash(message)

    blender_id_endpoint = current_app.config['BLENDER_ID_ENDPOINT']
    blender_profile_url = urllib.parse.urljoin(blender_id_endpoint,
                                               'settings/profile')

    return render_template('users/settings/profile.html',
                           form=form,
                           title='profile',
                           blender_profile_url=blender_profile_url)
Beispiel #3
0
def billing():
    """View the subscription status of a user
    """
    from . import store

    log.debug('START OF REQUEST')

    if current_user.has_role('protected'):
        return abort(404)  # TODO: make this 403, handle template properly

    expiration_date = 'No subscription to expire'

    # Classify the user based on their roles and capabilities
    cap_subs = current_user.has_cap('subscriber')
    if current_user.has_role('demo'):
        user_cls = 'demo'
    elif not cap_subs and current_user.has_cap('can-renew-subscription'):
        # This user has an inactive but renewable subscription.
        user_cls = 'subscriber-expired'
    elif cap_subs:
        if current_user.has_role('subscriber'):
            # This user pays for their own subscription. Only in this case do we need to fetch
            # the expiration date from the Store.
            user_cls = 'subscriber'
            store_user = store.fetch_subscription_info(current_user.email)
            if store_user is None:
                expiration_date = 'Unable to reach Blender Store to check'
            else:
                expiration_date = store_user['expiration_date'][:10]

        elif current_user.has_role('org-subscriber'):
            # An organisation pays for this subscription.
            user_cls = 'subscriber-org'
        else:
            # This user gets the subscription cap from somewhere else (like an organisation).
            user_cls = 'subscriber-other'
    else:
        user_cls = 'outsider'

    return render_template('users/settings/billing.html',
                           user_cls=user_cls,
                           expiration_date=expiration_date,
                           title='billing')
Beispiel #4
0
def users_index():
    if not current_user.has_role('admin'):
        return abort(403)
    return render_template('users/index.html')