Waldo

Models

Waldo provides abstract MultiViews to handle several levels of common authentication:

class philo.contrib.waldo.models.LoginMultiView(*args, **kwargs)

Handles exclusively methods and views related to logging users in and out.

login_page

A ForeignKey to the Page which will be used to render the login form.

login_form

A django form class which will be used for the authentication process. Default: WaldoAuthenticationForm.

set_requirement_redirect(request, redirect=None)

Figures out and stores where a user should end up after landing on a page (like the login page) because they have not fulfilled some kind of requirement.

get_requirement_redirect(request, default=None)

Returns the location which a user should be redirected to after fulfilling a requirement (like logging in).

login(request, *args, **kwargs)

Renders the login_page with an instance of the login_form for the given HttpRequest.

logout(request, *args, **kwargs)

Logs the given HttpRequest out, redirecting the user to the page they just left or to the get_absolute_url() for the request.node.

login_required(view)

Wraps a view function to require that the user be logged in.

class philo.contrib.waldo.models.PasswordMultiView(*args, **kwargs)

Adds support for password setting, resetting, and changing to the LoginMultiView. Password reset support includes handling of a confirmation email.

password_reset_page

A ForeignKey to the Page which will be used to render the password reset request form.

password_reset_confirmation_email

A ForeignKey to the Page which will be used to render the password reset confirmation email.

password_set_page

A ForeignKey to the Page which will be used to render the password setting form (i.e. the page that users will see after confirming a password reset).

password_change_page

A ForeignKey to the Page which will be used to render the password change form.

password_change_form

The password change form class. Default: django.contrib.auth.forms.PasswordChangeForm.

password_set_form

The password set form class. Default: django.contrib.auth.forms.SetPasswordForm.

password_reset_form

The password reset request form class. Default: django.contrib.auth.forms.PasswordResetForm.

Generates a confirmation link for an arbitrary action, such as a password reset.

Parameters:
  • confirmation_view – The view function which needs to be linked to.
  • token_generator – Generates a confirmable token for the action.
  • user – The user who is trying to take the action.
  • node – The node which is providing the basis for the confirmation URL.
  • token_args – A list of additional arguments (i.e. besides the user) to be used for token creation.
  • reverse_kwargs – A dictionary of any additional keyword arguments necessary for correctly reversing the view.
  • secure – Whether the link should use the https:// or http://.
send_confirmation_email(subject, email, page, extra_context)

Sends a confirmation email for an arbitrary action, such as a password reset. If the page‘s Template has a mimetype of text/html, then the email will be sent with an HTML alternative version.

Parameters:
  • subject – The subject line of the email.
  • email – The recipient’s address.
  • page – The page which will be used to render the email body.
  • extra_context – The context for rendering the page.
password_reset(request, extra_context=None, token_generator=<django.contrib.auth.tokens.PasswordResetTokenGenerator object at 0x2709350>)

Handles the process by which users request a password reset, and generates the context for the confirmation email. That context will contain:

link
The confirmation link for the password reset.
user
The user requesting the reset.
site
The current Site.
request
The current HttpRequest instance.
Parameters:token_generator – The token generator to use for the confirmation link.
password_reset_confirm(request, extra_context=None, uidb36=None, token=None, token_generator=<django.contrib.auth.tokens.PasswordResetTokenGenerator object at 0x2709350>)

