diff --git a/cvat-core/src/server-proxy.ts b/cvat-core/src/server-proxy.ts index fa866a16be63..28de4228f0de 100644 --- a/cvat-core/src/server-proxy.ts +++ b/cvat-core/src/server-proxy.ts @@ -341,10 +341,11 @@ async function login(username, email, password) { // Uncomment this for sending email in request // `${encodeURIComponent('email')}=${encodeURIComponent(email)}`, `${encodeURIComponent('username')}=${encodeURIComponent(username)}`, + `${encodeURIComponent('email')}=${encodeURIComponent(email)}`, `${encodeURIComponent('password')}=${encodeURIComponent(password)}`, ] - .join('&') - .replace(/%20/g, '+'); + .join('&') + .replace(/%20/g, '+'); removeToken(); let authenticationResponse = null; diff --git a/cvat-ui/src/components/signing-common/cvat-signing-input.tsx b/cvat-ui/src/components/signing-common/cvat-signing-input.tsx index 83453eceba75..64dbbb5ded39 100644 --- a/cvat-ui/src/components/signing-common/cvat-signing-input.tsx +++ b/cvat-ui/src/components/signing-common/cvat-signing-input.tsx @@ -20,6 +20,7 @@ interface SocialAccountLinkProps { export enum CVATInputType { TEXT = 'text', PASSWORD = 'passord', + EMAIL = 'email' } function CVATSigningInput(props: SocialAccountLinkProps): JSX.Element { diff --git a/cvat/apps/iam/serializers.py b/cvat/apps/iam/serializers.py index e6548ead876a..fd3ff5525101 100644 --- a/cvat/apps/iam/serializers.py +++ b/cvat/apps/iam/serializers.py @@ -9,6 +9,8 @@ from rest_framework import serializers from allauth.account import app_settings from allauth.account.utils import filter_users_by_email +from django.contrib.auth.models import User +import logging from django.conf import settings @@ -44,42 +46,12 @@ def get_email_options(self): class LoginSerializerEx(LoginSerializer): def get_auth_user_using_allauth(self, username, email, password): - - def is_email_authentication(): - return settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.EMAIL - - def is_username_authentication(): - return settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME - - # check that the server settings match the request - if is_username_authentication() and not username and email: - raise ValidationError( - 'Attempt to authenticate with email/password. ' - 'But username/password are used for authentication on the server. ' - 'Please check your server configuration ACCOUNT_AUTHENTICATION_METHOD.') - - if is_email_authentication() and not email and username: - raise ValidationError( - 'Attempt to authenticate with username/password. ' - 'But email/password are used for authentication on the server. ' - 'Please check your server configuration ACCOUNT_AUTHENTICATION_METHOD.') - - # Authentication through email - if settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.EMAIL: - return self._validate_email(email, password) - - # Authentication through username - if settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME: - return self._validate_username(username, password) - - # Authentication through either username or email - if email: - users = filter_users_by_email(email) - if not users or len(users) > 1: - raise ValidationError('Unable to login with provided credentials') - - return self._validate_username_email(username, email, password) - + if username: + user= self._validate_username(username=username,password=password) + if user is not None: + user.email = email + user.save() + return user class SocialLoginSerializerEx(SocialLoginSerializer): auth_params = serializers.CharField(required=False, allow_blank=True, default='')