Exemplo n.º 1
0
  def _late_init(self):  # pragma: no cover
    """Initializes access control fields once the object is setup."""

    def look_for_password():
      """Looks for password parameter. Not awesome."""
      password = self.request.get('password')
      if password:
        sha1_pass = hashlib.sha1(password).hexdigest()
        if Passwords.gql('WHERE password_sha1 = :1', sha1_pass).get():
          # The password is valid, this is a super admin.
          self._write_access = True
          self._read_access = True
          self._bot_login = True
        else:
          if utils.is_dev_env() and password == 'foobar':
            # Dev server is unsecure.
            self._read_access = True
            self._write_access = True
            self._bot_login = True
          else:
            logging.error('Password is invalid')

    self._user = users.get_current_user()
    if utils.is_dev_env():
      look_for_password()
      # Maybe the tests reloaded our public settings ...
      self.PUBLIC_ACCESS = GlobalConfig.all().get().public_access
    elif not self._user:
      try:
        self._user = oauth.get_current_user()
      except oauth.OAuthRequestError:
        if self.request.scheme == 'https':
          look_for_password()

    if not self._write_access and self._user:
      if self.PUBLIC_ACCESS:
        valid_email = self._VALID_PUBLIC_EMAIL
      else:
        valid_email = self._VALID_PRIVATE_EMAIL
      self._write_access = bool(
          users.is_current_user_admin() or
          valid_email.match(self._user.email()))
    if self.PUBLIC_ACCESS:
      self._read_access = True
    else:
      self._read_access = self._write_access

    self._initialized = True
    logging.info('ReadAccess: %r, WriteAccess: %r, BotLogin: %r, User: %s' % (
        self._read_access, self._write_access, self._bot_login, self._user))
Exemplo n.º 2
0
    def _late_init(self):  # pragma: no cover
        """Initializes access control fields once the object is setup."""
        def look_for_password():
            """Looks for password parameter. Not awesome."""
            password = self.request.get('password')
            if password:
                sha1_pass = hashlib.sha1(password).hexdigest()
                if Passwords.gql('WHERE password_sha1 = :1', sha1_pass).get():
                    # The password is valid, this is a super admin.
                    self._write_access = True
                    self._read_access = True
                    self._bot_login = True
                else:
                    if utils.is_dev_env() and password == 'foobar':
                        # Dev server is unsecure.
                        self._read_access = True
                        self._write_access = True
                        self._bot_login = True
                    else:
                        logging.error('Password is invalid')

        self._user = users.get_current_user()
        if utils.is_dev_env():
            look_for_password()
            # Maybe the tests reloaded our public settings ...
            self.PUBLIC_ACCESS = GlobalConfig.all().get().public_access
        elif not self._user:
            try:
                self._user = oauth.get_current_user()
            except oauth.OAuthRequestError:
                if self.request.scheme == 'https':
                    look_for_password()

        if not self._write_access and self._user:
            if self.PUBLIC_ACCESS:
                valid_email = self._VALID_PUBLIC_EMAIL
            else:
                valid_email = self._VALID_PRIVATE_EMAIL
            self._write_access = bool(users.is_current_user_admin()
                                      or valid_email.match(self._user.email()))
        if self.PUBLIC_ACCESS:
            self._read_access = True
        else:
            self._read_access = self._write_access

        self._initialized = True
        logging.info(
            'ReadAccess: %r, WriteAccess: %r, BotLogin: %r, User: %s' %
            (self._read_access, self._write_access, self._bot_login,
             self._user))
Exemplo n.º 3
0
 def look_for_password():
   """Looks for password parameter. Not awesome."""
   password = self.request.get('password')
   if password:
     sha1_pass = hashlib.sha1(password).hexdigest()
     if Passwords.gql('WHERE password_sha1 = :1', sha1_pass).get():
       # The password is valid, this is a super admin.
       self._write_access = True
       self._read_access = True
       self._bot_login = True
     else:
       if utils.is_dev_env() and password == 'foobar':
         # Dev server is unsecure.
         self._read_access = True
         self._write_access = True
         self._bot_login = True
       else:
         logging.error('Password is invalid')
Exemplo n.º 4
0
 def look_for_password():
     """Looks for password parameter. Not awesome."""
     password = self.request.get('password')
     if password:
         sha1_pass = hashlib.sha1(password).hexdigest()
         if Passwords.gql('WHERE password_sha1 = :1', sha1_pass).get():
             # The password is valid, this is a super admin.
             self._write_access = True
             self._read_access = True
             self._bot_login = True
         else:
             if utils.is_dev_env() and password == 'foobar':
                 # Dev server is unsecure.
                 self._read_access = True
                 self._write_access = True
                 self._bot_login = True
             else:
                 logging.error('Password is invalid')