def get(self, request, *args, **kwargs): auth_request = get_auth_request(request) response = api.poll_request(auth_request) message_code = response.get('message_code') if message_code == POLL_ERROR_NO_REQUEST: self.authentication_no_request() pending = message_code == POLL_ERROR_PENDING_RESPONSE expired = message_code == POLL_ERROR_EXPIRED_REQUEST authorized = False user_hash = response.get('user_hash') auth_package = response.get('auth') if auth_package: authorized = api.is_authorized(auth_request, auth_package) if user_hash: if self.request.user and self.request.user.is_authenticated(): association = Association.objects.associate(self.request.user, user_hash) else: try: association = Association.objects.get(user_hash=user_hash) except Association.DoesNotExist: return self.authentication_failed() if authorized: association.authorized = authorized association.save() authorized = association.authorized if self.request.is_ajax(): return self.auth_request_check( authorized=authorized, pending=pending, expired=expired) if authorized: return self.auth_request_authorized(user_hash) if expired: return self.auth_request_expired() return super(AuthRequestView, self).get(request, *args, **kwargs)
def log_logout(sender, request, user, **kwargs): auth_request = get_auth_request(request) api.logout(auth_request)
def authentication_failed(self): api.logout(get_auth_request(self.request)) messages.error(self.request, _(u"Could not authenticate with LaunchKey account.")) return HttpResponseRedirect(resolve_url('launchkey-login'))