Exemplo n.º 1
0
async def link_password_form(request, link_id):
    try:
        form = PasswordForm(request)
        data = await check_auth_form(request, link_id)
        return html(template_loader(template_file='password_form.html',
                                    form=form,
                                    payload=data),
                    status=200)
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
Exemplo n.º 2
0
async def confirm_delete_link_view(request, user, link_id):
    try:
        link_data = await retrieve_link(request, link_id)
        return html(template_loader(template_file='delete.html',
                                    link_id=link_id,
                                    owner=link_data['owner'],
                                    endpoint=link_data['endpoint']),
                    status=200)
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
Exemplo n.º 3
0
async def update_link_form(request, user, link_id):
    try:
        form = UpdateForm(request)
        data = await check_update_form(request, link_id)
        return html(template_loader(
            template_file='edit_form.html',
            form=form,
            payload=data,
            default_password=config('DEFAULT_PASSWORD')),
                    status=200)
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
Exemplo n.º 4
0
async def redirect_link_view(request, link_endpoint):
    try:
        target = await redirect_link(request, link_endpoint)
        if (target[:10] == '/authorize/'):
            return redirect(target)

        return html(template_loader(
            template_file='redirect.html',
            link=target,
        ),
                    status=307)
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
Exemplo n.º 5
0
async def deactivate_link_view(request, user, link_id):
    try:
        await deactivate_link(request, link_id)
        params = '?origin=deactivate&status=deactivated'
        return redirect(f'/edit/{link_id}{params}')
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
Exemplo n.º 6
0
async def create_link_save(request, user):
    try:
        form = CreateForm(request)
        if not form.validate():
            raise FormInvalidException

        form_data = {
            'owner': user.email,
            'owner_id': user.id,
            'password': form.password.data,
            'endpoint': form.endpoint.data,
            'url': form.url.data,
            'switch_date': form.switch_date.data
        }
        await create_link(request, data=form_data)
        status, message = 201, 'Link created successfully'
    except FormInvalidException:
        status, message = 400, 'Form invalid'
    except DuplicateActiveLinkForbidden:
        status, message = 409, 'An active link with that name already exists'
    finally:
        return html(template_loader(
                        template_file='message.html',
                        payload=message,
                        status_code=str(status)
                    ), status=status)
Exemplo n.º 7
0
async def update_link_form(request, user, link_id):
    try:
        form = UpdateForm(request)
        data = await check_update_form(request, link_id)
        return html(template_loader(
                        template_file='edit_form.html',
                        form=form,
                        payload=data,
                        status_code='200'
                    ), status=200)
    except NotFoundException:
        return html(template_loader(
                        template_file='message.html',
                        payload='Link does not exist',
                        status_code='404'
                    ), status=404)
Exemplo n.º 8
0
async def link_password_form(request, link_id):
    try:
        form = PasswordForm(request)
        data = await check_auth_form(request, link_id)
        return html(template_loader(
                        template_file='password_form.html',
                        form=form,
                        payload=data,
                        status_code='200'
                    ), status=200)
    except NotFoundException:
        return html(template_loader(
                        template_file='message.html',
                        payload='Link has no password or does not exist',
                        status_code='404'
                    ), status=404)
Exemplo n.º 9
0
async def link_password_save(request, link_id):
    try:
        form = PasswordForm(request)
        link = await check_password(request, link_id, form)
        return html(template_loader(
            template_file='redirect.html',
            link=link,
        ),
                    status=307)
    except FormInvalidException:
        message = 'invalid-form'  # status = 400
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
    except AccessDeniedException:
        message = 'incorrect-password'  # status = 401

    params = f'?origin=authorize&status={message}'
    return redirect(f'/authorize/{link_id}{params}')
Exemplo n.º 10
0
async def redirect_link_view(request, link_endpoint):
    try:
        target = await redirect_link(request, link_endpoint)
        return redirect(target, status=307)
    except NotFoundException:
        return html(template_loader(template_file='message.html',
                                    payload='Link inactive or does not exist',
                                    status_code='404'),
                    status=404)
Exemplo n.º 11
0
async def reset_password_view(request, user, link_id):
    try:
        await reset_password(request, link_id)
        status, message = 200, 'Password reset successfully'
    except NotFoundException:
        status, message = 404, 'Link has no password or does not exist'
    finally:
        return html(template_loader(template_file='message.html',
                                    payload=message,
                                    status_code=str(status)),
                    status=status)
