def _build_absolute_uri(appended_address):
    url = env("LITE_API_URL") + appended_address

    if not url.endswith("/") and "?" not in url:
        url = url + "/"

    return url
Beispiel #2
0
def _get_hawk_sender(url, method, content_type, content):
    return Sender(
        {"id": "internal-frontend", "key": env("LITE_INTERNAL_HAWK_KEY"), "algorithm": "sha256"},
        url,
        method,
        content_type=content_type,
        content=content,
        seen_nonce=_seen_nonce,
    )
def _get_hawk_sender(url, method, content_type, content):
    return Sender(
        {
            "id": "exporter-frontend",
            "key": env("LITE_EXPORTER_HAWK_KEY"),
            "algorithm": "sha256"
        },
        url,
        method,
        content_type=content_type,
        content=content,
        seen_nonce=_seen_nonce,
    )
def export_vars(request):
    data = {
        "SERVICE_NAME":
        "LITE",
        "GOV_UK_URL":
        "https://www.gov.uk",
        "FEEDBACK_URL":
        env("FEEDBACK_URL"),
        "INTERNAL_URL":
        env("INTERNAL_FRONTEND_URL"),
        "GOOGLE_ANALYTICS_KEY":
        env("GOOGLE_ANALYTICS_KEY"),
        "CURRENT_PATH":
        request.get_full_path(),
        "CURRENT_PATH_WITHOUT_PARAMS":
        request.get_full_path().split("?")[0].split("#")[0],
        "USER_PERMISSIONS":
        Permissions,
        "AUTHBROKER_URL":
        AUTHBROKER_URL,
    }
    return data
Beispiel #5
0
def login(request):
    if request.method == 'GET':
        context = {
            'title': get_string('misc.sign_in'),
        }
        return render(request, 'core/login.html', context)

    if request.method == 'POST':
        response = requests.post(env('LITE_API_URL') + '/users/authenticate/',
                                 json={
                                     'email': request.POST.get('email'),
                                     'password': request.POST.get('password'),
                                 },
                                 )

        # If login isn't successful, return previous page
        if response.status_code is not 200:
            context = {
                'title': get_string('misc.sign_in'),
                'error': True,
                'email': request.POST.get('email'),
            }
            return render(request, 'core/login.html', context)

        user_data = response.json().get('user')

        user_object, created = User.objects.get_or_create(id=user_data.get('id'), defaults={
            'email': user_data.get('email'),
            'first_name': user_data.get('first_name'),
            'last_name': user_data.get('last_name'),
        })

        django_login(request, user=user_object)

        # Redirect to index page as a signed in user
        return redirect('/')
def get(request, appended_address):
    return requests.get(env("LITE_API_URL") + appended_address,
                        headers={'USER-ID': str(request.user.id)})
def put(request, appended_address, json):
    return requests.put(env("LITE_API_URL") + appended_address,
                        json=json,
                        headers={'USER-ID': str(request.user.id)})
Beispiel #8
0
import functools
from urllib.parse import urljoin

from django.conf import settings
from django.shortcuts import redirect
from django.urls import reverse
from requests_oauthlib import OAuth2Session

from conf.settings import env

TOKEN_SESSION_KEY = env("TOKEN_SESSION_KEY")
PROFILE_URL = urljoin(settings.AUTHBROKER_URL, "sso/oauth2/user-profile/v1/")
INTROSPECT_URL = urljoin(settings.AUTHBROKER_URL, "sso/oauth2/introspect/")
TOKEN_URL = urljoin(settings.AUTHBROKER_URL, "sso/oauth2/token/")
AUTHORISATION_URL = urljoin(settings.AUTHBROKER_URL, "sso/oauth2/authorize/")
TOKEN_CHECK_PERIOD_SECONDS = 60
SCOPE = "profile"


def get_client(request, **kwargs):
    callback_url = reverse("auth:callback")
    redirect_uri = request.build_absolute_uri(callback_url)

    return OAuth2Session(
        settings.AUTHBROKER_CLIENT_ID,
        redirect_uri=redirect_uri,
        scope=SCOPE,
        token=request.session.get(TOKEN_SESSION_KEY, None),
        **kwargs,
    )
Beispiel #9
0
from conf.settings import env
from core.form_components import Form, Question, InputType, ArrayQuestion, Option

form = Form(title='Add Good', description='', caption='', questions=[
    Question(title='Description of good',
             description='This can make it easier to find your good later',
             input_type=InputType.TEXTAREA,
             name='description',
             extras={
                 'max_length': 280,
             }),
    ArrayQuestion(title='Is your good controlled?',
                  description='If you don\'t know you can use <a class="govuk-link" href="' + env('PERMISSIONS_FINDER_URL') + '">Permissions Finder</a>.',
                  input_type=InputType.RADIOBUTTONS,
                  name='is_good_controlled',
                  data=[
                      Option(key='yes',
                             value='Yes',
                             show_pane='pane_control_code'),
                      Option(key='no',
                             value='No')
                  ]),
    Question(title='Control Code',
             description='If your good is controlled, enter its control code. For example, ML1a.',
             input_type=InputType.INPUT,
             name='control_code'),
    ArrayQuestion(title='Is your good intended to be incorporated into an end product?',
                  description='',
                  input_type=InputType.RADIOBUTTONS,
                  name='is_good_end_product',
                  data=[