user

Module user |
[hide private]
[frames] | no frames]

## Source Code for Module user

     1
     2  from baseObjects import User
     3  from c3errors import ConfigFileException
     4  from utils import getFirstData, elementType
     5  import md5, crypt
     6
     7 -class SimpleUser(User):
     8      simpleNodes = ["username", "password", "email", "address", "tel", "realName", "description", "passwordType"]
     9      username = ""
    10      password = ""
    11      email = ""
    12      address =""
    13      tel = ""
    14      realName = ""
    15      description = ""
    16      flags = {}
    17
    18      allFlags = {"c3r:administrator" : "Administrator flag. Inherits all others.",
    19                  "info:srw/operation/1/create" : "Create record within this store",
    20                  "info:srw/operation/1/replace" : "Replace existing record within store",
    21                  "info:srw/operation/1/delete" : "Delete existing record from store",
    22                  "info:srw/operation/1/metadata" : "Modify metadata of record within store",
    23                  "info:srw/operation/2/index" : "Run indexing process for this object",
    24                  "info:srw/operation/2/unindex" : "Run un-indexing process for this object",
    25                  "info:srw/operation/2/cluster" : "Run clustering process for this object",
    26                  "info:srw/operation/2/permissions" : "Permission to change permissions",
    27                  "info:srw/operation/2/search" : "Permission to search",
    28                  "info:srw/operation/2/retrieve" : "Permission to retrieve object",
    29                  "info:srw/operation/2/scan" : "Permission to scan",
    30                  "info:srw/operation/2/sort" : "Permission to sort result set",
    31                  "info:srw/operation/2/transform" : "Permission to transform record"
    32                  }
    33      # Plus c3fn:(functionName) for function on object
    34
    35      resultSetIds = []
    36
    37 -    def _handleConfigNode(self, session, node):
    38          if (node.localName in self.simpleNodes):
    39              setattr(self, node.localName, getFirstData(node))
    40          elif (node.localName == "flags"):
    41              # Extract Rights info
    42              # <flags> <flag> <object> <value> </flag> </flags>
    43              for c in node.childNodes:
    44                  if c.nodeType == elementType and c.localName == "flag":
    45                      obj = None
    46                      flag = None
    47                      for c2 in c.childNodes:
    48                          if c2.nodeType == elementType:
    49                              if c2.localName == "object":
    50                                  obj = getFirstData(c2)
    51                              elif c2.localName == "value":
    52                                  flag = getFirstData(c2)
    53                                  if not self.allFlags.has_key(flag) and flag[:4] != "c3fn":
    54                                      raise ConfigFileException("Unknown flag: %s" % flag)
    55                      if obj == None or flag == None:
    56                          raise ConfigFileException("Missing object or value element for flag for user %s" % self.username)
    57                      if (obj):
    58                          f = self.flags.get(flag, [])
    59                          if f != "":
    60                              f.append(obj)
    61                              self.flags[flag] = obj
    62                      else:
    63                          self.flags[flag] = ""
    64          elif (node.localName == "history"):
    65              # Extract user history
    66              pass
    67          elif (node.localName == "hostmask"):
    68              # Extract allowed hostmask list
    69              pass
    70
    71 -    def hasFlag(self, session, flag, object=""):
    72          # Does the user have the flag for this object/all objects
    73          f = self.flags.get(flag, [])
    74          if f == "c3r:administrator" or object in f:
    75              return True
    76          else:
    77              # Does the user have a global flag for this object/all objects
    78              f = self.flags.get("", [])
    79              if f == "c3r:administrator" or object in f:
    80                  return True
    81              return False
    82
    83 -    def check_password(self, session, password):
    84          # Check password type
    85          if self.passwordType == 'md5':
    86              m = md5.md5(password)
    87              return m.hexdigest() == self.password
    88          else:
    89              return crypt.crypt(password, self.password[:2]) == self.password
    90