Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email update #6

Open
wants to merge 3 commits into
base: dt-v2.3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cvat-core/src/server-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface SocialAccountLinkProps {
export enum CVATInputType {
TEXT = 'text',
PASSWORD = 'passord',
EMAIL = 'email'
}

function CVATSigningInput(props: SocialAccountLinkProps): JSX.Element {
Expand Down
44 changes: 8 additions & 36 deletions cvat/apps/iam/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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='')
Expand Down