Exemplo n.º 1
0
    def validate(self, data):

        try:
            user = get_user_model().objects.get(email=data['email'])
        except get_user_model().DoesNotExist:
            raise UserNotFound()
        # Added user model to OrderedDict that serializer is validating
        data['user'] = user

        return data
Exemplo n.º 2
0
 def setUp(self):
     self.user_model = get_user_model()
     self.user = self.user_model.objects.create(
         username='******',
         email='*****@*****.**',
         password='******',
     )
Exemplo n.º 3
0
    def setUp(self):
        super().setUp()

        # Assuming that no user password created by social
        self.user_1 = get_user_model().objects.create(
            username='******',
            email='*****@*****.**'
        )
Exemplo n.º 4
0
    class Meta:
        model = get_user_model()

        # Check to response has password field in the case enable Facebook or Google login
        fields = drfr_settings.USER_FIELDS + (
            'has_password', ) if enable_has_password(
            ) else drfr_settings.USER_FIELDS
        read_only_fields = drfr_settings.USER_READ_ONLY_FIELDS
        extra_kwargs = {'password': {'write_only': True}}
Exemplo n.º 5
0
    def setUp(self):
        super().setUp()
        self.client = APIClient()
        self.auth = False
        self.resource = 'accounts'
        self.endpoint = '/api'

        self.user_model = get_user_model()
        self.user = self.user_model.objects.create(
            username='******',
            email='*****@*****.**',
        )

        self.user.set_password('123456')
        self.user.save()
Exemplo n.º 6
0
    def post(self, request, *args, **kwargs):
        """
        Authenticate user through the provider and access_token
        """

        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)

        provider = serializer.data.get('provider', None)

        # Check is invalid provider
        if not socials.is_valid_provider(provider):
            raise InvalidProvider()

        # Check valid token
        access_token = serializer.data.get('access_token', None)

        user_data = socials.get_user_info(provider, access_token)

        # None value mean the access token is not valid
        if not user_data:
            raise InvalidAccessToken()

        # Check the case can not get user email address
        if not user_data.get('email'):
            raise MissingEmail()

        # Create user if not exist
        User = get_user_model()
        try:
            user = User.objects.get(email=user_data['email'])
        except User.DoesNotExist:
            user = User.objects.create(
                username=user_data['email'],
                email=user_data['email'],
                first_name=user_data.get('first_name'),
                last_name=user_data.get('last_name'),
            )

            # Always verified user if they using Google or Facebook
            set_user_verified(user)

        # Update last logged in
        update_last_login(None, user)
        data = get_user_profile_data(user)

        return Response(data, status=status.HTTP_200_OK)
    def test_get_user_model(self):
        user_model = get_user_model()

        self.assertHasModelFields(user_model, ['username', 'email'])
 def setUp(self):
     self.user_model = get_user_model()
Exemplo n.º 9
0
 class Meta:
     model = get_user_model()
     fields = ('username', 'password')
Exemplo n.º 10
0
 def test_get_user_model(self):
     self.assertEqual(users.get_user_model(), get_user_model())