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 update(request):
    """Updates a User or UserProfile

    It is important to note that UserUpdateForm only updates the fields on User and UserProfile that are passed in, and does not have to update the entire object
    """
    user = request.user
    from htk.apps.accounts.forms.update import UserUpdateForm
    user_update_form = UserUpdateForm(user, request.POST)
    user_profile_update_form = user_update_form.get_profile_form()
    if user_update_form.is_valid() and user_profile_update_form.is_valid():
        updated_user = user_update_form.save()
        updated_profile = user_profile_update_form.save()
        response = json_response_okay()
    else:
        (
            errors,
            field_errors,
        ) = get_form_errors(user_update_form)
        (
            profile_errors,
            profile_field_errors,
        ) = get_form_errors(user_profile_update_form)
        obj = {
            HTK_API_JSON_KEY_STATUS: HTK_API_JSON_VALUE_ERROR,
            'errors': errors + profile_errors,
            'field_errors': field_errors + profile_field_errors,
        }
        response = json_response(obj)
    return response
Exemplo n.º 3
0
def debugger(request):
    import rollbar
    message = request.GET.get('m')
    rollbar.report_message(message, 'debug')
    from htk.api.utils import json_response_okay
    response = json_response_okay()
    return response
Exemplo n.º 4
0
def debugger(request):
    import rollbar
    message = request.GET.get('m')
    rollbar.report_message(message, 'debug')
    from htk.api.utils import json_response_okay
    response = json_response_okay()
    return response
Exemplo n.º 5
0
def dss_321forms_webhook_view(request):
    try:
        webhook_data = validate_webhook_request(request)

        if webhook_data:
            handle_webhook_request(webhook_data)
            response = json_response_okay()
        else:
            response = HttpResponseForbidden()
    except ValueError:
        rollbar.report_exc_info(request=request)
        response = json_response_okay()
    except Exception:
        rollbar.report_exc_info(request=request)
        response = json_response_okay()

    return response
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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.º 19
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.º 20
0
def username(request):
    """Update a User's username
    """
    user = request.user
    username_form = ChangeUsernameForm(user, request.POST)
    if username_form.is_valid():
        username_form.save(user)
        response = json_response_okay()
    else:
        obj = {
            HTK_API_JSON_KEY_STATUS: HTK_API_JSON_VALUE_ERROR,
            'error': get_form_error(username_form)
        }
        response = json_response(obj)
    return response
Exemplo n.º 21
0
def username(request):
    """Update a User's username
    """
    user = request.user
    username_form = ChangeUsernameForm(user, request.POST)
    if username_form.is_valid():
        username_form.save(user)
        response = json_response_okay()
    else:
        obj = {
            HTK_API_JSON_KEY_STATUS: HTK_API_JSON_VALUE_ERROR,
            'error' : get_form_error(username_form)
        }
        response = json_response(obj)
    return response
Exemplo n.º 22
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.º 23
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.º 24
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.º 25
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.º 26
0
def email_add(request):
    user = request.user
    add_email_form = AddEmailForm(user, request.POST)
    if add_email_form.is_valid():
        domain = request.get_host()
        user_email = add_email_form.save(domain=domain)
        response = json_response_okay()
    else:
        errors = []
        for error in add_email_form.non_field_errors():
            errors.append(error)
        obj = {
            HTK_API_JSON_KEY_STATUS: HTK_API_JSON_VALUE_ERROR,
            'errors': errors,
        }
        response = json_response(obj)
    return response
Exemplo n.º 27
0
def email_add(request):
    user = request.user
    add_email_form = AddEmailForm(user, request.POST)
    if add_email_form.is_valid():
        domain = request.get_host()
        user_email = add_email_form.save(domain=domain)
        response = json_response_okay()
    else:
        errors = []
        for error in add_email_form.non_field_errors():
            errors.append(error)
        obj = {
            HTK_API_JSON_KEY_STATUS: HTK_API_JSON_VALUE_ERROR,
            'errors': errors,
        }
        response = json_response(obj)
    return response
Exemplo n.º 28
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.º 29
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.º 30
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.º 31
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.º 32
0
def update(request):
    """Updates a User or UserProfile

    It is important to note that UserUpdateForm only updates the fields on User and UserProfile that are passed in, and does not have to update the entire object
    """
    user = request.user
    from htk.apps.accounts.forms.update import UserUpdateForm
    user_update_form = UserUpdateForm(user, request.POST)
    user_profile_update_form = user_update_form.get_profile_form()
    if user_update_form.is_valid() and user_profile_update_form.is_valid():
        updated_user = user_update_form.save()
        updated_profile = user_profile_update_form.save()
        response = json_response_okay()
    else:
        (errors, field_errors,) = get_form_errors(user_update_form)
        (profile_errors, profile_field_errors,) = get_form_errors(user_profile_update_form)
        obj = {
            HTK_API_JSON_KEY_STATUS: HTK_API_JSON_VALUE_ERROR,
            'errors' : errors + profile_errors,
            'field_errors' : field_errors + profile_field_errors,
        }
        response = json_response(obj)
    return response
Exemplo n.º 33
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.º 34
0
def logout_view(request):
    logout(request)
    reponse = json_response_okay()
    return response
Exemplo n.º 35
0
def logout_view(request):
    logout(request)
    reponse = json_response_okay()
    return response