diff --git a/core/serializers/auth.py b/core/serializers/auth.py index 8e31f2e..822e321 100644 --- a/core/serializers/auth.py +++ b/core/serializers/auth.py @@ -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 @@ -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 @@ -272,6 +274,8 @@ def validate(self, attrs): 'token': current_token }) + self.validate_kyc(user) + attrs['user'] = user captcher.set_captcha_passed() @@ -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) @@ -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 \ No newline at end of file + return settings.IS_SMS_ENABLED diff --git a/exchange/settings/kyc.py b/exchange/settings/kyc.py index e16e560..a8f1bb2 100644 --- a/exchange/settings/kyc.py +++ b/exchange/settings/kyc.py @@ -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')