'Invoked just after a user successfully authenticates via a
social provider, but before the login is actually processed.
We use it to:
1. Check if the user is connecting accounts via signup page
2. store the name of the socialaccount provider in the user\'s session.
TODO: When legacy Persona sessions are cleared (Nov 1 2016), this
function can probably go away as well.'

def pre_social_login(self, request, sociallogin):

    session_login_data = request.session.get('socialaccount_sociallogin', None)
    request_login = sociallogin
    if session_login_data:
        session_login = SocialLogin.deserialize(session_login_data)
        if (session_login.account.provider != request_login.account.provider):
            if (not request_login.is_existing):
                level = messages.ERROR
                message = 'socialaccount/messages/account_not_found.txt'
                get_adapter().add_message(request, level, message)
                raise ImmediateHttpResponse(redirect('socialaccount_signup'))
    request.session['sociallogin_provider'] = sociallogin.account.provider
    request.session.modified = True
