-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
234 additions
and
136 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.backends import ModelBackend | ||
from django.db.models import Q | ||
|
||
|
||
class EmailOrUsernameModelBackend(ModelBackend): | ||
""" | ||
Authentication backend which allows users to authenticate using either their | ||
username or email address | ||
Source: https://stackoverflow.com/a/35836674/59984 | ||
""" | ||
|
||
def authenticate(self, request, username=None, password=None, **kwargs): | ||
# n.b. Django <2.1 does not pass the `request` | ||
|
||
user_model = get_user_model() | ||
|
||
if username is None: | ||
username = kwargs.get(user_model.USERNAME_FIELD) | ||
|
||
# The `username` field is allows to contain `@` characters so | ||
# technically a given email address could be present in either field, | ||
# possibly even for different users, so we'll query for all matching | ||
# records and test each one. | ||
users = user_model._default_manager.filter( | ||
Q(**{user_model.USERNAME_FIELD: username}) | Q(email__iexact=username) | ||
) | ||
|
||
# Test whether any matched user has the provided password: | ||
for user in users: | ||
if user.check_password(password): | ||
return user | ||
if not users: | ||
# Run the default password hasher once to reduce the timing | ||
# difference between an existing and a non-existing user (see | ||
# https://code.djangoproject.com/ticket/20760) | ||
user_model().set_password(password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class IsOwnerOrReadOnly(permissions.BasePermission): | ||
""" | ||
Custom permission to only allow owners of an object to edit it. | ||
""" | ||
|
||
def has_object_permission(self, request, view, obj): | ||
# Read permissions are allowed to any request, | ||
# so we'll always allow GET, HEAD or OPTIONS requests. | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
|
||
# Write permissions are only allowed to the owner of the snippet. | ||
return obj.user_id == request.user.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
mymusix/scripts/__pycache__/add_festival_artists.cpython-38.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters