Skip to content

Commit

Permalink
patch to force kyc on login
Browse files Browse the repository at this point in the history
  • Loading branch information
joequant committed Apr 30, 2023
1 parent ae02e7a commit 98c7b1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/serializers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from allauth.account.utils import setup_user_email
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.core.cache import cache
from django.db.models import Model
from django.db.transaction import atomic
Expand Down Expand Up @@ -38,6 +39,7 @@
from core.tasks.facade import notify_user_ip_changed
from core.utils.auth import RegisterUserCheck
from exchange.loggers import DynamicFieldFilter
from exchange.settings.kyc import IS_KYC_REQUIRED
from lib.serializers import LANG_FIELD
from lib.utils import generate_random_string

Expand Down Expand Up @@ -272,6 +274,8 @@ def validate(self, attrs):
'token': current_token
})

self.validate_kyc(user)

attrs['user'] = user
captcher.set_captcha_passed()

Expand Down Expand Up @@ -320,6 +324,18 @@ def validate(self, attrs):

return attrs

def validate_kyc(self, user: User) -> None:
if not exchange.settings.kyc.IS_KYC_REQUIRED:
return
if not UserKYC.valid_for_user(user):
msg = _('Unable to log in due to KYC restrictions.')
raise ValidationError(
{
'message': msg,
'type': 'kyc'
}
)


class RegisterSerializer(BaseRegisterSerializer):
first_name = serializers.CharField(required=True)
Expand Down Expand Up @@ -499,4 +515,4 @@ def get_kyc_enabled(self, obj):
return settings.IS_KYC_ENABLED

def get_sms_enabled(self, obj):
return settings.IS_SMS_ENABLED
return settings.IS_SMS_ENABLED
1 change: 1 addition & 0 deletions exchange/settings/kyc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from exchange.settings import env

IS_KYC_ENABLED = env('IS_KYC_ENABLED', default=False)
IS_KYC_REQUIRED = env('IS_KYC_REQUIRED', default=False)
SUMSUB_SECRET_KEY = env('SUMSUB_SECRET_KEY')
SUMSUB_APP_TOKEN = env('SUMSUB_APP_TOKEN')
SUMSUM_CALLBACK_VALIDATION_SECRET = env('SUMSUM_CALLBACK_VALIDATION_SECRET')
Expand Down

0 comments on commit 98c7b1c

Please sign in to comment.