예제 #1
0
def change_email_opt_in(request):    
    """
    Allows user to opt in or opt out of email newsletters.
    
    """
    
    Logger.Info("%s - change_email_opt_in - started" % __name__)
    if not request.method == 'POST':
        return redirect('/delv/%s' % request.user.username)
    
    opt_in_status = request.POST.get('opt_in_status')
    
    controller = UserController(request.user)
    passed, errors = controller.change_email_opt_in(opt_in_status)
    
    template_data = _base_template_data(request)
    
    if errors:
        template_data['messages'] = errors
        template_data['opt_in_status'] = opt_in_status
    else:
        template_data['messages'] = ['Your email opt-in status has been updated successfully.']
    
    template_data['facebook_api_key'] = settings.FACEBOOK_SETTINGS['api_key']
    template_data['facebook_permissions'] = ','.join(settings.FACEBOOK_SETTINGS['requested_permissions'])
    template_data['twitter_api_key'] = settings.TWITTER_SETTINGS['api_key']
    
    Logger.Info('%s - change_email_opt_in - finished' % __name__)
    
    return render_to_response(
        'thecommunity/account_page/account_page.html',
        template_data,
        context_instance=RequestContext(request)
    )
예제 #2
0
def current_subscription(request):
    user = request.user
    uc = UserController(user)
    user_subscriptions = uc.get_user_subscriptions()
    current_active_subscription_name = user_subscriptions['active_subscription']
    current_active_subscription = settings.SUBSCRIPTIONS_SETTINGS['subscriptions'][current_active_subscription_name]
    return render_to_response(
        'thecommunity/account_page/_old/account_page_user_account_management_current_subscription.html',
        { 'subscription':current_active_subscription }
    )
예제 #3
0
def link_twitter_profile(request):
    """
    Associates a Twitter profile to a metaLayer user account.

    """

    if not request.method == 'POST':
        return redirect('/community/%s' % request.user.username)

    screen_name = request.POST.get('screen_name')

    controller = UserController(request.user)
    passed, errors = controller.link_twitter_profile(screen_name)

    # return profile pic location to caller so front-end can display profile picture
    if passed:
        return JSONResponse({'profile_picture': request.user.profile.profile_image() })
    else:
        return JSONResponse({'errors': errors })
예제 #4
0
def link_facebook_profile(request):
    """
    Associates a Facebook profile to a metaLayer user account.
    
    """
    
    if not request.method == 'POST':
        return redirect('/delv/%s' % request.user.username)
    
    facebook_id = request.POST.get('facebook_id')
    access_token = request.POST.get('access_token')
    
    controller = UserController(request.user)
    passed, errors = controller.link_facebook_profile(facebook_id, access_token)
    
    # return profile pic location to caller so front-end can display profile picture
    if passed:
        return JSONResponse({'profile_picture': request.user.profile.profile_image() })
    else:
        return JSONResponse({'errors': errors })
예제 #5
0
def change_password(request):
    """
    Allows logged-in user to change their password.
    
    """
    
    Logger.Info("%s - change_password - started" % __name__)
    if not request.method == 'POST':
        return redirect('/delv/%s' % request.user.username)
    
    current_password = request.POST.get('current_password')
    new_password = request.POST.get('new_password')
    confirm_password = request.POST.get('confirm_password')
    
    controller = UserController(request.user)
    passed, errors = controller.change_password(current_password, new_password, confirm_password)
    
    template_data = _base_template_data(request)
    
    if errors:
        template_data['messages'] = errors
        template_data['current_password'] = current_password
        template_data['new_password'] = new_password
        template_data['confirm_password'] = confirm_password
    else:
        template_data['messages'] = ['Your password has been changed successfully!']
    
    template_data['facebook_api_key'] = settings.FACEBOOK_SETTINGS['api_key']
    template_data['facebook_permissions'] = ','.join(settings.FACEBOOK_SETTINGS['requested_permissions'])
    template_data['twitter_api_key'] = settings.TWITTER_SETTINGS['api_key']
    
    Logger.Info('%s - change_password - finished' % __name__)
    
    return render_to_response(
        'thecommunity/account_page/account_page.html',
        template_data,
        context_instance=RequestContext(request)
    )
예제 #6
0
def change_subscription(request):
    Logger.Info("%s - change_subscription - started" % __name__)
    user = request.user
    if request.method == 'GET':
        if not 'subscription_id' in request.GET:
            uc = UserController(user)
            user_subscriptions = uc.get_user_subscriptions()
            current_active_subscription_name = user_subscriptions['active_subscription']
            available_subscriptions = [settings.SUBSCRIPTIONS_SETTINGS['subscriptions'][sub] for sub in settings.SUBSCRIPTIONS_SETTINGS['subscriptions'].keys() if sub != current_active_subscription_name]
            Logger.Info('%s - change_subscription - finished' % __name__)
            return render_to_response(
                'thecommunity/account_page/_old/account_page_user_account_management_list_available_subscriptions.html',
                    { 'subscriptions':available_subscriptions }
            )
        else:
            subscription_id = request.GET['subscription_id']
            subscription = [sub for sub in settings.SUBSCRIPTIONS_SETTINGS['subscriptions'].values() if sub['id'] == subscription_id][0]
            uc = UserController(user)
            subscription_migration_direction = uc.subscription_migration_direction(subscription['id'])
            template_name = 'thedashboard/change_subscriptions/%s' % subscription['templates'][subscription_migration_direction]
            Logger.Info('%s - change_subscription - finished' % __name__)
            return render_to_response(
                template_name,
                    {
                    'subscription':subscription,
                    'show_credit_card_form':uc.need_to_ask_for_credit_card_details()
                },
                context_instance=RequestContext(request)
            )
    else:
        if 'credit_card_number' in request.POST:
            credit_card_number = request.POST['credit_card_number']
            if credit_card_number != '0' and credit_card_number != '1':
                #TODO: this is just for the tests
                Logger.Info('%s - change_subscription - finished' % __name__)
                return JSONResponse({'errors':['Enter credit card number "1" to pass and "0" to fail']})

            first_name = request.POST['first_name'].strip()
            last_name = request.POST['last_name'].strip()

            if not first_name or not last_name:
                Logger.Info('%s - change_subscription - finished' % __name__)
                return JSONResponse({'errors':['You must provide your first and last name']})

            user.first_name = first_name
            user.last_name = last_name
            user.save()
            credit_card_data = {
                'number':credit_card_number,
                'expiry_month':request.POST['credit_card_expiry_month'],
                'expiry_year':int(request.POST['credit_card_expiry_year'])
            }
        else:
            credit_card_data = None

        new_subscription_id = request.POST['subscription_id']
        uc = UserController(user)
        subscription_changed = uc.change_user_subscription(
            new_subscription_id,
            credit_card_data
        )
        if not subscription_changed:
            Logger.Info('%s - change_subscription - finished' % __name__)
            return JSONResponse({'errors':['There was an error process your card details, please try again later']})

        maximum_number_of_dashboards = settings.SUBSCRIPTIONS_SETTINGS['subscriptions'][new_subscription_id]['config']['number_of_saved_dashboards']
        dc = DashboardsController(user)
        dc.delete_dashboards_to_match_subscription(maximum_number_of_dashboards)

        Logger.Info('%s - change_subscription - finished' % __name__)
        return JSONResponse()
예제 #7
0
def logout(request):
    uc = UserController(request.user)
    uc.logout_user(request)
    return redirect(community_page)