def perform_create(self, serializer): user = serializer.save(self.request) if getattr(settings, 'REST_USE_JWT', False): self.token = jwt_encode(user) else: create_token(self.token_model, user, serializer) complete_signup(self.request._request, user, allauth_settings.EMAIL_VERIFICATION, None) return user
def perform_create(self, serializer): user = serializer.save(self.request) if allauth_settings.EMAIL_VERIFICATION != \ allauth_settings.EmailVerificationMethod.MANDATORY: if getattr(settings, 'REST_USE_JWT', False): self.access_token, self.refresh_token = jwt_encode(user) else: create_token(self.token_model, user, serializer) complete_signup(self.request._request, user, allauth_settings.EMAIL_VERIFICATION, None) return user
def perform_create(self, serializer): user = serializer.save(self.request) if (allauth_settings.EMAIL_VERIFICATION != allauth_settings.EmailVerificationMethod.MANDATORY): if getattr(settings, "REST_USE_JWT", False): self.access_token, self.refresh_token = jwt_encode(user) else: create_token(self.token_model, user, serializer) email_address = EmailAddress.objects.get(user=user, email=user.email) confirmation_key = EmailConfirmationHMAC(email_address).key # TODO Send Email here -> "account-confirm-email/" + confirmation_key send_regestration_mail.delay(user.username, user.email, confirmation_key) return user
def perform_create(self, serializer): user = serializer.save(self.request) if allauth_settings.EMAIL_VERIFICATION != \ allauth_settings.EmailVerificationMethod.MANDATORY: if getattr(settings, 'REST_USE_JWT', False): self.access_token, self.refresh_token = jwt_encode(user) elif not getattr(settings, 'REST_SESSION_LOGIN', False): # Session authentication isn't active either, so this has to be # token authentication create_token(self.token_model, user, serializer) complete_signup( self.request._request, user, allauth_settings.EMAIL_VERIFICATION, None, ) return user
def create(self, request): data = request.data serializer = self.get_serializer(data=data) serializer.is_valid(raise_exception=True) serializer.save() self.user = User.objects.get(username=serializer.data.get('username')) if getattr(settings, 'REST_USE_JWT', False): self.access_token, self.refresh_token = jwt_encode(self.user) else: self.token = create_token(self.token_model, self.user, self.serializer) data = login.get_response(self).data return Response(data=data, status=status.HTTP_201_CREATED)
def token_view(request): """ Used to generate a token for the API from the Backend; Given a POST from a user that logged in via the Backend creates a new KnoxToken and returns the token key. """ if not app_settings.ASTROSAT_USERS_ENABLE_BACKEND_ACCESS: raise APIException( "token_view can only be called when ASTROSAT_USERS_ENABLE_BACKEND_ACCESS is set to 'True'" ) try: _, token_key = create_token(TokenModel, request.user, TokenSerializer) except Exception as e: raise APIException(e) return Response(token_key)
def create_auth_token(user): """ returns a knox token for a specific user. """ return create_token(TokenModel, user, TokenSerializer)