mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 00:39:16 +02:00
Fix #1039: setting to enforce email signup verification
This commit is contained in:
parent
67857d931c
commit
93f2c9f83c
16 changed files with 365 additions and 30 deletions
|
@ -3,6 +3,7 @@ import hashlib
|
|||
|
||||
from rest_framework import authentication, exceptions
|
||||
|
||||
from funkwhale_api.common import authentication as common_authentication
|
||||
from funkwhale_api.users.models import User
|
||||
|
||||
|
||||
|
@ -18,19 +19,26 @@ def authenticate(username, password):
|
|||
if password.startswith("enc:"):
|
||||
password = password.replace("enc:", "", 1)
|
||||
password = binascii.unhexlify(password).decode("utf-8")
|
||||
user = User.objects.select_related("actor").get(
|
||||
username__iexact=username, is_active=True, subsonic_api_token=password
|
||||
user = (
|
||||
User.objects.all()
|
||||
.for_auth()
|
||||
.get(username__iexact=username, is_active=True, subsonic_api_token=password)
|
||||
)
|
||||
except (User.DoesNotExist, binascii.Error):
|
||||
raise exceptions.AuthenticationFailed("Wrong username or password.")
|
||||
|
||||
if common_authentication.should_verify_email(user):
|
||||
raise exceptions.AuthenticationFailed("You need to verify your email.")
|
||||
|
||||
return (user, None)
|
||||
|
||||
|
||||
def authenticate_salt(username, salt, token):
|
||||
try:
|
||||
user = User.objects.select_related("actor").get(
|
||||
username=username, is_active=True, subsonic_api_token__isnull=False
|
||||
user = (
|
||||
User.objects.all()
|
||||
.for_auth()
|
||||
.get(username=username, is_active=True, subsonic_api_token__isnull=False)
|
||||
)
|
||||
except User.DoesNotExist:
|
||||
raise exceptions.AuthenticationFailed("Wrong username or password.")
|
||||
|
@ -38,6 +46,9 @@ def authenticate_salt(username, salt, token):
|
|||
if expected != token:
|
||||
raise exceptions.AuthenticationFailed("Wrong username or password.")
|
||||
|
||||
if common_authentication.should_verify_email(user):
|
||||
raise exceptions.AuthenticationFailed("You need to verify your email.")
|
||||
|
||||
return (user, None)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue