Esempio n. 1
0
    def validate(self, attrs):
        try:
            data = instagram.authenticate(
                attrs["code"], redirect_uri=settings.SIGNIN_REDIRECT_URI)
        except Exception as e:
            raise exceptions.AuthenticationFailed(
                _("Invalid Instagram code."), ) from e
        user_id = data.get("user_id")
        User = get_user_model()
        self.user = User.objects.filter(instagram_user_id=user_id).first()

        # Prior to Django 1.10, inactive users could be authenticated with the
        # default `ModelBackend`.  As of Django 1.10, the `ModelBackend`
        # prevents inactive users from authenticating.  App designers can still
        # allow inactive users to authenticate by opting for the new
        # `AllowAllUsersModelBackend`.  However, we explicitly prevent inactive
        # users from authenticating to enforce a reasonable policy and provide
        # sensible backwards compatibility with older Django versions.
        if self.user is None or not self.user.is_active:
            raise exceptions.AuthenticationFailed(
                self.error_messages["no_active_account"],
                "no_active_account",
            )

        refresh = self.get_token(self.user)
        data = {"refresh": str(refresh), "access": str(refresh.access_token)}

        return data
Esempio n. 2
0
    def validate(self, attrs):

        authenticate_kwargs = {
            self.username_field: attrs[self.username_field].lower(),
            'password': attrs['password'],
        }
        try:
            authenticate_kwargs['request'] = self.context['request']
        except KeyError:
            pass

        self.user = authenticate(**authenticate_kwargs)

        if self.user is None:
            raise exceptions.AuthenticationFailed(
                detail=self.error_messages['auth_failed'],
                code='invalid-credentials',
            )
        elif not self.user.is_active:
            raise exceptions.AuthenticationFailed(
                detail=self.error_messages['inactive'],
                code='inactive',
            )

        refresh = self.get_token(self.user)

        return {
            'refresh': str(refresh),
            'access': str(refresh.access_token)
        }
Esempio n. 3
0
    def validate(self, attrs):
        authenticate_kwargs = {
            self.username_field: attrs[self.username_field],
            'password': attrs['password'],
        }
        try:
            authenticate_kwargs['request'] = self.context['request']
        except KeyError:
            pass

        self.user = authenticate(**authenticate_kwargs)
        #or not self.user.is_active:
        if self.user is None:
            raise exceptions.AuthenticationFailed(
                self.error_messages['no_active_account'],
                'no_active_account',
            )
        
        refresh = self.get_token(self.user)
        data = {}
        data['refresh'] = str(refresh)
        data['access'] = str(refresh.access_token)
        data['university'] = self.user.university
        data['nickname'] = self.user.nickname

        return data 
Esempio n. 4
0
    def __call__(self, value, serializer_field):
        email = serializer_field.initial_data.get('email')
        confirmation_code = serializer_field.initial_data.get(
            'confirmation_code')

        credentials = Auth.objects.filter(email=email)
        if not credentials.exists(
        ) or not credentials[0].check_confirmation_code(confirmation_code):
            raise exceptions.AuthenticationFailed()
Esempio n. 5
0
    def validate(self, attrs):
        authenticate_kwargs = {
            self.username_field: attrs[self.username_field],
            'password': attrs['password'],
        }

        self.user = authenticate(**authenticate_kwargs)

        if self.user is None or not self.user.is_active:
            raise exceptions.AuthenticationFailed(
                self.error_messages['no_active_account'],
                'no_active_account',
            )

        refresh = self.get_token(self.user)
        data = {}
        data['nickname'] = self.user.nickname
        data['refresh'] = str(refresh)
        data['access'] = str(refresh.access_token)
        return data
    def _get_superuser(self):
        user = User.objects.filter(is_superuser=True).first()
        if not user:
            raise exceptions.AuthenticationFailed("No superusers identified")

        return user