Allow anonymous users to access the view by creating a guest user.
Usage example:
from guest_user.decorators import allow_guest_user @allow_guest_user def hello_world(request): return HttpResponse(f"Hello {request.user.username}!")
Current user must be a temporary guest.
Since being a guest user is not a state that a registered user can ever revert back to, there is no “next” URL handling in this decorator.
anonymous_url – Redirect target for anonymous users. Defaults to GUEST_USER_REQUIRED_ANON_URL
.
registered_url – Redirect target for registered users. Defaults to GUEST_USER_REQUIRED_USER_URL
.
Usage example:
from guest_user.decorators import guest_user_required @guest_user_required(anonymous_url="/login/", registered_url="/dashboard/") def only_for_guests(request): pass
Current user must not be a temporary guest.
The redirected URL will get a “next” parameter added to the URL in order to redirect the user back to the page they were trying to access.
login_url – Redirect target for anonymous users. Defaults to django:ref/settings:``login_url``.
convert_url – Redirect target for guest users. Defaults to GUEST_USER_CONVERT_URL
.
redirect_field_name – URL parameter used to redirect to the origin page. Defaults to django.contrib.auth.REDIRECT_FIELD_NAME
(= “next”).
Usage example:
from guest_user.decorators import regular_user_required @regular_user_required def permanent_users_only(request): # This view will redirect anonymous users to the login page # and guest users to the convert page, respectively. # A redirect URL parameter will be added to users can jump right back here. pass
Allow anonymous users to access the view by creating a guest user.
This mixin does not require overriding any attributes.
Example usage:
from guest_user.mixins import AllowGuestUserMixin class HelloWorldView(AllowGuestUserMixin, View): def get(self, request): return HttpResponse(f"Hello {request.user.username}!")
Current user must be a temporary guest.
Since being a guest user is not a state that a registered user can ever revert back to, there is no “next” URL handling in this mixin.
Example usage:
from guest_user.mixins import GuestUserRequiredMixin class OnlyGuestView(GuestUserRequiredMixin, View): anonymous_url = "/login/" registered_url = "/dashboard/"
Redirect target for anonymous users. Defaults to GUEST_USER_REQUIRED_ANON_URL
.
Redirect target for registered users. Defaults to GUEST_USER_REQUIRED_USER_URL
.
Current user must not be a temporary guest.
Anonymous users will be redirected to login_url. Guest users will be redirected to the convert_url.
The redirected URL will get a “next” parameter added to the URL in order to redirect the user back to the page they were trying to access.
Example usage:
from guest_user.mixins import RegularUserRequiredMixin class RealUsersOnlyView(RegularUserRequiredMixin, View): login_url = "/login/" convert_url = "/convert/?from=RealUsersOnlyView"
Redirect target for anonymous users. Defaults to django:ref/settings:``login_url``.
Redirect target for guest users. Defaults to GUEST_USER_CONVERT_URL
.
URL parameter used to redirect to the origin page. Defaults to django.contrib.auth.REDIRECT_FIELD_NAME
(= “next”).
The django-guest-user
template tags are registered in the guest_user
namespace.
To use them, load them in your template:
Template filter to check if the passed object is a guest user.
Usage
{% if user|is_guest_user %} Hello guest. {% endif %}
Several helper functions are provided for advanced usage.
Create a guest user and log them in.
This function will create and authenticate a new guest user should the visitor not be authenticated already and their user agent isn’t on the block list.
Return the configured Guest model.
Check if the given user instance is a temporary guest.
Generate a random username based on UUID.
Generate a random username based on a prefix and a random number.
Generate a random username with adjective and nouns put together.
Requires random-username to be installed.
A visitor accessed a view that created a guest user.
user – The new guest user.
request – The request that created the guest user.
A guest user converted to a regular registered user.
user – The now registered user.
A temporary guest user.
Users linked to a Guest instance are considered temporary guests and will be deleted by cleanup jobs after their expiration.
The age of a guest user is determined by the created_at
field.
This model is swappable with the GUEST_USER_MODEL
setting. Custom Guest models should use the GuestManager or a custom manager that implements the same custom methods.
Manager for Guest objects.
Create a guest user.
Returns the underlying User object.
request – The current request object.
username – The preferred username for the user, may be None.
Convert a guest user to a regular one.
The form passed in is expected to be a ModelForm instance, bound to the user to be converted.
TypeError if the user is not a temporary guest.
form – The model form used to create the permanent user.
The converted User
object.
Delete all expired guest users.
A modelform that creates a standard Django user.
Custom implementations must implement get_credentials()
.
Get the credentials required to log the user in after conversion.
The credentials are passed to Django’s authenticate()
.
Login credentials. This is usually a dict with “username” and “password”.
Return all media required to render the widgets on this form.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4