Exemplo n.º 12
0
async def activate_link_view(request, user, link_id):
    try:
        await activate_link(request, link_id)
        message = 'activated'  # status = 200
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
    except DuplicateActiveLinkForbidden:
        message = 'duplicate'  # status = 409

    params = f'?origin=activate&status={message}'
    return redirect(f'/edit/{link_id}{params}')
Exemplo n.º 13
0
async def delete_link_view(request, user, link_id):
    try:
        await delete_link(request, link_id)
        status, message = 200, 'Link deleted successfully'
    except NotFoundException:
        status, message = 404, 'Link does not exist'
    finally:
        return html(template_loader(template_file='message.html',
                                    payload=message,
                                    status_code=str(status)),
                    status=status)
Exemplo n.º 14
0
async def link_list_form(request, user):
    form = QuickCreateForm(request)
    filters = get_filter_dict(request)
    link_data = await retrieve_links(request,
                                     {'is_active': filters['is_active']})
    filtered_data = filter_links(link_data, filters)
    return html(template_loader(template_file='all_links.html',
                                form=form,
                                domain_name=config('DOMAIN_NAME'),
                                data=filtered_data),
                status=200)
Exemplo n.º 15
0
async def activate_link_view(request, user, link_id):
    try:
        await activate_link(request, link_id)
        status, message = 200, 'Link activated successfully'
    except NotFoundException:
        status, message = 404, 'Link does not exist'
    except DuplicateActiveLinkForbidden:
        status, message = 400, 'An active link with that name already exists'
    finally:
        return html(template_loader(template_file='message.html',
                                    payload=message,
                                    status_code=str(status)),
                    status=status)
Exemplo n.º 16
0
async def link_password_save(request, link_id):
    try:
        form = PasswordForm(request)
        link = await check_password(request, link_id, form)
        return redirect(link, status=307)
    except FormInvalidException:
        status, message = 400, 'Form invalid'
    except NotFoundException:
        status, message = 404, 'Link has no password or does not exist'
    except AccessDeniedException:
        status, message = 401, 'Password incorrect'

    return html(template_loader(
                    template_file='message.html',
                    payload=message,
                    status_code=str(status)
                ), status=status)
Exemplo n.º 17
0
async def update_link_save(request, user, link_id):
    try:
        form = UpdateForm(request)
        if not form.validate():
            raise FormInvalidException

        form_data = {
            'password': form.password.data,
            'url': form.url.data,
            'switch_date': form.switch_date.data
        }
        await update_link(request, link_id=link_id, data=form_data)
        status, message = 200, 'Link updated successfully'
    except FormInvalidException:
        status, message = 400, 'Form invalid'
    except NotFoundException:
        status, message = 404, 'Link does not exist'
    finally:
        return html(template_loader(
                        template_file='message.html',
                        payload=message,
                        status_code=str(status)
                    ), status=status)
Exemplo n.º 18
0
async def update_link_save(request, user, link_id):
    try:
        form = UpdateForm(request)
        if not form.validate():
            raise FormInvalidException

        form_data = {
            'password': form.password.data,
            'endpoint': form.endpoint.data,
            'url': form.url.data,
            'switch_date': form.switch_date.data
        }
        await update_link(request, link_id=link_id, data=form_data)
        message = 'updated'  # status = 200
    except FormInvalidException:
        message = 'form-invalid'  # status = 400
    except LinkNotAllowed:
        message = 'not-allowed'  # status = 400
    except NotFoundException:
        return html(template_loader('message.html'), status=404)
    except DuplicateActiveLinkForbidden:
        message = 'duplicate'  # status = 409

    return redirect(f'/links/all?origin=edit&status={message}')
Exemplo n.º 19
0
async def create_link_form(request, user):
    form = CreateForm(request)
    return html(template_loader(
                    template_file='create_form.html',
                    form=form
                ), status=200)
Exemplo n.º 20
0
async def about_page(request):
    return html(template_loader(template_file='about.html'), status=200)
Exemplo n.º 21
0
async def all_active_links(request, user):
    link_data = await retrieve_links(request, filters={'is_active': True})
    return html(template_loader(template_file='all_links.html',
                                domain_name=config('DOMAIN_NAME'),
                                data=link_data),
                status=200)
Exemplo n.º 22
0
async def owner_specific_links(request, user):
    link_data = await retrieve_links(request, filters={'owner_id': user.id})
    return html(template_loader(template_file='my_links.html',
                                domain_name=config('DOMAIN_NAME'),
                                link_data=link_data),
                status=200)
Exemplo n.º 23
0
async def delete_link_view(request, user, link_id):
    try:
        await delete_link(request, link_id)
        return redirect('/links/all?origin=delete&status=deleted')
    except NotFoundException:
        return html(template_loader('message.html'), status=404)