Checks that token` is valid, and if so, renders an instance of password_set_form with password_set_page.

Parameters:token_generator – The token generator used to check the token.
password_change(request, extra_context=None)

Renders an instance of password_change_form with password_change_page.

class philo.contrib.waldo.models.RegistrationMultiView(*args, **kwargs)

Adds support for user registration to the PasswordMultiView.

register_page

A ForeignKey to the Page which will be used to display the registration form.

register_confirmation_email

A ForeignKey to the Page which will be used to render the registration confirmation email.

registration_form

The registration form class. Default: RegistrationForm.

register(request, extra_context=None, token_generator=<philo.contrib.waldo.tokens.RegistrationTokenGenerator object at 0x333d350>)

Renders the register_page with an instance of registration_form in the context as form. If the form has been submitted, sends a confirmation email using register_confirmation_email and the same context as PasswordMultiView.password_reset().

Parameters:token_generator – The token generator to use for the confirmation link.
register_confirm(request, extra_context=None, uidb36=None, token=None, token_generator=<philo.contrib.waldo.tokens.RegistrationTokenGenerator object at 0x333d350>)

Checks that token is valid, and if so, logs the user in and redirects them to post_register_confirm_redirect().

Parameters:token_generator – The token generator used to check the token.
post_register_confirm_redirect(request)

Returns an HttpResponseRedirect for post-registration-confirmation. Default: Node.get_absolute_url() for request.node.

class philo.contrib.waldo.models.AccountMultiView(*args, **kwargs)

Adds support for user accounts on top of the RegistrationMultiView. By default, the account consists of the first_name, last_name, and email fields of the User model. Using a different account model is as simple as replacing account_form with any form class that takes an auth.User instance as the first argument.

manage_account_page

A ForeignKey to the Page which will be used to render the account management form.

email_change_confirmation_email

A ForeignKey to a Page which will be used to render an email change confirmation email. This is optional; if it is left blank, then email changes will be performed without confirmation.

account_form

A django form class which will be used to manage the user’s account. Default: UserAccountForm

account_view(request, extra_context=None, token_generator=<philo.contrib.waldo.tokens.EmailTokenGenerator object at 0x333d310>, *args, **kwargs)

Renders the manage_account_page with an instance of account_form in the context as form. If the form has been posted, the user’s email was changed, and email_change_confirmation_email is not None, sends a confirmation email to the new email to make sure it exists before making the change. The email will have the same context as PasswordMultiView.password_reset().

Parameters:token_generator – The token generator to use for the confirmation link.
has_valid_account(user)

Returns True if the user has a valid account and False otherwise.

account_required(view)

Wraps a view function to allow access only to users with valid accounts and otherwise redirect them to the account_view().

post_register_confirm_redirect(request)

Automatically redirects users to the account_view() after registration.

email_change_confirm(request, extra_context=None, uidb36=None, token=None, email=None, token_generator=<philo.contrib.waldo.tokens.EmailTokenGenerator object at 0x333d310>)

Checks that token is valid, and if so, changes the user’s email.

Parameters:token_generator – The token generator used to check the token.

Forms

class philo.contrib.waldo.forms.EmailInput(attrs=None)

Displays an HTML5 email input on browsers which support it and a normal text input on other browsers.

class philo.contrib.waldo.forms.RegistrationForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)

Handles user registration. If recaptcha_django is installed on the system and recaptcha_django.middleware.ReCaptchaMiddleware is in settings.MIDDLEWARE_CLASSES, then a recaptcha field will automatically be added to the registration form.

See also

recaptcha-django

email

An EmailField using the EmailInput widget.

class philo.contrib.waldo.forms.UserAccountForm(user, *args, **kwargs)

Handles a user’s account - by default, auth.User.first_name, auth.User.last_name, auth.User.email.

email_changed()

Returns True if the email field changed value and False if it did not, or if there is no email field on the form. This method must be supplied by account forms used with waldo.

reset_email()

ModelForms modify their instances in-place during _post_clean(); this method resets the email value to its initial state and returns the altered value. This is a method on the form to allow unusual behavior such as storing email on a UserProfile.

classmethod set_email(user, email)

Given a valid instance and an email address, correctly set the email address for that instance and save the changes. This is a class method in order to allow unusual behavior such as storing email on a UserProfile.

class philo.contrib.waldo.forms.WaldoAuthenticationForm(request=None, *args, **kwargs)

Handles user authentication. Checks that the user has not mistakenly entered their email address (like django.contrib.admin.forms.AdminAuthenticationForm) but does not require that the user be staff.

Token generators

Based on django.contrib.auth.tokens. Supports the following settings:

WALDO_REGISTRATION_TIMEOUT_DAYS
The number of days a registration link will be valid before expiring. Default: 1.
WALDO_EMAIL_TIMEOUT_DAYS
The number of days an email change link will be valid before expiring. Default: 1.
philo.contrib.waldo.tokens.registration_token_generator

Strategy object used to generate and check tokens for the user registration mechanism.

philo.contrib.waldo.tokens.email_token_generator

Strategy object used to generate and check tokens for a user email change mechanism.

Project Versions

Table Of Contents

Previous topic

Sobol

Next topic

Winer

This Page