A Django app that allows visitors to interact with your site as a guest user without requiring registration.

Overview

django-guest-user

A Django app that allows visitors to interact with your site as a guest user without requiring registration.

Largely inspired by django-lazysignup and rewritten for Django 3 and Python 3.6 and up.

Installation

Install the package with your favorite package manager from PyPI:

pip install django-guest-user

Add the app to your INSTALLED_APPS and AUTHENTICATION_BACKENDS:

INSTALLED_APPS = [
    ...
    "django_guest_user",
]

AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
    "guest_user.backends.GuestBackend",
]

Add the patterns to your URL config:

urlpatterns = [
    ...
    path("convert/", include("guest_user.urls")),
]

Don't forget to run migrations:

python manage.py migrate

How to use

Guest users are not created for every unauthenticated request. Instead, use the @allow_guest_user decorator on a view to enable that view to be accessed by a temporary guest user.

from guest_user.decorators import allow_guest_user

@allow_guest_user
def my_view(request):
    # Will always be either a registered a guest user.
    username = request.user.username
    return HttpResponse(f"Hello, {username}!")

API

@guest_user.decorators.allow_guest_user

View decorator that will create a temporary guest user in the event that the decorated view is accessed by an unauthenticated visitor.

Takes no arguments.

@guest_user.decorators.guest_user_required(redirect_field_name="next", login_url=None)

View decorator that redirects to a given URL if the accessing user is anonymous or already authenticated.

Arguments:

  • redirect_field_name: URL query parameter to use to link back in the case of a redirect to the login url. Defaults to django.contrib.auth.REDIRECT_FIELD_NAME ("next").
  • login_url: URL to redirect to if the user is not authenticated. Defaults to the LOGIN_URL setting.

@guest_user.decorators.regular_user_required(redirect_field_name="next", login_url=None)

Decorator that will not allow guest users to access the view. Will redirect to the conversion page to allow a guest user to fully register.

Arguments:

  • redirect_field_name: URL query parameter to use to link back in the case of a redirect to the login url. Defaults to django.contrib.auth.REDIRECT_FIELD_NAME ("next").
  • login_url: URL to redirect to if the user is a guest. Defaults to "guest_user_convert".

guest_user.functions.get_guest_model()

The guest user model is swappable. This function will return the currently configured model class.

guest_user.functions.is_guest_user(user)

Check wether the given user instance is a temporary guest.

guest_user.signals.converted

Signal that is dispatched when a guest user is converted to a regular user.

Template tag is_guest_user

A filter to use in templates to check if the user object is a guest.

{% load guest_user %}

{% if user|is_guest_user %}
  Hello guest.
{% endif %}

Settings

Various settings are provided to allow customization of the guest user behavior.

GUEST_USER_ENABLED

bool. If False, the @allow_guest_user decorator will not create guest users. Defaults to True.

GUEST_USER_MODEL

str. The swappable model identifier to use as the guest model. Defaults to "guest_user.Guest".

GUEST_USER_NAME_GENERATOR

str. Import path to a function that will generate a username for a guest user. Defaults to "guest_user.functions.generate_uuid_username".

Included with the package are two alternatives:

"guest_user.functions.generate_numbered_username": Will create a random four digit number prefixed by GUEST_USER_NAME_PREFIX.

"guest_user.functions.generate_friendly_username": Creates a friendly and easy to remember username by combining an adjective, noun and number. Requires random_username to be installed.

GUEST_USER_NAME_PREFIX

str. A prefix to use with the generate_numbered_username generator. Defaults to "Guest".

GUEST_USER_CONVERT_FORM

str. Import path for the guest conversion form. Must implement get_credentials to be passed to Django's authenticate function. Defaults to "guest_user.forms.UserCreationForm".

GUEST_USER_CONVERT_PREFILL_USERNAME

bool. Set the generated username as initial value on the conversion form. Defaults to False.

GUEST_USER_CONVERT_URL

str. URL name for the convert view. Defaults to "guest_user_convert".

GUEST_USER_CONVERT_REDIRECT_URL

str. URL name to redirect to after conversion, unless a redirect parameter was provided. Defaults to "guest_user_convert_success".

GUEST_USER_BLOCKED_USER_AGENTS

list[str]. Web crawlers and other user agents to block from becoming guest users. The list will be combined into a regular expression. Default includes a number of well known bots and spiders.

Status

This project is currently untested. But thanks to previous work it is largely functional.

