Beispiel #1
0
    def for_identity(self, identity, request):
        try:
            user_map = self.get(identity=identity)
        except self.model.DoesNotExist:
            # if there is authenticated user - map identity to that user
            # if not - create new user and mapping for him
            if request.user.is_authenticated():
                user = request.user
            else:
                loginza_data = json.loads(identity.data)

                loginza_email = loginza_data.get('email', '')
                email = loginza_email if '@' in loginza_email else settings.DEFAULT_EMAIL

                # if nickname is not set - try to get it from email
                # e.g. [email protected] -> vgarvardt
                loginza_nickname = loginza_data.get('nickname', None)
                if loginza_nickname is None or loginza_nickname == "":
                    username = email.split('@')[0]
                else:
                    username = loginza_nickname

                # check duplicate user name
                while User.objects.filter(username=username).exists():
                    username = get_next_username()

                user = User.objects.create_user(
                    username,
                    email
                )
            user_map = UserMap.objects.create(identity=identity, user=user)
            signals.created.send(request, user_map=user_map)
        return user_map
Beispiel #2
0
    def test_should_return_ascii_value(self):
        response = get_next_username()
        try:
            response.decode('ascii')
            is_raised = False
        except UnicodeDecodeError:
            is_raised = True

        self.assertFalse(is_raised, 'get_next_username should return ascii encoded value')
Beispiel #3
0
    def test_should_return_ascii_value(self):
        response = get_next_username()
        try:
            response.decode('ascii')
            is_raised = False
        except UnicodeDecodeError:
            is_raised = True

        self.assertFalse(
            is_raised, 'get_next_username should return ascii encoded value')
Beispiel #4
0
 def test_should_return_30_chars_length_value(self):
     response = get_next_username()
     msg = 'should return 30 chars length value, because User.username field max_length=30'
     self.assertEqual(len(response), 30, msg=msg)
Beispiel #5
0
 def test_should_return_value_without_spaces(self):
     response = get_next_username()
     self.assertFalse(' ' in response)
Beispiel #6
0
 def test_should_return_random_value(self):
     for i in range(10):
         self.assertNotEqual(get_next_username(), get_next_username())
Beispiel #7
0
 def test_should_return_30_chars_length_value(self):
     response = get_next_username()
     msg = 'should return 30 chars length value, because User.username field max_length=30'
     self.assertEqual(len(response), 30, msg=msg)
Beispiel #8
0
 def test_should_return_value_without_spaces(self):
     response = get_next_username()
     self.assertFalse(' ' in response)
Beispiel #9
0
 def test_should_return_random_value(self):
     for i in range(10):
         self.assertNotEqual(get_next_username(), get_next_username())