Exemplo n.º 1
0
def cpq_pay(request, cpq_code, cpq_type):
    from htk.apps.cpq.utils import resolve_cpq_code
    cpq_obj = resolve_cpq_code(cpq_code, cpq_type=cpq_type)
    if cpq_obj is None:
        raise Http404
    if not htk_setting('HTK_CPQ_PAY_ONLINE'):
        raise Http404

    success = False
    try:
        stripe_token = request.POST.get('stripeToken')
        amount = int(request.POST.get('amount'))
        email = request.POST.get('email')
        line_item_ids = request.POST.get('lineItemIds').split(',')
        success = cpq_obj.approve_and_pay(stripe_token, amount, email,
                                          line_item_ids)
    except ValueError:
        # most likely encountered exception parsing `amount` or `line_item_ids`
        pass

    if success:
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 2
0
def dismiss_alert(request):
    user = request.user
    success = False
    if request.user.is_authenticated():
        alert_name = request.POST.get('alert_name')
        success = dismiss_alert_for_user(user, alert_name)

    response = json_response_okay() if success else json_response_error()
    return response
Exemplo n.º 3
0
def email_delete(request):
    user = request.user
    email = request.POST.get('email')
    user_email = get_object_or_404(UserEmail, user=user, email=email)
    if user_email.delete():
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 4
0
def email_delete(request):
    user = request.user
    email = request.POST.get('email')
    user_email = get_object_or_404(UserEmail, user=user, email=email)
    if user_email.delete():
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 5
0
def email_set_primary(request):
    user = request.user
    email = request.POST.get('email')
    user_email = get_object_or_404(UserEmail, user=user, email=email)
    user = user_email.set_primary_email()
    if user:
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 6
0
def login_view(request):
    from htk.apps.accounts.forms.auth import UsernameEmailAuthenticationForm
    auth_form = UsernameEmailAuthenticationForm(None, request.POST)
    if auth_form.is_valid():
        user = auth_form.get_user()
        login(request, user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 7
0
def email_set_primary(request):
    user = request.user
    email = request.POST.get('email')
    user_email = get_object_or_404(UserEmail, user=user, email=email)
    user = user_email.set_primary_email()
    if user:
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 8
0
def login_view(request):
    from htk.apps.accounts.forms.auth import UsernameEmailAuthenticationForm
    auth_form = UsernameEmailAuthenticationForm(None, request.POST)
    if auth_form.is_valid():
        user = auth_form.get_user()
        login_authenticated_user(request, user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 9
0
def unfollow(request, encrypted_uid):
    """Unfollow another user
    """
    user = request.user
    other_user = resolve_encrypted_uid(encrypted_uid)
    if other_user:
        user.profile.unfollow_user(other_user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 10
0
def unfollow(request, encrypted_uid):
    """Unfollow another user
    """
    user = request.user
    other_user = resolve_encrypted_uid(encrypted_uid)
    if other_user:
        user.profile.unfollow_user(other_user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 11
0
def password(request):
    """Update a User's password
    """
    user = request.user
    password_form = ChangePasswordForm(user, request.POST)
    if password_form.is_valid():
        password_form.save(user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 12
0
def avatar(request):
    json_data = json.loads(request.body)

    avatar_type = json_data['type']
    if avatar_type in AVATAR_TYPES:
        user = request.user
        profile = user.profile
        profile.avatar = avatar_type
        profile.save(update_fields=['avatar',])
        response = json_response_okay()
    else:
        response = json_response_error()

    return response
Exemplo n.º 13
0
def password(request):
    """Update a User's password
    """
    user = request.user
    password_form = ChangePasswordForm(user, request.POST)
    if password_form.is_valid():
        user = password_form.save(user)
        if htk_setting('HTK_ACCOUNTS_CHANGE_PASSWORD_UPDATE_SESSION_AUTH_HASH'):
            from django.contrib.auth import update_session_auth_hash
            update_session_auth_hash(request, user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 14
0
def submit(request):
    success = False

    antispam = request.POST.get(HTK_API_KEY_ANTISPAM) == HTK_API_VALUE_ANTISPAM_CHALLENGE_RESPONSE
    feedback_form = FeedbackForm(request.POST)
    if antispam and feedback_form.is_valid():
        site = get_current_site(request)
        success = True
        feedback = feedback_form.save(site, request)
    data = {}
    if success:
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 15
0
def submit(request):
    success = False

    antispam = request.POST.get(HTK_API_KEY_ANTISPAM) == HTK_API_VALUE_ANTISPAM_CHALLENGE_RESPONSE
    feedback_form = FeedbackForm(request.POST)
    if antispam and feedback_form.is_valid():
        site = get_current_site(request)
        success = True
        feedback = feedback_form.save(site, request)
    data = {}
    if success:
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 16
0
def password(request):
    """Update a User's password
    """
    user = request.user
    password_form = ChangePasswordForm(user, request.POST)
    if password_form.is_valid():
        user = password_form.save(user)
        if htk_setting(
                'HTK_ACCOUNTS_CHANGE_PASSWORD_UPDATE_SESSION_AUTH_HASH'):
            from django.contrib.auth import update_session_auth_hash
            update_session_auth_hash(request, user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 17
0
def avatar(request):
    """Update a User's avatar to the specified type
    """
    json_data = json.loads(request.body)

    avatar_type_name = json_data['type']
    if avatar_type_name in ProfileAvatarType.__members__:
        user = request.user
        profile = user.profile
        profile.avatar = ProfileAvatarType[avatar_type_name].value
        profile.save(update_fields=['avatar',])
        response = json_response_okay()
    else:
        response = json_response_error()

    return response
Exemplo n.º 18
0
def avatar(request):
    """Update a User's avatar to the specified type
    """
    json_data = json.loads(request.body)

    avatar_type_name = json_data['type']
    if avatar_type_name in ProfileAvatarType.__members__:
        user = request.user
        profile = user.profile
        profile.avatar = ProfileAvatarType[avatar_type_name].value
        profile.save(update_fields=[
            'avatar',
        ])
        response = json_response_okay()
    else:
        response = json_response_error()

    return response
Exemplo n.º 19
0
def suggest(request):
    """This API endpoint supports User autocomplete
    """
    from htk.apps.accounts.formatters import DEFAULT_USER_SUGGEST_FORMATTER
    from htk.apps.accounts.search import search_by_username_name
    query = request.GET.get('q')
    if query:
        query = query.strip()
        user_results = search_by_username_name(query)
        formatted_results = [DEFAULT_USER_SUGGEST_FORMATTER(user) for user in user_results]
        obj = {
            'data' : {
                'results' : formatted_results,
            },
        }
        response = json_response(obj)
    else:
        response = json_response_error()
    return response
Exemplo n.º 20
0
def settings(request):
    data = wrap_data_accounts(request)
    data.update(csrf(request))    
    user = data['user']

    data['social_auths_status'] = get_social_auths_status(user)
    data['user_update_forms'] = get_user_update_forms(user)

    if request.method == 'POST':
        user_update_form_class = get_user_update_form(request)
        user_update_form = user_update_form_class(user, request.POST)
        if user_update_form.is_valid():
            success = True
            result = user_update_form.save()
            response = json_response_okay()
        else:
            response = json_response_error()
    else:
        response = _r('account/settings.html', data)
    return response
Exemplo n.º 21
0
def suggest(request):
    """This API endpoint supports User autocomplete
    """
    from htk.apps.accounts.formatters import DEFAULT_USER_SUGGEST_FORMATTER
    from htk.apps.accounts.search import search_by_username_name
    query = request.GET.get('q')
    if query:
        query = query.strip()
        user_results = search_by_username_name(query)
        formatted_results = [
            DEFAULT_USER_SUGGEST_FORMATTER(user) for user in user_results
        ]
        obj = {
            'data': {
                'results': formatted_results,
            },
        }
        response = json_response(obj)
    else:
        response = json_response_error()
    return response
Exemplo n.º 22
0
def slack_beacon_view(request):
    """Receiver for Slack homing beacon
    """

    beacon_key = request.GET.get('k')
    from htk.lib.slack.beacon.cachekeys import SlackBeaconCache
    c = SlackBeaconCache(prekey=beacon_key)
    beacon = c.get()
    ip = extract_request_ip(request)
    if beacon:
        from htk.lib.slack.messages import slack_message_geoip
        slack_text = slack_message_geoip(ip, beacon['user_name'])
        from htk.lib.slack.utils import webhook_call
        webhook_call(
            webhook_url=beacon['slack_webhook_url'],
            channel=beacon['channel_name'],
            text=slack_text,
        )
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 23
0
def email_delete(request):
    user = request.user
    email = request.POST.get('email')

    if user.profile.is_company_employee:
        # admin user, grab only by email
        user_email = get_object_or_404(UserEmail, email=email)
    else:
        # regular user, retrieve by user and email
        from htk.apps.accounts.utils import get_user_email
        user_email = get_user_email(user, email)

    if user_email:
        if user_email.delete():
            response = json_response_okay()
        else:
            response = json_response_error()
    else:
        # email does not exist or was already deleted
        response = json_response_okay()

    return response
Exemplo n.º 24
0
def slack_beacon_view(request):
    """Receiver for Slack homing beacon
    """

    beacon_key = request.GET.get('k')
    from htk.lib.slack.beacon.cachekeys import SlackBeaconCache
    c = SlackBeaconCache(prekey=beacon_key)
    beacon = c.get()
    ip = extract_request_ip(request)
    if beacon:
        from htk.lib.slack.messages import slack_message_geoip
        slack_text = slack_message_geoip(ip, beacon['user_name'])
        from htk.lib.slack.utils import webhook_call
        webhook_call(
            webhook_url=beacon['slack_webhook_url'],
            channel=beacon['channel_name'],
            text=slack_text,
        )
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Exemplo n.º 25
0
def email_delete(request):
    user = request.user
    email = request.POST.get('email')

    if user.profile.is_company_employee:
        # admin user, grab only by email
        user_email = get_object_or_404(UserEmail, email=email)
    else:
        # regular user, retrieve by user and email
        from htk.apps.accounts.utils import get_user_email
        user_email = get_user_email(user, email)

    if user_email:
        if user_email.delete():
            response = json_response_okay()
        else:
            response = json_response_error()
    else:
        # email does not exist or was already deleted
        response = json_response_okay()

    return response
Exemplo n.º 26
0
def suggest(request):
    """This API endpoint supports User autocomplete
    First retrieve from followers and following, then search all users
    """
    query = request.GET.get('q')
    if query:
        query = query.strip()
        user_results = User.objects.filter(username__istartswith=query)
        results = [
            {
                'username' : user.username,
            }
            for user in user_results
        ]
        obj = {
            'data' : {
                'results' : results,
            },
        }
        response = json_response(obj)
    else:
        response = json_response_error()
    return response
Exemplo n.º 27
0
def cpq_pay(request, cpq_code, cpq_type):
    from htk.apps.cpq.utils import resolve_cpq_code
    cpq_obj = resolve_cpq_code(cpq_code, cpq_type=cpq_type)
    if cpq_obj is None:
        raise Http404
    if not htk_setting('HTK_CPQ_PAY_ONLINE'):
        raise Http404

    success = False
    try:
        stripe_token = request.POST.get('stripeToken')
        amount = int(request.POST.get('amount'))
        email = request.POST.get('email')
        line_item_ids = request.POST.get('lineItemIds').split(',')
        success = cpq_obj.approve_and_pay(stripe_token, amount, email, line_item_ids)
    except ValueError:
        # most likely encountered exception parsing `amount` or `line_item_ids`
        pass

    if success:
        response = json_response_okay()
    else:
        response = json_response_error()
    return response