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"""
|
||||
# REQUEST
|
||||
username_or_email = serializers.CharField(write_only=True)
|
||||
password = serializers.CharField(write_only=True)
|
||||
|
||||
# For cookie properties (Max-Age)
|
||||
remember = serializers.BooleanField(write_only=True)
|
||||
|
|
@ -101,21 +100,24 @@ class LoginByUsernameOrEmailSerializer(SourceSerializerMixin,
|
|||
'refresh_token',
|
||||
'access_token',
|
||||
)
|
||||
extra_kwargs = {
|
||||
'password': {'write_only': True}
|
||||
}
|
||||
|
||||
def validate(self, attrs):
|
||||
"""Override validate method"""
|
||||
username_or_email = attrs.pop('username_or_email')
|
||||
password = attrs.pop('password')
|
||||
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():
|
||||
raise utils_exceptions.UserNotFoundError()
|
||||
raise utils_exceptions.WrongAuthCredentials()
|
||||
else:
|
||||
user = user_qs.first()
|
||||
authentication = authenticate(username=user.get_username(),
|
||||
password=password)
|
||||
if not authentication:
|
||||
raise utils_exceptions.UserNotFoundError()
|
||||
raise utils_exceptions.WrongAuthCredentials()
|
||||
self.instance = user
|
||||
return attrs
|
||||
|
||||
|
|
@ -127,10 +129,6 @@ class LoginByUsernameOrEmailSerializer(SourceSerializerMixin,
|
|||
return super().to_representation(instance)
|
||||
|
||||
|
||||
class LogoutSerializer(SourceSerializerMixin):
|
||||
"""Serializer for Logout endpoint."""
|
||||
|
||||
|
||||
class RefreshTokenSerializer(SourceSerializerMixin):
|
||||
"""Serializer for refresh token view"""
|
||||
refresh_token = serializers.CharField(read_only=True)
|
||||
|
|
@ -169,7 +167,3 @@ class RefreshTokenSerializer(SourceSerializerMixin):
|
|||
class OAuth2Serialzier(SourceSerializerMixin):
|
||||
"""Serializer OAuth2 authorization"""
|
||||
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
|
||||
|
||||
|
||||
# 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
|
||||
class BaseOAuth2ViewMixin(generics.GenericAPIView):
|
||||
"""BaseMixin for classic auth views"""
|
||||
|
|
@ -112,6 +94,7 @@ class OAuth2SignUpView(OAuth2ViewMixin, JWTGenericViewMixin):
|
|||
# Preparing request data
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
request_data = self.prepare_request_data(serializer.validated_data)
|
||||
source = serializer.validated_data.get('source')
|
||||
request_data.update({
|
||||
|
|
@ -196,7 +179,7 @@ class ConfirmationEmailView(JWTGenericViewMixin):
|
|||
|
||||
|
||||
# Login by username|email + password
|
||||
class LoginByUsernameOrEmailView(JWTAuthViewMixin):
|
||||
class LoginByUsernameOrEmailView(JWTGenericViewMixin):
|
||||
"""Login by email and password"""
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.LoginByUsernameOrEmailSerializer
|
||||
|
|
@ -205,10 +188,12 @@ class LoginByUsernameOrEmailView(JWTAuthViewMixin):
|
|||
"""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')
|
||||
is_permanent = serializer.validated_data.get('remember')
|
||||
|
||||
return self._put_cookies_in_response(
|
||||
cookies=self._put_data_in_cookies(access_token=access_token,
|
||||
refresh_token=refresh_token,
|
||||
|
|
@ -243,9 +228,11 @@ class RefreshTokenView(JWTGenericViewMixin):
|
|||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
response = Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ class WrongAuthCredentials(AuthErrorMixin):
|
|||
"""
|
||||
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):
|
||||
|
|
|
|||
|
|
@ -280,9 +280,9 @@ SMS_SENDER = 'GM'
|
|||
|
||||
# EMAIL
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_HOST_USER = 'anatolyfeteleu@gmail.com'
|
||||
EMAIL_HOST_PASSWORD = 'nggrlnbehzksgmbt'
|
||||
EMAIL_HOST = 'smtp.yandex.ru'
|
||||
EMAIL_HOST_USER = 't3st.t3stov.t3stovich@yandex.ru'
|
||||
EMAIL_HOST_PASSWORD = 'ylhernyutkfbylgk'
|
||||
EMAIL_PORT = 587
|
||||
|
||||
# Django Rest Swagger
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user