I decided to rewrite the project since the original project hasn't seen any larger updates for a few years now and the code base was written a long time ago.

You might also like...
 An insecure login and registration website with Django.
An insecure login and registration website with Django.

An insecure login and registration website with Django.

Vehicle registration using Python, Django and SQlite3

PythonCrud Cadastro de veículos utilizando Python, Django e SQlite3 Para acessar o deploy no Heroku:

A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.
A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.

Django Sage Painless The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web

Django API without Django REST framework.

Django API without DRF This is a API project made with Django, and without Django REST framework. This project was done with: Python 3.9.8 Django 3.2.

django-idom allows Django to integrate with IDOM

django-idom allows Django to integrate with IDOM, a package inspired by ReactJS for creating responsive web interfaces in pure Python.

Displaying objects on maps in the Django views and administration site.
Displaying objects on maps in the Django views and administration site.

DjangoAdminGeomap library The free, open-source DjangoAdminGeomap library is designed to display objects on the map in the Django views and admin site

Use webpack to generate your static bundles without django's staticfiles or opaque wrappers.

django-webpack-loader Use webpack to generate your static bundles without django's staticfiles or opaque wrappers. Django webpack loader consumes the

A Django web application that allows you to be in the loop about everything happening in your neighborhood.
A Django web application that allows you to be in the loop about everything happening in your neighborhood.

A Django web application that allows you to be in the loop about everything happening in your neighborhood. From contact information of different handyman to meeting announcements or even alerts.

Django project starter on steroids: quickly create a Django app AND generate source code for data models + REST/GraphQL APIs (the generated code is auto-linted and has 100% test coverage).

Create Django App 💛 We're a Django project starter on steroids! One-line command to create a Django app with all the dependencies auto-installed AND

Comments
  • Add django-tos contrib app

    Add django-tos contrib app

    This PR adds an integration with django-tos.

    It is necessary when using django-tos's middleware option (2). When using django-tos' middleware, since guest users have full user accounts they are required to agree to the site's terms of service before they can do anything else.

    I have refactored django-tos a bit in revsys/django-tos#65 specifically to make this custom middleware easier to write. That PR allows us to minimize the amount of code necessary in this middleware and any changes to upstream django-tos should not interfere with this middleware.

    opened by blag 3
  • RFC on a changing GuestManager.convert to update in-place

    RFC on a changing GuestManager.convert to update in-place

    Hi @julianwachholz,

    First off, thank you very much for maintaining this package for new versions of Django!

    I've opened this ticket to propose a relatively simple change (or addition) of the GuestManager in the package that I think would enable greater functionality for devs wanting to create guest users.

    Background

    Business Use Case

    I started using this package to enable guest users functionality on a site, with the goal that:

    • ephemeral guest users would be able to modify the db (ie CRUD their own objects like a regular user)
    • after conversion all of the state in related models would be maintained

    After reading the documentation for django-guest-user I didn't see any flags that stated this usage wasn't possible, but after installing the package and trying to use it, to the best of my understanding, the use case above is not supported. I think this has also been raised previously in https://github.com/julianwachholz/django-guest-user/issues/3.

    EDIT:

    • This use case is supported; I had a misconfigured form and had misread the guest creation workflow when debugging.

    Thanks very much for your time!

    opened by mbhynes 3
  • How to log in instead of registering a new user?

    How to log in instead of registering a new user?

    Hi @julianwachholz,

    Thanks a lot for working on this package, it's very useful!

    I had a question I hoped you could help me answer: Is there a way to allow the user to log in, instead of creating a new user during the conversion? So that if a user hadn't logged in before putting items in the cart, he can still keep them

    Thank you.

    Best, Dylan

    opened by dylanjcastillo 2
  • Django 4.0

    Django 4.0

    This PR:

    • removes one last feature that was deprecated in Django 4.0 (which silences a warning from this package when running tests)
    • adds Django 4.0 to the test matrix
    • removes Django 3.1 from the test matrix (since this is EOL in just a few days)
    • adds Python 3.10 to the test matrix
    opened by blag 1
Releases(0.5.3)
Owner
Julian Wachholz
Python and JavaScript developer. I enjoy riding motorcycles and playing board games. PGP: https://julianwachholz.dev/julian_wachholz_pub.asc
Julian Wachholz
Utility for working with recurring dates in Django.

