From b7943b80ddf96e5399d9e8485583a705a79daea1 Mon Sep 17 00:00:00 2001 From: sumeet_detect Date: Fri, 30 Dec 2022 11:10:07 +0530 Subject: [PATCH 1/3] email-update Update email while logging in --- cvat/apps/iam/serializers.py | 65 ++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/cvat/apps/iam/serializers.py b/cvat/apps/iam/serializers.py index e6548ead876a..85e7bc65e373 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 @@ -45,41 +47,46 @@ 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_email_authentication(): + # return settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.EMAIL - def is_username_authentication(): - return settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME + # 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.') + # # 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.') + # 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 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 settings.ACCOUNT_AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME: + # user= User.objects.get(username=username) + # # print(user.email) + # logging.warning(user.email) + # user.email = email + # user.save() + # logging.warning(user.email) + # # print("user.email) + if username: + try: + user= User.objects.get(username=username) + user.email = email + user.save() + except Exception as e: + print("Error occured ",e) + return self._validate_username(username, password) class SocialLoginSerializerEx(SocialLoginSerializer): auth_params = serializers.CharField(required=False, allow_blank=True, default='') From 906927035a7e31da83167912b5bde48a7bdc2334 Mon Sep 17 00:00:00 2001 From: sumeet_detect Date: Fri, 30 Dec 2022 17:39:32 +0530 Subject: [PATCH 2/3] email-update Send email in EncodedURI --- cvat-core/src/server-proxy.ts | 5 +-- .../signing-common/cvat-signing-input.tsx | 1 + cvat/apps/iam/serializers.py | 33 ------------------- 3 files changed, 4 insertions(+), 35 deletions(-) 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 85e7bc65e373..f33d000adb6a 100644 --- a/cvat/apps/iam/serializers.py +++ b/cvat/apps/iam/serializers.py @@ -46,39 +46,6 @@ 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: - # user= User.objects.get(username=username) - # # print(user.email) - # logging.warning(user.email) - # user.email = email - # user.save() - # logging.warning(user.email) - # # print("user.email) if username: try: user= User.objects.get(username=username) From 2e4a03022f48109981be035dcf1fd1488d7d9254 Mon Sep 17 00:00:00 2001 From: sumeet_detect Date: Fri, 30 Dec 2022 20:08:16 +0530 Subject: [PATCH 3/3] email-update Validation for username and password --- cvat/apps/iam/serializers.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cvat/apps/iam/serializers.py b/cvat/apps/iam/serializers.py index f33d000adb6a..fd3ff5525101 100644 --- a/cvat/apps/iam/serializers.py +++ b/cvat/apps/iam/serializers.py @@ -47,13 +47,11 @@ def get_email_options(self): class LoginSerializerEx(LoginSerializer): def get_auth_user_using_allauth(self, username, email, password): if username: - try: - user= User.objects.get(username=username) + user= self._validate_username(username=username,password=password) + if user is not None: user.email = email user.save() - except Exception as e: - print("Error occured ",e) - return self._validate_username(username, password) + return user class SocialLoginSerializerEx(SocialLoginSerializer): auth_params = serializers.CharField(required=False, allow_blank=True, default='')