Jump to >

reviewboard.accounts.backends.base

Base class for authentication backends.

class BaseAuthBackend[source]

Bases: object

Base class for a Review Board authentication backend.

backend_id = None[source]

The unique ID for the authentication backend.

name = None[source]

The display name for the authentication backend.

This will be shown in the list of backends in the administration UI.

settings_form = None[source]

The form class used for authentication settings.

This must be a subclass of SiteSettingsForm.

supports_registration = False[source]

Whether this backend supports registering new users.

supports_change_name = False[source]

Whether this backend supports changing the user’s full name.

supports_change_email = False[source]

Whether this backend supports changing the user’s e-mail address.

supports_change_password = False[source]

Whether this backend supports changing the user’s password.

login_instructions = None[source]

Authentication instructions to display above the Login form.

INVALID_USERNAME_CHAR_REGEX = <_sre.SRE_Pattern object>[source]

A regex for matching invalid characters in usernames.

authenticate(**credentials)[source]

Authenticate a user.

This will authenticate a user identified by the provided credentials. object, or None.

This must be implemented by subclasses.

Parameters:**credentials (dict) – The credentials passed to the backend. This will often contain username and password keys.
Returns:The authenticated user, or None if the user could not be authenticated for any reason.
Return type:django.contrib.auth.models.User
get_or_create_user(username, request=None)[source]

Return an existing user or create one if it doesn’t exist.

This does not authenticate the user.

If the user does not exist in the database, but does in the backend, its information will be stored in the database for later lookup. Subclasses can impose restrictions on this.

This must be implemented by subclasses.

Parameters:
  • username (unicode) – The username to fetch or create.
  • request (django.http.HttpRequest, optional) – The HTTP request from the client.
Returns:

The resulting user, or None if one could not be found.

Return type:

django.contrib.auth.models.User

get_user(user_id)[source]

Return an existing user given a numeric user ID.

Parameters:user_id (int) – The ID of the user to retrieve.
Returns:The resulting user, or None if one could not be found.
Return type:django.contrib.auth.models.User
update_password(user, password)[source]

Update a user’s password on the backend.

Authentication backends can override this to update the password on the backend. By default, this is not supported.

Callers should only call this after checking whether supports_change_password is True.

Parameters:
Raises:

NotImplementedError – The backend does not support changing passwords.

update_name(user)[source]

Update a user’s full name on the backend.

Authentication backends can override this to update the name on the backend based on the first_name and last_name values in user. By default, this will do nothing.

Callers should only call this after checking whether supports_change_name is True.

Parameters:user (django.contrib.auth.models.User) – The user whose full name will be changed.
update_email(user)[source]

Update a user’s e-mail address on the backend.

Authentication backends can override this to update the e-mail address on the backend based on the email value in user. NBy default, this will do nothing.

Callers should only call this after checking whether supports_change_email is True.

Parameters:user (django.contrib.auth.models.User) – The user whose full name will be changed.
populate_users(query, request, **kwargs)[source]

Populate users from the backend into the database based on a query.

Authentication backends can override this to add users stored on the backend into the local database, based on a query string representing a full or partial first name, last name, or username. Each result that’s found based on the query should be stored in the database by the backend, generally using the same creation logic as in get_or_create_user().

Callers should use this when they need to look up all available users from a backend. After calling this, they should look up the results from the database.

If a legacy query_users() method exists on the class, then this will default to calling that with the same parameters (as this was the older name for this method). Otherwise, by default, this will do nothing.

Parameters:
  • query (unicode) – A search query for matching users. This will match the entirety or prefix of a username. It’s expected that the match will be case-insensitive.
  • request (django.http.HttpRequest) – The HTTP request from the client.
  • **kwargs (dict) – Extra positional arguments, for future use.
Raises:

reviewboard.accounts.errors.UserQueryError – There was an error processing the query or looking up users. Details will be in the error message.

build_search_users_query(query, request, **kwargs)[source]

Build a query for searching users in the database.

This allows backends to construct specialized search queries ( for use in QuerySet.filter() when searching for users via the User List Resource.

If a legacy search_users() method exists on the class, then this will default to calling that with the same parameters (as this was the older name for this method). Otherwise, by default, this will return None.

Parameters:
  • query (unicode) – A search query for matching users. This will match the entirety or prefix of a username. It’s expected that the match will be case-insensitive.
  • request (django.http.HttpRequest) – The HTTP request from the client.
  • **kwargs (dict) – Extra positional arguments, for future use.
Returns:

The resulting query for the queryset, or None to use the query for the next available backend (eventually defaulting to the standard search query).

Return type:

django.db.models.Q