@@ -62,7 +62,7 @@ def post(self, request, *args, **kwargs):
6262 else :
6363 status_code = status .HTTP_400_BAD_REQUEST
6464 response_detail = self .failure_response
65- return Response ({' detail' : response_detail }, status = status_code )
65+ return Response ({" detail" : response_detail }, status = status_code )
6666 else :
6767 return Response (serializer .error_messages , status = status .HTTP_400_BAD_REQUEST )
6868
@@ -73,15 +73,15 @@ class ObtainEmailCallbackToken(AbstractBaseObtainCallbackToken):
7373 success_response = "A login token has been sent to your email."
7474 failure_response = "Unable to email you a login code. Try again later."
7575
76- alias_type = ' email'
76+ alias_type = " email"
7777 token_type = CallbackToken .TOKEN_TYPE_AUTH
7878
7979 email_subject = api_settings .PASSWORDLESS_EMAIL_SUBJECT
8080 email_plaintext = api_settings .PASSWORDLESS_EMAIL_PLAINTEXT_MESSAGE
8181 email_html = api_settings .PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME
82- message_payload = {' email_subject' : email_subject ,
83- ' email_plaintext' : email_plaintext ,
84- ' email_html' : email_html }
82+ message_payload = {" email_subject" : email_subject ,
83+ " email_plaintext" : email_plaintext ,
84+ " email_html" : email_html }
8585
8686
8787class ObtainMobileCallbackToken (AbstractBaseObtainCallbackToken ):
@@ -90,11 +90,11 @@ class ObtainMobileCallbackToken(AbstractBaseObtainCallbackToken):
9090 success_response = "We texted you a login code."
9191 failure_response = "Unable to send you a login code. Try again later."
9292
93- alias_type = ' mobile'
93+ alias_type = " mobile"
9494 token_type = CallbackToken .TOKEN_TYPE_AUTH
9595
9696 mobile_message = api_settings .PASSWORDLESS_MOBILE_MESSAGE
97- message_payload = {' mobile_message' : mobile_message }
97+ message_payload = {" mobile_message" : mobile_message }
9898
9999
100100class ObtainEmailVerificationCallbackToken (AbstractBaseObtainCallbackToken ):
@@ -103,16 +103,16 @@ class ObtainEmailVerificationCallbackToken(AbstractBaseObtainCallbackToken):
103103 success_response = "A verification token has been sent to your email."
104104 failure_response = "Unable to email you a verification code. Try again later."
105105
106- alias_type = ' email'
106+ alias_type = " email"
107107 token_type = CallbackToken .TOKEN_TYPE_VERIFY
108108
109109 email_subject = api_settings .PASSWORDLESS_EMAIL_VERIFICATION_SUBJECT
110110 email_plaintext = api_settings .PASSWORDLESS_EMAIL_VERIFICATION_PLAINTEXT_MESSAGE
111111 email_html = api_settings .PASSWORDLESS_EMAIL_VERIFICATION_TOKEN_HTML_TEMPLATE_NAME
112112 message_payload = {
113- ' email_subject' : email_subject ,
114- ' email_plaintext' : email_plaintext ,
115- ' email_html' : email_html
113+ " email_subject" : email_subject ,
114+ " email_plaintext" : email_plaintext ,
115+ " email_html" : email_html
116116 }
117117
118118
@@ -122,11 +122,11 @@ class ObtainMobileVerificationCallbackToken(AbstractBaseObtainCallbackToken):
122122 success_response = "We texted you a verification code."
123123 failure_response = "Unable to send you a verification code. Try again later."
124124
125- alias_type = ' mobile'
125+ alias_type = " mobile"
126126 token_type = CallbackToken .TOKEN_TYPE_VERIFY
127127
128128 mobile_message = api_settings .PASSWORDLESS_MOBILE_MESSAGE
129- message_payload = {' mobile_message' : mobile_message }
129+ message_payload = {" mobile_message" : mobile_message }
130130
131131
132132class AbstractBaseObtainAuthToken (APIView ):
@@ -139,19 +139,19 @@ class AbstractBaseObtainAuthToken(APIView):
139139 def post (self , request , * args , ** kwargs ):
140140 serializer = self .serializer_class (data = request .data )
141141 if serializer .is_valid (raise_exception = True ):
142- user = serializer .validated_data [' user' ]
142+ user = serializer .validated_data [" user" ]
143143 token_creator = import_string (api_settings .PASSWORDLESS_AUTH_TOKEN_CREATOR )
144144 (token , _ ) = token_creator (user )
145145
146146 if token :
147147 TokenSerializer = import_string (api_settings .PASSWORDLESS_AUTH_TOKEN_SERIALIZER )
148- token_serializer = TokenSerializer (data = token .__dict__ , partial = True )
148+ token_serializer = TokenSerializer (data = token .__dict__ , partial = True , context = { "request" : request } )
149149 if token_serializer .is_valid ():
150150 # Return our key for consumption.
151151 return Response (token_serializer .data , status = status .HTTP_200_OK )
152152 else :
153153 logger .error ("Couldn't log in unknown user. Errors on serializer: {}" .format (serializer .error_messages ))
154- return Response ({' detail' : ' Couldn\ ' t log you in. Try again later.' }, status = status .HTTP_400_BAD_REQUEST )
154+ return Response ({" detail" : " Couldn't log you in. Try again later." }, status = status .HTTP_400_BAD_REQUEST )
155155
156156
157157class ObtainAuthTokenFromCallbackToken (AbstractBaseObtainAuthToken ):
@@ -171,10 +171,10 @@ class VerifyAliasFromCallbackToken(APIView):
171171 serializer_class = CallbackTokenVerificationSerializer
172172
173173 def post (self , request , * args , ** kwargs ):
174- serializer = self .serializer_class (data = request .data , context = {' user_id' : self .request .user .id })
174+ serializer = self .serializer_class (data = request .data , context = {" user_id" : self .request .user .id })
175175 if serializer .is_valid (raise_exception = True ):
176- return Response ({' detail' : ' Alias verified.' }, status = status .HTTP_200_OK )
176+ return Response ({" detail" : " Alias verified." }, status = status .HTTP_200_OK )
177177 else :
178178 logger .error ("Couldn't verify unknown user. Errors on serializer: {}" .format (serializer .error_messages ))
179179
180- return Response ({' detail' : ' We couldn\ ' t verify this alias. Try again later.' }, status .HTTP_400_BAD_REQUEST )
180+ return Response ({" detail" : " We couldn't verify this alias. Try again later." }, status .HTTP_400_BAD_REQUEST )
0 commit comments