switched host email account, changed exception error
This commit is contained in:
parent
fec3e703ce
commit
f693c36382
|
|
@ -81,7 +81,6 @@ class LoginByUsernameOrEmailSerializer(SourceSerializerMixin,
|
||||||
"""Serializer for login user"""
|
"""Serializer for login user"""
|
||||||
# REQUEST
|
# REQUEST
|
||||||
username_or_email = serializers.CharField(write_only=True)
|
username_or_email = serializers.CharField(write_only=True)
|
||||||
password = serializers.CharField(write_only=True)
|
|
||||||
|
|
||||||
# For cookie properties (Max-Age)
|
# For cookie properties (Max-Age)
|
||||||
remember = serializers.BooleanField(write_only=True)
|
remember = serializers.BooleanField(write_only=True)
|
||||||
|
|
@ -101,21 +100,24 @@ class LoginByUsernameOrEmailSerializer(SourceSerializerMixin,
|
||||||
'refresh_token',
|
'refresh_token',
|
||||||
'access_token',
|
'access_token',
|
||||||
)
|
)
|
||||||
|
extra_kwargs = {
|
||||||
|
'password': {'write_only': True}
|
||||||
|
}
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
"""Override validate method"""
|
"""Override validate method"""
|
||||||
username_or_email = attrs.pop('username_or_email')
|
username_or_email = attrs.pop('username_or_email')
|
||||||
password = attrs.pop('password')
|
password = attrs.pop('password')
|
||||||
user_qs = account_models.User.objects.filter(Q(username=username_or_email) |
|
user_qs = account_models.User.objects.filter(Q(username=username_or_email) |
|
||||||
(Q(email=username_or_email)))
|
Q(email=username_or_email))
|
||||||
if not user_qs.exists():
|
if not user_qs.exists():
|
||||||
raise utils_exceptions.UserNotFoundError()
|
raise utils_exceptions.WrongAuthCredentials()
|
||||||
else:
|
else:
|
||||||
user = user_qs.first()
|
user = user_qs.first()
|
||||||
authentication = authenticate(username=user.get_username(),
|
authentication = authenticate(username=user.get_username(),
|
||||||
password=password)
|
password=password)
|
||||||
if not authentication:
|
if not authentication:
|
||||||
raise utils_exceptions.UserNotFoundError()
|
raise utils_exceptions.WrongAuthCredentials()
|
||||||
self.instance = user
|
self.instance = user
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
@ -127,10 +129,6 @@ class LoginByUsernameOrEmailSerializer(SourceSerializerMixin,
|
||||||
return super().to_representation(instance)
|
return super().to_representation(instance)
|
||||||
|
|
||||||
|
|
||||||
class LogoutSerializer(SourceSerializerMixin):
|
|
||||||
"""Serializer for Logout endpoint."""
|
|
||||||
|
|
||||||
|
|
||||||
class RefreshTokenSerializer(SourceSerializerMixin):
|
class RefreshTokenSerializer(SourceSerializerMixin):
|
||||||
"""Serializer for refresh token view"""
|
"""Serializer for refresh token view"""
|
||||||
refresh_token = serializers.CharField(read_only=True)
|
refresh_token = serializers.CharField(read_only=True)
|
||||||
|
|
@ -169,7 +167,3 @@ class RefreshTokenSerializer(SourceSerializerMixin):
|
||||||
class OAuth2Serialzier(SourceSerializerMixin):
|
class OAuth2Serialzier(SourceSerializerMixin):
|
||||||
"""Serializer OAuth2 authorization"""
|
"""Serializer OAuth2 authorization"""
|
||||||
token = serializers.CharField(max_length=255)
|
token = serializers.CharField(max_length=255)
|
||||||
|
|
||||||
|
|
||||||
class OAuth2LogoutSerializer(SourceSerializerMixin):
|
|
||||||
"""Serializer for logout"""
|
|
||||||
|
|
|
||||||
|
|
@ -27,24 +27,6 @@ from utils.permissions import IsAuthenticatedAndTokenIsValid
|
||||||
from utils.views import JWTGenericViewMixin
|
from utils.views import JWTGenericViewMixin
|
||||||
|
|
||||||
|
|
||||||
# Mixins
|
|
||||||
# JWTAuthView mixin
|
|
||||||
class JWTAuthViewMixin(JWTGenericViewMixin):
|
|
||||||
"""Mixin for authentication views"""
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
"""Implement POST method"""
|
|
||||||
serializer = self.get_serializer(data=request.data)
|
|
||||||
serializer.is_valid(raise_exception=True)
|
|
||||||
response = Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
access_token = serializer.data.get('access_token')
|
|
||||||
refresh_token = serializer.data.get('refresh_token')
|
|
||||||
return self._put_cookies_in_response(
|
|
||||||
cookies=self._put_data_in_cookies(access_token=access_token,
|
|
||||||
refresh_token=refresh_token),
|
|
||||||
response=response)
|
|
||||||
|
|
||||||
|
|
||||||
# OAuth2
|
# OAuth2
|
||||||
class BaseOAuth2ViewMixin(generics.GenericAPIView):
|
class BaseOAuth2ViewMixin(generics.GenericAPIView):
|
||||||
"""BaseMixin for classic auth views"""
|
"""BaseMixin for classic auth views"""
|
||||||
|
|
@ -112,6 +94,7 @@ class OAuth2SignUpView(OAuth2ViewMixin, JWTGenericViewMixin):
|
||||||
# Preparing request data
|
# Preparing request data
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
request_data = self.prepare_request_data(serializer.validated_data)
|
request_data = self.prepare_request_data(serializer.validated_data)
|
||||||
source = serializer.validated_data.get('source')
|
source = serializer.validated_data.get('source')
|
||||||
request_data.update({
|
request_data.update({
|
||||||
|
|
@ -196,7 +179,7 @@ class ConfirmationEmailView(JWTGenericViewMixin):
|
||||||
|
|
||||||
|
|
||||||
# Login by username|email + password
|
# Login by username|email + password
|
||||||
class LoginByUsernameOrEmailView(JWTAuthViewMixin):
|
class LoginByUsernameOrEmailView(JWTGenericViewMixin):
|
||||||
"""Login by email and password"""
|
"""Login by email and password"""
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = serializers.LoginByUsernameOrEmailSerializer
|
serializer_class = serializers.LoginByUsernameOrEmailSerializer
|
||||||
|
|
@ -205,10 +188,12 @@ class LoginByUsernameOrEmailView(JWTAuthViewMixin):
|
||||||
"""Implement POST method"""
|
"""Implement POST method"""
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
response = Response(serializer.data, status=status.HTTP_200_OK)
|
response = Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
access_token = serializer.data.get('access_token')
|
access_token = serializer.data.get('access_token')
|
||||||
refresh_token = serializer.data.get('refresh_token')
|
refresh_token = serializer.data.get('refresh_token')
|
||||||
is_permanent = serializer.validated_data.get('remember')
|
is_permanent = serializer.validated_data.get('remember')
|
||||||
|
|
||||||
return self._put_cookies_in_response(
|
return self._put_cookies_in_response(
|
||||||
cookies=self._put_data_in_cookies(access_token=access_token,
|
cookies=self._put_data_in_cookies(access_token=access_token,
|
||||||
refresh_token=refresh_token,
|
refresh_token=refresh_token,
|
||||||
|
|
@ -243,9 +228,11 @@ class RefreshTokenView(JWTGenericViewMixin):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
response = Response(serializer.data, status=status.HTTP_201_CREATED)
|
response = Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
access_token = serializer.data.get('access_token')
|
access_token = serializer.data.get('access_token')
|
||||||
refresh_token = serializer.data.get('refresh_token')
|
refresh_token = serializer.data.get('refresh_token')
|
||||||
|
|
||||||
return self._put_cookies_in_response(
|
return self._put_cookies_in_response(
|
||||||
cookies=self._put_data_in_cookies(access_token=access_token,
|
cookies=self._put_data_in_cookies(access_token=access_token,
|
||||||
refresh_token=refresh_token),
|
refresh_token=refresh_token),
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ class WrongAuthCredentials(AuthErrorMixin):
|
||||||
"""
|
"""
|
||||||
The exception should be raised when credentials is not valid for this user
|
The exception should be raised when credentials is not valid for this user
|
||||||
"""
|
"""
|
||||||
default_detail = _('Wrong authorization credentials')
|
default_detail = _('Incorrect login or password.')
|
||||||
|
|
||||||
|
|
||||||
class FavoritesError(exceptions.APIException):
|
class FavoritesError(exceptions.APIException):
|
||||||
|
|
|
||||||
|
|
@ -280,9 +280,9 @@ SMS_SENDER = 'GM'
|
||||||
|
|
||||||
# EMAIL
|
# EMAIL
|
||||||
EMAIL_USE_TLS = True
|
EMAIL_USE_TLS = True
|
||||||
EMAIL_HOST = 'smtp.gmail.com'
|
EMAIL_HOST = 'smtp.yandex.ru'
|
||||||
EMAIL_HOST_USER = 'anatolyfeteleu@gmail.com'
|
EMAIL_HOST_USER = 't3st.t3stov.t3stovich@yandex.ru'
|
||||||
EMAIL_HOST_PASSWORD = 'nggrlnbehzksgmbt'
|
EMAIL_HOST_PASSWORD = 'ylhernyutkfbylgk'
|
||||||
EMAIL_PORT = 587
|
EMAIL_PORT = 587
|
||||||
|
|
||||||
# Django Rest Swagger
|
# Django Rest Swagger
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user