social-core icon indicating copy to clipboard operation
social-core copied to clipboard

Return user-appropriate 'account already in use' errors (i.e. without backend.name strings)

Open mc-funk opened this issue 8 years ago • 0 comments

The otherwise user-friendly text provided when an account is already in use uses the backend name -- e.g. 'github', 'bitbucket-oauth2', etc., which is not suitable for being piped through to the user without parsing it:

Fn (/pipeline/social_auth.py)

def social_user(backend, uid, user=None, *args, **kwargs):
    provider = backend.name
    social = backend.strategy.storage.user.get_social_auth(provider, uid)
    if social:
        if user and social.user != user:
            msg = 'This {0} account is already in use.'.format(provider)
            raise AuthAlreadyAssociated(backend, msg)
        elif not user:
            user = social.user
    return {'social': social,
            'user': user,
            'is_new': user is None,
            'new_association': social is None}

Test: (/social_core/tests/actions/test_associate.py)

    def test_already_associated_error(self):
        self.user = self.user1
        self.do_login()
        self.user = User(username='foobar2', email='[email protected]')
        with self.assertRaisesRegexp(AuthAlreadyAssociated,
                                     'This github account is already in use.'):
            self.do_login()

Probably the most dead-simple way to fix this would be to remove the provider name from the error message entirely; I don't know all the use cases, but it's plausible that a user would already know what type of account they were trying to connect.

mc-funk avatar Oct 03 '18 20:10 mc-funk