mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 00:49:16 +02:00
Blacked the code
This commit is contained in:
parent
b6fc0051fa
commit
62ca3bd736
279 changed files with 8861 additions and 9527 deletions
|
@ -10,23 +10,20 @@ from funkwhale_api.users.models import User
|
|||
def get_token(salt, password):
|
||||
to_hash = password + salt
|
||||
h = hashlib.md5()
|
||||
h.update(to_hash.encode('utf-8'))
|
||||
h.update(to_hash.encode("utf-8"))
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def authenticate(username, password):
|
||||
try:
|
||||
if password.startswith('enc:'):
|
||||
password = password.replace('enc:', '', 1)
|
||||
password = binascii.unhexlify(password).decode('utf-8')
|
||||
if password.startswith("enc:"):
|
||||
password = password.replace("enc:", "", 1)
|
||||
password = binascii.unhexlify(password).decode("utf-8")
|
||||
user = User.objects.get(
|
||||
username=username,
|
||||
is_active=True,
|
||||
subsonic_api_token=password)
|
||||
except (User.DoesNotExist, binascii.Error):
|
||||
raise exceptions.AuthenticationFailed(
|
||||
'Wrong username or password.'
|
||||
username=username, is_active=True, subsonic_api_token=password
|
||||
)
|
||||
except (User.DoesNotExist, binascii.Error):
|
||||
raise exceptions.AuthenticationFailed("Wrong username or password.")
|
||||
|
||||
return (user, None)
|
||||
|
||||
|
@ -34,18 +31,13 @@ def authenticate(username, password):
|
|||
def authenticate_salt(username, salt, token):
|
||||
try:
|
||||
user = User.objects.get(
|
||||
username=username,
|
||||
is_active=True,
|
||||
subsonic_api_token__isnull=False)
|
||||
except User.DoesNotExist:
|
||||
raise exceptions.AuthenticationFailed(
|
||||
'Wrong username or password.'
|
||||
username=username, is_active=True, subsonic_api_token__isnull=False
|
||||
)
|
||||
except User.DoesNotExist:
|
||||
raise exceptions.AuthenticationFailed("Wrong username or password.")
|
||||
expected = get_token(salt, user.subsonic_api_token)
|
||||
if expected != token:
|
||||
raise exceptions.AuthenticationFailed(
|
||||
'Wrong username or password.'
|
||||
)
|
||||
raise exceptions.AuthenticationFailed("Wrong username or password.")
|
||||
|
||||
return (user, None)
|
||||
|
||||
|
@ -53,15 +45,15 @@ def authenticate_salt(username, salt, token):
|
|||
class SubsonicAuthentication(authentication.BaseAuthentication):
|
||||
def authenticate(self, request):
|
||||
data = request.GET or request.POST
|
||||
username = data.get('u')
|
||||
username = data.get("u")
|
||||
if not username:
|
||||
return None
|
||||
|
||||
p = data.get('p')
|
||||
s = data.get('s')
|
||||
t = data.get('t')
|
||||
p = data.get("p")
|
||||
s = data.get("s")
|
||||
t = data.get("t")
|
||||
if not p and (not s or not t):
|
||||
raise exceptions.AuthenticationFailed('Missing credentials')
|
||||
raise exceptions.AuthenticationFailed("Missing credentials")
|
||||
|
||||
if p:
|
||||
return authenticate(username, p)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue