@gen.engine
  def _AuthUser(self, user_dict, ident_dict, device_dict, confirmed=False):
    """Called when a requester has been authenticated as a Viewfinder user by a trusted authority
    that provides additional information about the user, such as name, email, gender, etc. At
    this point, we can trust that the identity key provided in "ident_dict" is controlled by the
    calling user.

    Completes the authentication action in two steps: first, makes sure the user id and device
    id are retrieved or allocated as necessary; second, starts a user registration operation and
    returns a login cookie. If "confirmed" is True, then the "confirm_time" field in the user
    cookie is set, indicating the time at which the user confirmed their control of the identity
    via email or SMS. This type of cookie is necessary to perform certain high-privilege
    operations, such as updating the password.

    Registration is synchronous, meaning that the caller will wait until it is complete. This
    ensures that when the caller tries to login immediately following this call, the new user
    will be created and ready.
    """
    before_user = yield gen.Task(self._PrepareAuthUser, user_dict, ident_dict, device_dict)

    # Map auth attribute names to those used by User schema and exclude any attributes that are not yet stored
    # in the User table.
    scratch_user_dict = {'user_id': user_dict['user_id']}
    for k, v in user_dict.items():
      user_key = AuthHandler._AUTH_ATTRIBUTE_MAP.get(k, None)
      if user_key is not None:
        if getattr(before_user, user_key) is None:
          scratch_user_dict[user_key] = v

        # Set facebook email if it has not yet been set.
        if user_key == 'email' and ident_dict['authority'] == 'Facebook':
          if getattr(before_user, 'facebook_email') is None:
            scratch_user_dict['facebook_email'] = v

    # If the device id is not present, then allocate it now.
    if device_dict is not None and device_dict not in 'device_id':
      device_dict['device_id'] = yield gen.Task(Device._allocator.NextId, self._client)

    # Make synchronous request to ensure user is fully created before returning.
    request = {'headers': {'synchronous': True},
               'user_dict': scratch_user_dict,
               'ident_dict': ident_dict,
               'device_dict': device_dict}
    op = yield gen.Task(Operation.CreateAndExecute,
                        self._client,
                        user_dict['user_id'],
                        device_dict['device_id'] if device_dict is not None else before_user.webapp_dev_id,
                        'RegisterUserOperation.Execute',
                        request)

    if self._action == 'link':
      # Now make asynchronous request (or synchronous if requested by client) to fetch contacts.
      # Fetching contacts can take a long time, so best to do this in the background by default.
      request = {'key': ident_dict['key'],
                 'user_id': user_dict['user_id']}
      if self._IsInteractiveRequest() or self._request_message.dict['headers'].get('synchronous', False):
        request['headers'] = {'synchronous': True}

      op = yield gen.Task(Operation.CreateAndExecute,
                          self._client,
                          user_dict['user_id'],
                          device_dict['device_id'] if device_dict is not None else before_user.webapp_dev_id,
                          'FetchContactsOperation.Execute',
                          request)

    # Get the user that was registered by the operation.
    after_user = yield gen.Task(User.Query, self._client, user_dict['user_id'], None)

    # If the identity was confirmed via email/SMS, set the cookie "confirm_time", which allows
    # the cookie to authorize higher privilege operations, such as setting the user password.
    confirm_time = util.GetCurrentTimestamp() if confirmed else None

    # Create the user cookie dict that will be returned to the caller.
    device_id = after_user.webapp_dev_id if device_dict is None else device_dict['device_id']
    user_cookie_dict = self.CreateUserCookieDict(after_user.user_id,
                                                 device_id,
                                                 after_user.name,
                                                 confirm_time=confirm_time)

    # Sets the user cookie and finishes the request.
    if self._IsInteractiveRequest():
      self.SetUserCookie(user_cookie_dict)
      self._FinishInteractiveRequest()
    else:
      response_dict = {'user_id': user_dict['user_id']}
      if device_dict is not None:
        response_dict['device_id'] = device_dict['device_id']

      use_session_cookie = self._request_message.dict.get('use_session_cookie', None)
      util.SetIfNotNone(user_cookie_dict, 'is_session_cookie', use_session_cookie)

      self.SetUserCookie(user_cookie_dict)
      self._FinishJSONRequest(op, response_dict, json_schema.AUTH_RESPONSE)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/www/auth.py/AuthHandler._AuthUser/swapped operands of `not in`