django-recurrence django-recurrence is a utility for working with recurring dates in Django. Documentation is available at https://django-recurrence.r

408 Jan 06, 2023
A CTF leaderboard for the submission of flags during a CTF challenge. Built using Django.

🚩 CTF Leaderboard The goal of this project is to provide a simple web page to allow the participants of an CTF to enter their found flags. Also the l

Maurice Bauer 2 Jan 17, 2022
Website desenvolvido em Django para gerenciamento e upload de arquivos (.pdf).

Website para Gerenciamento de Arquivos Features Esta é uma aplicação full stack web construída para desenvolver habilidades com o framework Django. O

Alinne Grazielle 8 Sep 22, 2022
Django Starter is a simple Skeleton to start with a Django project.

Django Starter Template Description Django Starter is a simple Skeleton to start

Numan Ibn Mazid 1 Jan 10, 2022
Bootstrap 3 integration with Django.

django-bootstrap3 Bootstrap 3 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 3. Want to use Bootstr

Zostera B.V. 2.3k Jan 02, 2023
Media-Management with Grappelli

Django FileBrowser Media-Management with Grappelli. The FileBrowser is an extension to the Django administration interface in order to: browse directo

Patrick Kranzlmueller 913 Dec 28, 2022
A calendaring app for Django. It is now stable, Please feel free to use it now. Active development has been taken over by bartekgorny.

Django-schedule A calendaring/scheduling application, featuring: one-time and recurring events calendar exceptions (occurrences changed or cancelled)

Tony Hauber 814 Dec 26, 2022
A tool to automatically fix Django deprecations.

A tool to help upgrade Django projects to newer version of the framework by automatically fixing deprecations. The problem When maintaining a Django s

Bruno Alla 155 Dec 14, 2022
https://django-storages.readthedocs.io/

Installation Installing from PyPI is as easy as doing: pip install django-storages If you'd prefer to install from source (maybe there is a bugfix in

Josh Schneier 2.3k Jan 06, 2023
Twitter-clone using Django (DRF) + VueJS

Twitter Clone work in progress 🚧 A Twitter clone project Table Of Contents About the Project Built With Getting Started Running project License Autho

Ahmad Alwi 8 Sep 08, 2022
A collection of models, views, middlewares, and forms to help secure a Django project.

Django-Security This package offers a number of models, views, middlewares and forms to facilitate security hardening of Django applications. Full doc

SD Elements 258 Jan 03, 2023
Create a netflix-like service using Django, React.js, & More.

Create a netflix-like service using Django. Learn advanced Django techniques to achieve amazing results like never before.

Coding For Entrepreneurs 67 Dec 08, 2022
This is a repository for a web application developed with Django, built with Crowdbotics

assignment_32558 This is a repository for a web application developed with Django, built with Crowdbotics Table of Contents Project Structure Features

Crowdbotics 1 Dec 29, 2021
Zendesk Assignment - Django Based Ticket Viewer

Zendesk-Coding-Challenge Django Based Ticket Viewer The assignment has been made using Django. Important methods have been scripted in views.py. Excep

Akash Sampurnanand Pandey 0 Dec 23, 2021
Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS)

django-cors-headers A Django App that adds Cross-Origin Resource Sharing (CORS) headers to responses. This allows in-browser requests to your Django a

Adam Johnson 4.8k Jan 03, 2023
RestApi With Django 3.2 And Django Rest Framework

RestApi-With-Django-3.2-And-Django-Rest-Framework Description This repository is a Software of Development with Python. Virtual Using pipenv, virtuale

Daniel Arturo Alejo Alvarez 6 Aug 02, 2022
DCM is a set of tools that helps you to keep your data in your Django Models consistent.

Django Consistency Model DCM is a set of tools that helps you to keep your data in your Django Models consistent. Motivation You have a lot of legacy

Occipital 59 Dec 21, 2022
A simple REST API to manage postal addresses, written in Python/Django.

A simple REST API to manage postal addresses, written in Python/Django.

Attila Bagossy 2 Feb 14, 2022
A Django based shop system

django-SHOP Django-SHOP aims to be a the easy, fun and fast e-commerce counterpart to django-CMS. Here you can find the full documentation for django-

Awesto 2.9k Dec 30, 2022
A django integration for huey task queue that supports multi queue management

django-huey This package is an extension of huey contrib djhuey package that allows users to manage multiple queues. Installation Using pip package ma

GAIA Software 32 Nov 26, 2022