Esempio n. 1
0
    def post(self):
        """Handles POST requests."""
        username = self.normalized_payload.get('username')

        username_is_taken = user_services.is_username_taken(username)
        self.render_json({
            'username_is_taken': username_is_taken,
        })
Esempio n. 2
0
    def post(self):
        """Handles POST requests."""
        username = self.payload.get("username")
        try:
            user_services.UserSettings.require_valid_username(username)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        username_is_taken = user_services.is_username_taken(username)
        self.render_json({"username_is_taken": username_is_taken})
Esempio n. 3
0
    def post(self):
        """Handles POST requests."""
        username = self.payload.get('username')
        try:
            user_services.UserSettings.require_valid_username(username)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        username_is_taken = user_services.is_username_taken(username)
        self.render_json({
            'username_is_taken': username_is_taken,
        })
Esempio n. 4
0
    def put(self):
        old_username = self.normalized_payload.get('old_username')
        new_username = self.normalized_payload.get('new_username')

        user_id = user_services.get_user_id_from_username(old_username)
        if user_id is None:
            raise self.InvalidInputException('Invalid username: %s' %
                                             old_username)

        if user_services.is_username_taken(new_username):
            raise self.InvalidInputException('Username already taken.')

        user_services.set_username(user_id, new_username)
        user_services.log_username_change(self.user_id, old_username,
                                          new_username)
        self.render_json({})
Esempio n. 5
0
    def put(self):
        old_username = self.payload.get('old_username', None)
        new_username = self.payload.get('new_username', None)

        if old_username is None:
            raise self.InvalidInputException(
                'Invalid request: The old username must be specified.')

        if new_username is None:
            raise self.InvalidInputException(
                'Invalid request: A new username must be specified.')

        if not isinstance(old_username, python_utils.UNICODE):
            raise self.InvalidInputException(
                'Expected old username to be a unicode string, received %s' %
                old_username)

        if not isinstance(new_username, python_utils.UNICODE):
            raise self.InvalidInputException(
                'Expected new username to be a unicode string, received %s' %
                new_username)

        user_id = user_services.get_user_id_from_username(old_username)
        if user_id is None:
            raise self.InvalidInputException('Invalid username: %s' %
                                             old_username)

        if len(new_username) > constants.MAX_USERNAME_LENGTH:
            raise self.InvalidInputException(
                'Expected new username to be less than %s characters, '
                'received %s' % (constants.MAX_USERNAME_LENGTH, new_username))

        if user_services.is_username_taken(new_username):
            raise self.InvalidInputException('Username already taken.')

        user_services.set_username(user_id, new_username)
        user_services.log_username_change(self.user_id, old_username,
                                          new_username)
        self.render_json({})
Esempio n. 6
0
 def test_is_username_taken_different_case(self):
     user_id = 'someUser'
     username = '******'
     user_services._create_user(user_id, '*****@*****.**')
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken('CaMeLcAsE'))
Esempio n. 7
0
 def test_is_username_taken_true(self):
     user_id = 'someUser'
     username = '******'
     user_services._create_user(user_id, '*****@*****.**')
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken(username))
Esempio n. 8
0
 def test_is_username_taken_false(self):
     self.assertFalse(user_services.is_username_taken('fakeUsername'))
Esempio n. 9
0
 def test_is_username_taken_true(self):
     user_id = 'someUser'
     username = '******'
     user_services.get_or_create_user(user_id, '*****@*****.**')
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken(username))
Esempio n. 10
0
 def test_is_username_taken_different_case(self):
     user_id = 'someUser'
     username = '******'
     user_services._create_user(user_id, '*****@*****.**')
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken('CaMeLcAsE'))
Esempio n. 11
0
 def test_is_username_taken_true(self):
     user_id = 'someUser'
     username = '******'
     user_services._create_user(user_id, '*****@*****.**')
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken(username))
Esempio n. 12
0
 def test_is_username_taken_false(self):
     self.assertFalse(user_services.is_username_taken('fakeUsername'))
Esempio n. 13
0
 def test_is_username_taken_true(self):
     user_id = 'someUser'
     username = '******'
     user_services.get_or_create_user(user_id, '*****@*****.**')
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken(username))
Esempio n. 14
0
 def test_is_username_taken_different_case(self):
     user_id = "someUser"
     username = "******"
     user_services._create_user(user_id, "*****@*****.**")
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken("CaMeLcAsE"))
Esempio n. 15
0
 def test_is_username_taken_true(self):
     user_id = "someUser"
     username = "******"
     user_services._create_user(user_id, "*****@*****.**")
     user_services.set_username(user_id, username)
     self.assertTrue(user_services.is_username_taken(username))