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 authorize(self, auth_request, user_hash, auth_package): association = get_object_or_404(Association, user_hash=user_hash) association.authorized = api.is_authorized(auth_request, auth_package) association.save()