Revision c8d89a3c snf-astakos-app/astakos/im/target/linkedin.py

b/snf-astakos-app/astakos/im/target/linkedin.py
55 55
from astakos.im import settings
56 56
from astakos.im import auth_providers
57 57
from astakos.im.target import add_pending_auth_provider, get_pending_key, \
58
    handle_third_party_signup
58
    handle_third_party_signup, handle_third_party_login
59 59

  
60 60
import astakos.im.messages as astakos_messages
61 61

  
......
149 149
    provider_info = profile_data
150 150
    affiliation = 'LinkedIn.com'
151 151

  
152
    third_party_key = get_pending_key(request)
153

  
154
    # an existing user accessed the view
155
    if request.user.is_authenticated():
156
        if request.user.has_auth_provider('linkedin', identifier=userid):
157
            return HttpResponseRedirect(reverse('edit_profile'))
158

  
159
        # automatically add eppn provider to user
160
        user = request.user
161
        if not request.user.can_add_auth_provider('linkedin',
162
                                                  identifier=userid):
163
            # TODO: handle existing uuid message separately
164
            messages.error(request, _(astakos_messages.AUTH_PROVIDER_ADD_FAILED) +
165
                          u' ' + _(astakos_messages.AUTH_PROVIDER_ADD_EXISTS))
166
            return HttpResponseRedirect(reverse('edit_profile'))
167

  
168
        user.add_auth_provider('linkedin', identifier=userid,
169
                               affiliation=affiliation,
170
                               provider_info=provider_info)
171
        messages.success(request, astakos_messages.AUTH_PROVIDER_ADDED)
172
        return HttpResponseRedirect(reverse('edit_profile'))
173 152

  
174 153
    try:
175
        # astakos user exists ?
176
        user = AstakosUser.objects.get_auth_provider_user(
177
            'linkedin',
178
            identifier=userid
179
        )
180
        if user.is_active:
181
            # authenticate user
182
            response = prepare_response(request,
183
                                    user,
184
                                    next_url,
185
                                    'renew' in request.GET)
186
            provider = auth_providers.get_provider('linkedin')
187
            messages.success(request, _(astakos_messages.LOGIN_SUCCESS) %
188
                             _(provider.get_login_message_display))
189
            add_pending_auth_provider(request, third_party_key)
190
            response.set_cookie('astakos_last_login_method', 'linkedin')
191
            return response
192
        else:
193
            message = user.get_inactive_message()
194
            messages.error(request, message)
195
            return HttpResponseRedirect(login_url(request))
196

  
154
        return handle_third_party_login(request, 'linkedin', userid,
155
                                        provider_info, affiliation)
197 156
    except AstakosUser.DoesNotExist, e:
157
        third_party_key = get_pending_key(request)
198 158
        user_info = {'affiliation': affiliation, 'realname': realname}
199 159
        return handle_third_party_signup(request, userid, 'linkedin',
200 160
                                         third_party_key,

Also available in: Unified diff