Ejemplo n.º 1
0
    def new_f(self, domain):
      formok = True
      errors = []
      items = {}

      try:
        ParamChecker.checkDomain('domain')
      except InvalidParameterFormat as ipf:
        formok = False
        errors.append(ipf.message)

      if not formok:
        self.session['errors'] = errors
        self.session['reqparams'] = {}

        # @TODO request.params may contain multiple values per key... test & fix
        for k in self.request.params.iterkeys():
          self.session['reqparams'][k] = self.request.params[k]

        self.session.save()

        raise HTTPRedirect('/mails/editDomain')
      else:
        items['domain'] = domain

      return f(self, items)
Ejemplo n.º 2
0
    def validatePayment(self, member_id, idPayment):
        """ Validate a payment specified by an id """
        try:
            ParamChecker.checkUsername('member_id', param=True)
            ParamChecker.checkInt('idPayment', param=True)
        except:
            raise HTTPRedirect('/payments/index')

        try:
            np = self.db.query(Payment).filter(Payment.id == idPayment).one()

            if np.verified:
                np.verified = False
            else:
                np.verified = True
            self.request.db.commit()

            self.session['flash'] = _(
                'Payment validation successfully toggled')
            self.session['flash_class'] = 'success'
        except:
            self.session['flash'] = _('Saving payment failed')
            self.session['flash_class'] = 'error'

        self.session.save()

        raise HTTPRedirect(
            '/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 3
0
  def validatePayment(self, member_id, idPayment):
    """ Validate a payment specified by an id """
    try:
      ParamChecker.checkUsername('member_id', param=True)
      ParamChecker.checkInt('idPayment', param=True)
    except:
      raise HTTPRedirect('/payments/index')

    try:
      np = self.db.query(Payment).filter(Payment.id == idPayment).one()

      if np.verified:
        np.verified = False
      else:
        np.verified = True
      self.request.db.commit()

      self.session['flash'] = _('Payment validation successfully toggled')
      self.session['flash_class'] = 'success'
    except:
      self.session['flash'] = _('Saving payment failed')
      self.session['flash_class'] = 'error'

    self.session.save()

    raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 4
0
        def new_f(self, domain):
            formok = True
            errors = []
            items = {}

            try:
                ParamChecker.checkDomain("domain")
            except InvalidParameterFormat as ipf:
                formok = False
                errors.append(ipf.message)

            if not formok:
                self.session["errors"] = errors
                self.session["reqparams"] = {}

                # @TODO request.params may contain multiple values per key... test & fix
                for k in self.request.params.iterkeys():
                    self.session["reqparams"][k] = self.request.params[k]

                self.session.save()

                raise HTTPRedirect("/mails/editDomain")
            else:
                items["domain"] = domain

            return f(self, items)
Ejemplo n.º 5
0
    def editPayment(self, member_id, year=None, month=None, idPayment='0'):
        """ Add or edit a payment to/of a specific user """
        if not self.is_admin() and not member_id == self.session.get(
                'username'):
            raise HTTPError(403, 'Forbidden')

        c = TemplateContext()
        c.member_id = member_id
        c.status_0 = False
        c.status_1 = False
        c.status_2 = False

        # vary form depending on mode (do that over ajax)
        if idPayment == '0':
            c.payment = Payment()
            action = 'Adding'

            try:
                ParamChecker.checkYear('year', param=True)
                ParamChecker.checkMonth('month', param=True)
                c.date = str(datetime.date(int(year), int(month), 1))
            except:
                '''Don't care ... just let the user enter a new date'''
                pass

        elif not idPayment == '' and IsInt(idPayment) and int(idPayment) > 0:
            # @fixme convert IsInt to new class
            action = 'Editing'
            payment_q = self.db.query(Payment).filter(
                Payment.id == int(idPayment))
            try:
                payment = payment_q.one()

                # @TODO allow member editing if not verified???
                if payment.verified and not self.is_admin():
                    raise HTTPError(403, 'Forbidden')

                c.payment = payment
                setattr(c, 'status_' + str(payment.status), True)
            except NoResultFound:
                print "oops"
                raise HTTPRedirect('/members/index')
        else:
            raise HTTPRedirect('/members/index')

        c.heading = _('%s payment for user %s') % (action, c.member_id)
        self.sidebar.append({
            'name': _('List payments'),
            'args': {
                'controller': 'payments',
                'action': 'listPayments',
                'params': {
                    'member_id': member_id
                }
            }
        })

        return self.render('/payments/editPayment.mako', template_context=c)
Ejemplo n.º 6
0
  def listPayments(self, member_id=None, year=None):
    """ Show a specific user's payments """
    if member_id is None:
      if not self.is_admin() and not self.is_finance_admin():
        raise HTTPError(403, 'Forbidden')
      else:
        raise HTTPRedirect('/payments/showOutstanding/?showAll=1')
    elif not self.is_admin() and not self.is_finance_admin() and not member_id == self.session.get('username'):
      raise HTTPError(403, 'Forbidden')

    if not year is None:
      try:
        ParamChecker.checkInt('year', param=True, max_len=4)
        if int(year) > 1970 and int(year) < 2222:
          year = int(year)
        else:
          year = datetime.datetime.now().year
      except:
        pass

    if year is None:
      try:
        ParamChecker.checkUsername('member_id', param=True)
        year = self._getLastPayment(member_id).year
      except:
        pass

    if year is None:
      year = datetime.datetime.now().year

    c = TemplateContext()
    c.heading = _('Payments for the year {0}, user {1}'.format(year, member_id))
    c.member_id = member_id

    ## consider pagination
    # http://pylonsbook.com/en/1.1/starting-the-simplesite-tutorial.html#using-pagination
    try:
      #c.member.leavingDate = date(int(member.leavingDate[:4]),int(member.leavingDate[5:6]),int(member.leavingDate[7:8]))
      ## ideally, fetch monthly from member and the rest from payment (one to many relation)
      ## http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html

      y_start = datetime.date(year, 1, 1)
      y_end = datetime.date(year, 12, 31)
      payment_sql = self.db.query(Payment).filter(Payment.uid == member_id).filter(Payment.date.between(y_start, y_end)).order_by(Payment.date.desc()).all()

      payments = {}
      c.unverifiedPledges = 0
      for p in payment_sql:
        if p.verified == 0:
          c.unverifiedPledges += 1
        payments[p.date.month] = p

      c.year = year
      c.payments = payments

    except AttributeError, e:
      return 'This member has made no payments o.O ?!: %s' % e
Ejemplo n.º 7
0
        def new_f(self, member_id, **kwargs):
            # @TODO request.params may contain multiple values per key... test & fix
            formok = True
            errors = []

            try:
                ParamChecker.checkMode('mode', values=('add', 'edit'))
            except InvalidParameterFormat as ipf:
                formok = False
                errors.append(ipf.message)

            m = Member()

            for v in m.str_vars:
                setattr(m, v, self.request.params.get(v, ''))

            m.uid = member_id

            try:
                m.check()
            except InvalidParameterFormat as ipf:
                formok = False
                errors += ipf.message

            if self.request.params[
                    'mode'] == 'add' or not self.request.params.get(
                        'userPassword', '') == '':
                try:
                    ParamChecker.checkPassword('userPassword', 'userPassword2')
                except InvalidParameterFormat as ipf:
                    formok = False
                    errors.append(ipf.message)

            if not formok:
                self.session['errors'] = errors
                self.session['reqparams'] = {}

                # @TODO request.params may contain multiple values per key... test & fix
                for k in self.request.params.iterkeys():
                    if k == 'fullMember' or k == 'lockedMember':
                        if self.request.params[k] == 'on':
                            self.session['reqparams'][k] = True
                        else:
                            self.session['reqparams'][k] = False
                    else:
                        self.session['reqparams'][k] = self.request.params[k]

                self.session.save()

                if self.request.params['mode'] == 'add':
                    raise HTTPRedirect('/members/addMember')
                else:
                    raise HTTPRedirect(
                        '/members/editMember/?member_id={0}'.format(member_id))

            return f(self)
Ejemplo n.º 8
0
    def editAlias(self, alias=None, *args, **kwargs):
        c = TemplateContext()

        # vary form depending on mode (do that over ajax)
        if alias is None:
            action = "Adding"
            c.mode = "add"

            domains = self.mf.getDomains()
            c.select_domains = []
            for d in domains:
                c.select_domains.append([d.dc, d.dc])

        elif not alias == "":
            try:
                ParamChecker.checkEmail("alias")
            except:
                raise HTTPRedirect("/mails/index")

            action = "Editing"
            c.alias = alias
            c.mode = "edit"
            try:
                alias = self.mf.getAlias(alias)
                mail = ""

                for m in alias.mail:
                    if not mail == "":
                        mail += "\n"
                    if not m == alias.dn_mail:
                        mail += m

                c.mail = mail

                maildrop = ""

                for m in alias.maildrop:
                    if not maildrop == "":
                        maildrop += "\n"
                    if not m == alias.dn_mail and not m in maildrop:
                        maildrop += m

                c.maildrop = maildrop

            except LookupError:
                # @TODO implement better handler
                msg = _("No such alias!")
                return self.index(msg=msg)
        else:
            raise HTTPRedirect("/mails/index")

        c.heading = "{0} alias".format(action)

        return self.render("/mails/editAlias.mako", template_context=c)
Ejemplo n.º 9
0
  def bulkAdd(self, member_id):
    try:
      ParamChecker.checkUsername('member_id', param=True)
    except:
      raise HTTPRedirect('/payments/index')

    c = TemplateContext()
    c.member_id = member_id
    c.heading = _('Add bulk payments')

    return self.render('/payments/bulkAdd.mako', template_context=c)
Ejemplo n.º 10
0
    def bulkAdd(self, member_id):
        try:
            ParamChecker.checkUsername('member_id', param=True)
        except:
            raise HTTPRedirect('/payments/index')

        c = TemplateContext()
        c.member_id = member_id
        c.heading = _('Add bulk payments')

        return self.render('/payments/bulkAdd.mako', template_context=c)
Ejemplo n.º 11
0
  def editAlias(self, alias=None, *args, **kwargs):
    c = TemplateContext()

    # vary form depending on mode (do that over ajax)
    if alias is None:
      action = 'Adding'
      c.mode = 'add'

      domains = self.mf.getDomains()
      c.select_domains = []
      for d in domains:
        c.select_domains.append([d.dc, d.dc])

    elif not alias == '':
      try:
        ParamChecker.checkEmail('alias')
      except:
        raise HTTPRedirect('/mails/index')

      action = 'Editing'
      c.alias = alias
      c.mode = 'edit'
      try:
        alias = self.mf.getAlias(alias)
        mail = ''

        for m in alias.mail:
          if not mail == '':
            mail += '\n'
          if not m == alias.dn_mail:
            mail += m

        c.mail = mail

        maildrop = ''

        for m in alias.maildrop:
          if not maildrop == '':
            maildrop += '\n'
          if not m == alias.dn_mail and not m in maildrop:
            maildrop += m

        c.maildrop = maildrop

      except LookupError:
        # @TODO implement better handler
        msg = _('No such alias!')
        return self.index(msg=msg)
    else:
      raise HTTPRedirect('/mails/index')

    c.heading = '{0} alias'.format(action)

    return self.render('/mails/editAlias.mako', template_context=c)
Ejemplo n.º 12
0
    def listAliases(self, domain, *args, **kwargs):
        try:
            ParamChecker.checkDomain("domain", param=True)
        except:
            raise HTTPRedirect("/mails/index")

        c = TemplateContext()
        c.heading = _("Aliases for domain: %s") % (domain)
        c.domain = domain
        c.aliases = self.mf.getAliases(domain)

        return self.render("/mails/listAliases.mako", template_context=c)
Ejemplo n.º 13
0
    def new_f(self, member_id, **kwargs):
      # @TODO request.params may contain multiple values per key... test & fix
      formok = True
      errors = []

      try:
        ParamChecker.checkMode('mode', values=('add', 'edit'))
      except InvalidParameterFormat as ipf:
        formok = False
        errors.append(ipf.message)

      m = Member()

      for v in m.str_vars:
        setattr(m, v, self.request.params.get(v, ''))

      m.uid = member_id

      try:
        m.check()
      except InvalidParameterFormat as ipf:
        formok = False
        errors += ipf.message

      if self.request.params['mode'] == 'add' or not self.request.params.get('userPassword', '') == '':
        try:
          ParamChecker.checkPassword('userPassword', 'userPassword2')
        except InvalidParameterFormat as ipf:
          formok = False
          errors.append(ipf.message)

      if not formok:
        self.session['errors'] = errors
        self.session['reqparams'] = {}

        # @TODO request.params may contain multiple values per key... test & fix
        for k in self.request.params.iterkeys():
          if k == 'fullMember' or k == 'lockedMember':
            if self.request.params[k] == 'on':
              self.session['reqparams'][k] = True
            else:
              self.session['reqparams'][k] = False
          else:
            self.session['reqparams'][k] = self.request.params[k]

        self.session.save()

        if self.request.params['mode'] == 'add':
          raise HTTPRedirect('/members/addMember')
        else:
          raise HTTPRedirect('/members/editMember/?member_id={0}'.format(member_id))

      return f(self)
Ejemplo n.º 14
0
  def listAliases(self, domain, *args, **kwargs):
    try:
      ParamChecker.checkDomain('domain', param=True)
    except:
      raise HTTPRedirect('/mails/index')

    c = TemplateContext()
    c.heading = _('Aliases for domain: %s') % (domain)
    c.domain = domain
    c.aliases = self.mf.getAliases(domain)

    return self.render('/mails/listAliases.mako', template_context=c)
Ejemplo n.º 15
0
    def doLogin(self, username=None, password=None):
        try:
            ParamChecker.checkUsername('username', param=True)
            ParamChecker.checkPassword('password', 'password', param=True)
        except InvalidParameterFormat as ipf:
            return self.index(_('Invalid data'))

        try:
            ldap_connector = LdapConnector(username=username,
                                           password=password)
        except mematool.helpers.exceptions.InvalidCredentials:
            return self.index(_('Invalid credentials'))
        except mematool.helpers.exceptions.ServerError:
            return self.index(_('Server error, please retry later'))

        old_session_language = self.session.get('language', '')

        self.session.regenerate()
        self.session['username'] = username
        self.session['password'] = encodeAES(password)
        self.set_ldapcon(ldap_connector.get_connection())
        self.session['groups'] = self.mf.getUserGroupList(username)

        try:
            user = self.mf.getUser(self.session['username'])
        except:
            return self.index(_('Server error, please retry later'))

        self.session['user'] = user

        if self.is_admin():
            self.session[
                'pendingMemberValidations'] = self.pendingMemberValidations()

        uidNumber = user.uidNumber
        language = self.db.query(Preferences).filter(
            and_(Preferences.uidNumber == uidNumber,
                 Preferences.key == 'language')).one()

        if language.value in self.languages:
            self.session['language'] = language.value
        elif not old_session_language == '':
            self.session['language'] = old_session_language
        else:
            self.session['language'] = self.default_language

        log.info(username + ' logged in')

        if user.is_admin():
            raise HTTPRedirect('/members/index')
        else:
            raise HTTPRedirect('/profile/index')
Ejemplo n.º 16
0
  def doLogin(self, username=None, password=None):
    try:
      ParamChecker.checkUsername('username', param=True)
      ParamChecker.checkPassword('password', 'password', param=True)
    except InvalidParameterFormat as ipf:
      return self.index(_('Invalid data'))

    try:
      ldap_connector = LdapConnector(username=username, password=password)
    except mematool.helpers.exceptions.InvalidCredentials:
      return self.index(_('Invalid credentials'))
    except mematool.helpers.exceptions.ServerError:
      return self.index(_('Server error, please retry later'))

    old_session_language = self.session.get('language', '')

    self.session.regenerate()
    self.session['username'] = username
    self.session['password'] = encodeAES(password)
    self.set_ldapcon(ldap_connector.get_connection())
    self.session['groups'] = self.mf.getUserGroupList(username)

    try:
      user = self.mf.getUser(self.session['username'])
    except:
      return self.index(_('Server error, please retry later'))

    self.session['user'] = user

    if self.is_admin():
      self.session['pendingMemberValidations'] = self.pendingMemberValidations()

    uidNumber = user.uidNumber
    language = self.db.query(Preferences).filter(and_(Preferences.uidNumber == uidNumber, Preferences.key == 'language')).one()

    if language.value in self.languages:
      self.session['language'] = language.value
    elif not old_session_language == '':
      self.session['language'] = old_session_language
    else:
      self.session['language'] = self.default_language

    log.info(username + ' logged in')

    if user.is_admin():
      raise HTTPRedirect('/members/index')
    else:
      raise HTTPRedirect('/profile/index')
Ejemplo n.º 17
0
    def unmanageGroup(self, gid):
        try:
            ParamChecker.checkUsername('gid', param=True)
        except:
            raise HTTPRedirect('/groups/index')

        result = self.mf.unmanageGroup(gid)

        if result:
            msg = _('Group no longer managed')
            msg_class = 'success'
        else:
            msg = _('Failed to remove group from management!')
            msg_class = 'error'

        return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 18
0
  def unmanageGroup(self, gid):
    try:
      ParamChecker.checkUsername('gid', param=True)
    except:
      raise HTTPRedirect('/groups/index')

    result = self.mf.unmanageGroup(gid)

    if result:
      msg = _('Group no longer managed')
      msg_class = 'success'
    else:
      msg = _('Failed to remove group from management!')
      msg_class = 'error'

    return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 19
0
  def deleteGroup(self, gid):
    try:
      ParamChecker.checkUsername('gid', param=True)
    except:
      raise HTTPRedirect('/groups/index')

    result = self.mf.deleteGroup(request.params['gid'])

    if result:
      msg = _('Group successfully deleted')
      msg_class = 'success'
    else:
      msg = _('Failed to delete group!')
      msg_class = 'error'

    return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 20
0
    def deleteGroup(self, gid):
        try:
            ParamChecker.checkUsername('gid', param=True)
        except:
            raise HTTPRedirect('/groups/index')

        result = self.mf.deleteGroup(request.params['gid'])

        if result:
            msg = _('Group successfully deleted')
            msg_class = 'success'
        else:
            msg = _('Failed to delete group!')
            msg_class = 'error'

        return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 21
0
  def editPayment(self, member_id, year=None, month=None, idPayment='0'):
    """ Add or edit a payment to/of a specific user """
    if not self.is_admin() and not member_id == self.session.get('username'):
      raise HTTPError(403, 'Forbidden')

    c = TemplateContext()
    c.member_id = member_id
    c.status_0 = False
    c.status_1 = False
    c.status_2 = False

    # vary form depending on mode (do that over ajax)
    if idPayment == '0':
      c.payment = Payment()
      action = 'Adding'

      try:
        ParamChecker.checkYear('year', param=True)
        ParamChecker.checkMonth('month', param=True)
        c.date = str(datetime.date(int(year), int(month), 1))
      except:
        '''Don't care ... just let the user enter a new date'''
        pass

    elif not idPayment == '' and IsInt(idPayment) and int(idPayment) > 0:
      # @fixme convert IsInt to new class
      action = 'Editing'
      payment_q = self.db.query(Payment).filter(Payment.id == int(idPayment))
      try:
        payment = payment_q.one()

        # @TODO allow member editing if not verified???
        if payment.verified and not self.is_admin():
          raise HTTPError(403, 'Forbidden')

        c.payment = payment
        setattr(c, 'status_' + str(payment.status), True)
      except NoResultFound:
        print "oops"
        raise HTTPRedirect('/members/index')
    else:
      raise HTTPRedirect('/members/index')

    c.heading = _('%s payment for user %s') % (action, c.member_id)
    self.sidebar.append({'name': _('List payments'), 'args': {'controller': 'payments', 'action': 'listPayments', 'params': {'member_id': member_id}}})

    return self.render('/payments/editPayment.mako', template_context=c)
Ejemplo n.º 22
0
  def deletePayment(self, member_id, idPayment):
    """ Delete a payment specified by an id """
    try:
      ParamChecker.checkUsername('member_id', param=True)
      ParamChecker.checkInt('idPayment', param=True)
    except:
      raise HTTPRedirect('/members/index')

    try:
      np = self.db.query(Payment).filter(Payment.id == idPayment).one()
      self.db.delete(np)
      self.db.commit()
    except:
      ''' Don't care '''
      pass

    raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 23
0
    def deletePayment(self, member_id, idPayment):
        """ Delete a payment specified by an id """
        try:
            ParamChecker.checkUsername('member_id', param=True)
            ParamChecker.checkInt('idPayment', param=True)
        except:
            raise HTTPRedirect('/members/index')

        try:
            np = self.db.query(Payment).filter(Payment.id == idPayment).one()
            self.db.delete(np)
            self.db.commit()
        except:
            ''' Don't care '''
            pass

        raise HTTPRedirect(
            '/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 24
0
    def new_f(self, gid, users=None):
      formok = True
      errors = []
      items = {}

      try:
        ParamChecker.checkUsername('gid', param=True)
      except:
        formok = False
        errors.append(_('Invalid group ID'))

      items['users'] = []

      if not users is None:
        try:
          #ParamChecker.checkString('users', param=True, min_len=-1, max_len=9999, regex=r'([\w]{1,20}\n?)*')

          for k in users.split('\n'):
            m = k.replace('\r', '').replace(' ', '')
            if m == '':
              continue
            else:
              ParamChecker.checkUsername(m, param=False)
              items['users'].append(m)
        except InvalidParameterFormat as ipf:
          formok = False
          errors.append(_('Invalid user name(s)'))

      if not formok:
        self.session['errors'] = errors
        self.session['reqparams'] = {}

        # @TODO request.params may contain multiple values per key... test & fix
        for k in self.request.params.iterkeys():
          self.session['reqparams'][k] = cherrypy.request.params[k]

        self.session.save()

        raise HTTPRedirect('/groups/editGroup/?gid={0}'.format(gid))
      else:
        items['gid'] = gid

      return f(self, items)
Ejemplo n.º 25
0
        def new_f(self, gid, users=None):
            formok = True
            errors = []
            items = {}

            try:
                ParamChecker.checkUsername('gid', param=True)
            except:
                formok = False
                errors.append(_('Invalid group ID'))

            items['users'] = []

            if not users is None:
                try:
                    #ParamChecker.checkString('users', param=True, min_len=-1, max_len=9999, regex=r'([\w]{1,20}\n?)*')

                    for k in users.split('\n'):
                        m = k.replace('\r', '').replace(' ', '')
                        if m == '':
                            continue
                        else:
                            ParamChecker.checkUsername(m, param=False)
                            items['users'].append(m)
                except InvalidParameterFormat as ipf:
                    formok = False
                    errors.append(_('Invalid user name(s)'))

            if not formok:
                self.session['errors'] = errors
                self.session['reqparams'] = {}

                # @TODO request.params may contain multiple values per key... test & fix
                for k in self.request.params.iterkeys():
                    self.session['reqparams'][k] = cherrypy.request.params[k]

                self.session.save()

                raise HTTPRedirect('/groups/editGroup/?gid={0}'.format(gid))
            else:
                items['gid'] = gid

            return f(self, items)
Ejemplo n.º 26
0
        def new_f(self, **kwargs):
            # @TODO request.params may contain multiple values per key... test & fix
            formok = True
            errors = []

            m = self.mf.getUser(self.session.get('username'))

            for v in m.str_vars:
                if v in self.request.params:
                    setattr(m, v, self.request.params.get(v, ''))

            try:
                m.check()
            except InvalidParameterFormat as ipf:
                formok = False
                errors += ipf.message

            if not self.request.params.get(
                    'userPassword', ''
            ) == '' and self.request.params[
                    'userPassword'] == self.request.params['userPassword2']:
                try:
                    ParamChecker.checkPassword('userPassword', 'userPassword2')
                except InvalidParameterFormat as ipf:
                    formok = False
                    errors.append(ipf.message)

            if not formok:
                self.session['errors'] = errors
                self.session['reqparams'] = {}

                # @TODO request.params may contain multiple values per key... test & fix
                for k in self.request.params.iterkeys():
                    self.session['reqparams'][k] = self.request.params[k]

                self.session.save()

                raise HTTPRedirect('/profile/edit')

            return f(self)
Ejemplo n.º 27
0
  def deleteAlias(self, alias, *args, **kwargs):
    try:
      ParamChecker.checkEmail('alias', param=True)
    except:
      raise HTTPRedirect('/mails/index')

    try:
      result = self.mf.deleteAlias(alias)

      if result:
        msg = _('Alias successfully deleted')
        msg_class = 'success'
      else:
        msg = _('Failed to delete alias!')
        msg_class = 'error'
    except:
      import sys, traceback
      traceback.print_exc(file=sys.stdout)
      msg = _('Failed to delete alias!')
      msg_class = 'error'

    return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 28
0
    def deleteAlias(self, alias, *args, **kwargs):
        try:
            ParamChecker.checkEmail("alias", param=True)
        except:
            raise HTTPRedirect("/mails/index")

        try:
            result = self.mf.deleteAlias(alias)

            if result:
                msg = _("Alias successfully deleted")
                msg_class = "success"
            else:
                msg = _("Failed to delete alias!")
                msg_class = "error"
        except:
            import sys, traceback

            traceback.print_exc(file=sys.stdout)
            msg = _("Failed to delete alias!")
            msg_class = "error"

        return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 29
0
    def deleteDomain(self, domain):
        return "HARD disabled ... you do not want to mess with this in production!!!"

        try:
            ParamChecker.checkDomain("domain", param=True)
        except:
            raise HTTPRedirect("/mails/index")

        try:
            result = self.mf.deleteDomain(domain)

            if result:
                msg = _("Domain successfully deleted")
                msg_class = "success"
            else:
                msg = _("Failed to delete domain!")
                msg_class = "error"
        except:
            msg = _("Failed to delete domain!")
            msg_class = "error"

        self.session.save()
        return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 30
0
    def editDomain(self, domain=None):
        c = TemplateContext()
        # vary form depending on mode (do that over ajax)
        if domain is None:
            action = "Adding"
            c.mode = "add"
        else:
            try:
                ParamChecker.checkDomain("domain")
            except:
                return self.index()

            action = "Editing"
            c.mode = "edit"
            try:
                c.domain = self.mf.getDomain(domain)
            except LookupError:
                msg = _("No such domain!")
                return self.index(msg=msg)

        c.heading = "%s domain" % (action)

        return self.render("/mails/editDomain.mako", template_context=c)
Ejemplo n.º 31
0
  def editDomain(self, domain=None):
    c = TemplateContext()
    # vary form depending on mode (do that over ajax)
    if domain is None:
      action = 'Adding'
      c.mode = 'add'
    else:
      try:
        ParamChecker.checkDomain('domain')
      except:
        return self.index()

      action = 'Editing'
      c.mode = 'edit'
      try:
        c.domain = self.mf.getDomain(domain)
      except LookupError:
        msg = _('No such domain!')
        return self.index(msg=msg)

    c.heading = '%s domain' % (action)

    return self.render('/mails/editDomain.mako', template_context=c)
Ejemplo n.º 32
0
  def deleteDomain(self, domain):
    return 'HARD disabled ... you do not want to mess with this in production!!!'

    try:
      ParamChecker.checkDomain('domain', param=True)
    except:
      raise HTTPRedirect('/mails/index')

    try:
      result = self.mf.deleteDomain(domain)

      if result:
        msg = _('Domain successfully deleted')
        msg_class = 'success'
      else:
        msg = _('Failed to delete domain!')
        msg_class = 'error'
    except:
      msg = _('Failed to delete domain!')
      msg_class = 'error'

    self.session.save()
    return self.index(msg=msg, msg_class=msg_class)
Ejemplo n.º 33
0
        def new_f(self, language):
            # @TODO request.params may contain multiple values per key... test & fix
            formok = True
            errors = []

            try:
                ParamChecker.checkString('language', min_len=2, max_len=2)
            except InvalidParameterFormat:
                errors.append(_('Invalid language'))

            if not formok:
                self.session['errors'] = errors
                self.session['reqparams'] = {}

                # @TODO request.params may contain multiple values per key... test & fix
                for k in self.request.params.iterkeys():
                    self.session['reqparams'][k] = self.request.params[k]

                self.session.save()

                raise HTTPRedirect('/preferences/edit')

            return f(self)
Ejemplo n.º 34
0
    def new_f(self, language):
      # @TODO request.params may contain multiple values per key... test & fix
      formok = True
      errors = []

      try:
        ParamChecker.checkString('language', min_len=2, max_len=2)
      except InvalidParameterFormat:
        errors.append(_('Invalid language'))

      if not formok:
        self.session['errors'] = errors
        self.session['reqparams'] = {}

        # @TODO request.params may contain multiple values per key... test & fix
        for k in self.request.params.iterkeys():
          self.session['reqparams'][k] = self.request.params[k]

        self.session.save()

        raise HTTPRedirect('/preferences/edit')

      return f(self)
Ejemplo n.º 35
0
    def new_f(self, **kwargs):
      # @TODO request.params may contain multiple values per key... test & fix
      formok = True
      errors = []

      m = self.mf.getUser(self.session.get('username'))

      for v in m.str_vars:
        if v in self.request.params:
          setattr(m, v, self.request.params.get(v, ''))

      try:
        m.check()
      except InvalidParameterFormat as ipf:
        formok = False
        errors += ipf.message

      if not self.request.params.get('userPassword', '') == '' and self.request.params['userPassword'] == self.request.params['userPassword2']:
        try:
          ParamChecker.checkPassword('userPassword', 'userPassword2')
        except InvalidParameterFormat as ipf:
          formok = False
          errors.append(ipf.message)

      if not formok:
        self.session['errors'] = errors
        self.session['reqparams'] = {}

        # @TODO request.params may contain multiple values per key... test & fix
        for k in self.request.params.iterkeys():
          self.session['reqparams'][k] = self.request.params[k]

        self.session.save()

        raise HTTPRedirect('/profile/edit')

      return f(self)
Ejemplo n.º 36
0
    def savePayment(self, member_id, items):
        """ Save a new or edited payment """
        verified = False

        if self.is_finance_admin() and ParamChecker.checkInt(
                'verified', param=True, optional=True):
            verified = True

        if items['idPayment'] > 0:
            try:
                np = self.db.query(Payment).filter(
                    Payment.id == items['idPayment']).one()
                np.verified = verified
            except:
                self.session['flash'] = _('Invalid record')
                self.session.save()
                raise HTTPRedirect(
                    '/payments/listPayments/?member_id={0}'.format(member_id))
        else:
            np = Payment()
            np.verified = verified
            np.status = 0

        for key, value in items.iteritems():
            setattr(np, key, value)

        try:
            np.uid = member_id
        except:
            self.session['flash'] = _('Invalid member')
            self.session.save()
            raise HTTPRedirect(
                '/payments/listPayments/?member_id={0}'.format(member_id))

        # Cleanup session
        if 'reqparams' in self.session:
            del (self.session['reqparams'])
        self.session.save()
        ##########

        self.db.add(np)
        self.db.commit()

        self.session['flash'] = _('Payment saved successfully.')
        self.session['flash_class'] = 'success'
        self.session.save()

        raise HTTPRedirect(
            '/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 37
0
  def editGroup(self, gid=None):
    c = TemplateContext()

    # vary form depending on mode (do that over ajax)
    if gid is None:
      c.group = Group()
      action = 'Adding'
      c.gid = ''
    else:
      try:
        ParamChecker.checkUsername('gid', param=True)
      except:
        msg =  _('Invalid format!')
        return self.index(msg=msg)

      action = 'Editing'
      c.gid = gid
      try:
        c.group = self.mf.getGroup(gid)
        print 'poll'
        users = ''

        for u in c.group.users:
          if not users == '':
            users += '\n'
          users += u

        c.group.users = users
      except LookupError:
        # @TODO implement better handler
        msg =  _('No such group!')
        return self.index(msg=msg)

    c.heading = '{0} group'.format(action)

    return self.render('/groups/editGroup.mako', template_context=c)
Ejemplo n.º 38
0
    def editGroup(self, gid=None):
        c = TemplateContext()

        # vary form depending on mode (do that over ajax)
        if gid is None:
            c.group = Group()
            action = 'Adding'
            c.gid = ''
        else:
            try:
                ParamChecker.checkUsername('gid', param=True)
            except:
                msg = _('Invalid format!')
                return self.index(msg=msg)

            action = 'Editing'
            c.gid = gid
            try:
                c.group = self.mf.getGroup(gid)
                print 'poll'
                users = ''

                for u in c.group.users:
                    if not users == '':
                        users += '\n'
                    users += u

                c.group.users = users
            except LookupError:
                # @TODO implement better handler
                msg = _('No such group!')
                return self.index(msg=msg)

        c.heading = '{0} group'.format(action)

        return self.render('/groups/editGroup.mako', template_context=c)
Ejemplo n.º 39
0
    def new_f(self, member_id, idPayment, date, status):
      # @TODO request.params may contain multiple values per key... test & fix
      if not self.is_admin() and not member_id == self.session.get('username') or (member_id == self.session.get('username') and ParamChecker.checkInt('idPayment', param=True, optional=True)):
        print 'checkPayment err0r::', str(self.isAdmin()), str(member_id), str(self.session.get('username')), str(ParamChecker.checkInt('idPayment', param=True, optional=True))
        raise HTTPError(403, 'Forbidden')
      else:
        formok = True
        errors = []
        items = {}
        d = None

        try:
          ParamChecker.checkDate('date', param=True)
          d = parser.parse(date)
          d = datetime.date(d.year, d.month, 1)
        except Exception as e:
          print e
          formok = False
          errors.append(_('Invalid date'))

        try:
          ParamChecker.checkInt('status', param=True)
          items['status'] = int(status)
        except:
          formok = False
          errors.append(_('Invalid payment status'))

        try:
          ParamChecker.checkInt('idPayment', param=True)
          items['idPayment'] = int(idPayment)
        except:
          items['idPayment'] = 0

        if not d is None and items['idPayment'] == 0:
          p_count = self.db.query(Payment).filter(Payment.uid == member_id).filter(Payment.date == d).count()

          if p_count > 0:
            formok = False
            errors.append(_('That month is already on records!'))

        if not formok:
          self.session['errors'] = errors
          self.session['reqparams'] = {}

          # @TODO request.params may contain multiple values per key... test & fix
          for k in self.request.params.iterkeys():
            self.session['reqparams'][k] = self.request.params[k]

          self.session.save()

          raise HTTPRedirect('/payments/editPayment/?member_id={0}&idPayment={1}'.format(member_id, items['idPayment']))
        else:
          items['date'] = d

      return f(self, member_id, items)
Ejemplo n.º 40
0
  def savePayment(self, member_id, items):
    """ Save a new or edited payment """
    verified = False

    if self.is_finance_admin() and ParamChecker.checkInt('verified', param=True, optional=True):
      verified = True

    if items['idPayment'] > 0:
      try:
        np = self.db.query(Payment).filter(Payment.id == items['idPayment']).one()
        np.verified = verified
      except:
        self.session['flash'] = _('Invalid record')
        self.session.save()
        raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
    else:
      np = Payment()
      np.verified = verified
      np.status = 0

    for key, value in items.iteritems():
      setattr(np, key, value)

    try:
      np.uid = member_id
    except:
      self.session['flash'] = _('Invalid member')
      self.session.save()
      raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))

    # Cleanup session
    if 'reqparams' in self.session:
      del(self.session['reqparams'])
    self.session.save()
    ##########

    self.db.add(np)
    self.db.commit()

    self.session['flash'] = _('Payment saved successfully.')
    self.session['flash_class'] = 'success'
    self.session.save()

    raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 41
0
    def doBulkAdd(self, member_id, months, verified=None):
        try:
            ParamChecker.checkUsername('member_id', param=True)
            ParamChecker.checkInt('months', param=True, max_len=2)
        except:
            raise HTTPRedirect('/payments/index')

        lastDate = self._getLastPayment(member_id)
        months = int(months)

        if self.is_finance_admin():
            try:
                ParamChecker.checkInt('verified', param=True, max_len=1)
                verified = True
            except:
                verified = False

        try:
            for i in range(months):
                p = Payment()
                p.uid = member_id
                p.date = lastDate + relativedelta(months=i)
                p.status = 0
                p.verified = verified

                self.db.add(p)

            self.db.commit()

            self.session['flash'] = _('Payments added')
            self.session['flash_class'] = 'success'
        except Exception as e:
            self.session['flash'] = _('Operation failed')
            self.session['flash_class'] = 'error'

        self.session.save()

        raise HTTPRedirect(
            '/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 42
0
  def doBulkAdd(self, member_id, months, verified=None):
    try:
      ParamChecker.checkUsername('member_id', param=True)
      ParamChecker.checkInt('months', param=True, max_len=2)
    except:
      raise HTTPRedirect('/payments/index')

    lastDate = self._getLastPayment(member_id)
    months = int(months)

    if self.is_finance_admin():
      try:
        ParamChecker.checkInt('verified', param=True, max_len=1)
        verified = True
      except:
        verified = False

    try:
      for i in range(months):
        p = Payment()
        p.uid = member_id
        p.date = lastDate + relativedelta(months=i)
        p.status = 0
        p.verified = verified

        self.db.add(p)

      self.db.commit()

      self.session['flash'] = _('Payments added')
      self.session['flash_class'] = 'success'
    except Exception as e:
      self.session['flash'] = _('Operation failed')
      self.session['flash_class'] = 'error'

    self.session.save()

    raise HTTPRedirect('/payments/listPayments/?member_id={0}'.format(member_id))
Ejemplo n.º 43
0
    def check(self):
        errors = []
        checkOK = True

        try:
            ParamChecker.checkUsername(self.uid, param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid username'))

        try:
            ParamChecker.checkString(self.sn,
                                     min_len=0,
                                     max_len=20,
                                     param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid surname'))

        try:
            ParamChecker.checkString(self.givenName,
                                     min_len=0,
                                     max_len=20,
                                     param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid given name'))

        try:
            ParamChecker.checkString(self.homePostalAddress,
                                     min_len=0,
                                     max_len=255,
                                     param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid address'))
        '''optional'''
        try:
            ParamChecker.checkBool(self.isMinor, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid selection for "is minor"'))
        '''optional'''
        try:
            ParamChecker.checkPhone(self.homePhone, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(ipf.message)
        '''optional'''
        try:
            ParamChecker.checkPhone(self.mobile, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid mobile number'))

        try:
            ParamChecker.checkEmail(self.mail, param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(ipf.message)

        try:
            ParamChecker.checkString(self.loginShell,
                                     min_len=0,
                                     max_len=20,
                                     regex=regex.loginShell,
                                     param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid login shell'))

        try:
            ParamChecker.checkDate(self.arrivalDate, param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid "member since" date'))
        '''optional'''
        try:
            ParamChecker.checkDate(self.leavingDate,
                                   param=False,
                                   optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid "membership canceled" date'))
        '''optional'''
        try:
            ParamChecker.checkString(self.sshPublicKey,
                                     min_len=0,
                                     max_len=1200,
                                     regex=regex.sshKey,
                                     param=False,
                                     optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid SSH key'))
        '''optional'''
        try:
            ParamChecker.checkPGP(self.pgpKey, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(ipf.message)
        '''optional'''
        try:
            ParamChecker.checkiButtonUID(self.iButtonUID,
                                         param=False,
                                         optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(ipf.message)

        try:
            ParamChecker.checkUsername(self.conventionSigner, param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid convention signer'))
        '''optional'''
        try:
            ParamChecker.checkEmail(self.xmppID, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid XMPP/Jabber/GTalk ID'))
        '''optional'''
        try:
            ParamChecker.checkBool(self.spaceKey, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid Space-Key value'))
        '''optional'''
        try:
            ParamChecker.checkBool(self.npoMember, param=False, optional=True)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid NPO-Member value'))

        try:
            ParamChecker.checkCountryCode(self.nationality, param=False)
        except InvalidParameterFormat as ipf:
            checkOK = False
            errors.append(_('Invalid nationality'))

        if checkOK:
            return checkOK

        raise InvalidParameterFormat(errors)
Ejemplo n.º 44
0
    def listPayments(self, member_id=None, year=None):
        """ Show a specific user's payments """
        if member_id is None:
            if not self.is_admin() and not self.is_finance_admin():
                raise HTTPError(403, 'Forbidden')
            else:
                raise HTTPRedirect('/payments/showOutstanding/?showAll=1')
        elif not self.is_admin() and not self.is_finance_admin(
        ) and not member_id == self.session.get('username'):
            raise HTTPError(403, 'Forbidden')

        if not year is None:
            try:
                ParamChecker.checkInt('year', param=True, max_len=4)
                if int(year) > 1970 and int(year) < 2222:
                    year = int(year)
                else:
                    year = datetime.datetime.now().year
            except:
                pass

        if year is None:
            try:
                ParamChecker.checkUsername('member_id', param=True)
                year = self._getLastPayment(member_id).year
            except:
                pass

        if year is None:
            year = datetime.datetime.now().year

        c = TemplateContext()
        c.heading = _('Payments for the year {0}, user {1}'.format(
            year, member_id))
        c.member_id = member_id

        ## consider pagination
        # http://pylonsbook.com/en/1.1/starting-the-simplesite-tutorial.html#using-pagination
        try:
            #c.member.leavingDate = date(int(member.leavingDate[:4]),int(member.leavingDate[5:6]),int(member.leavingDate[7:8]))
            ## ideally, fetch monthly from member and the rest from payment (one to many relation)
            ## http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html

            y_start = datetime.date(year, 1, 1)
            y_end = datetime.date(year, 12, 31)
            payment_sql = self.db.query(Payment).filter(
                Payment.uid == member_id).filter(
                    Payment.date.between(y_start, y_end)).order_by(
                        Payment.date.desc()).all()

            payments = {}
            c.unverifiedPledges = 0
            for p in payment_sql:
                if p.verified == 0:
                    c.unverifiedPledges += 1
                payments[p.date.month] = p

            c.year = year
            c.payments = payments

        except AttributeError, e:
            return 'This member has made no payments o.O ?!: %s' % e
Ejemplo n.º 45
0
        def new_f(self, member_id, idPayment, date, status):
            # @TODO request.params may contain multiple values per key... test & fix
            if not self.is_admin() and not member_id == self.session.get(
                    'username') or (member_id == self.session.get('username')
                                    and ParamChecker.checkInt('idPayment',
                                                              param=True,
                                                              optional=True)):
                print 'checkPayment err0r::', str(
                    self.isAdmin()), str(member_id), str(
                        self.session.get('username')), str(
                            ParamChecker.checkInt('idPayment',
                                                  param=True,
                                                  optional=True))
                raise HTTPError(403, 'Forbidden')
            else:
                formok = True
                errors = []
                items = {}
                d = None

                try:
                    ParamChecker.checkDate('date', param=True)
                    d = parser.parse(date)
                    d = datetime.date(d.year, d.month, 1)
                except Exception as e:
                    print e
                    formok = False
                    errors.append(_('Invalid date'))

                try:
                    ParamChecker.checkInt('status', param=True)
                    items['status'] = int(status)
                except:
                    formok = False
                    errors.append(_('Invalid payment status'))

                try:
                    ParamChecker.checkInt('idPayment', param=True)
                    items['idPayment'] = int(idPayment)
                except:
                    items['idPayment'] = 0

                if not d is None and items['idPayment'] == 0:
                    p_count = self.db.query(Payment).filter(
                        Payment.uid == member_id).filter(
                            Payment.date == d).count()

                    if p_count > 0:
                        formok = False
                        errors.append(_('That month is already on records!'))

                if not formok:
                    self.session['errors'] = errors
                    self.session['reqparams'] = {}

                    # @TODO request.params may contain multiple values per key... test & fix
                    for k in self.request.params.iterkeys():
                        self.session['reqparams'][k] = self.request.params[k]

                    self.session.save()

                    raise HTTPRedirect(
                        '/payments/editPayment/?member_id={0}&idPayment={1}'.
                        format(member_id, items['idPayment']))
                else:
                    items['date'] = d

            return f(self, member_id, items)
Ejemplo n.º 46
0
        def new_f(self, mode, alias, domain, mail=None, maildrop=None):
            formok = True
            errors = []
            items = {}

            if not mode in ["add", "edit"]:
                raise HTTPRedirect("/mails/index")

            if mode == "add":
                try:
                    ParamChecker.checkDomain("domain")
                except InvalidParameterFormat as ipf:
                    formok = False
                    errors.append(ipf.message)

                alias += "@" + domain

            domain = alias.split("@")[1]

            try:
                ParamChecker.checkDomain(domain, param=False)
            except InvalidParameterFormat as ipf:
                formok = False
                errors.append(ipf.message)

            # @TODO improve check
            try:
                ParamChecker.checkString("maildrop", min_len=0, max_len=300)
            except InvalidParameterFormat as ipf:
                formok = False
                errors.append(_("Invalid mail destination!"))

            if mail and not mail == "":
                for k in mail.split("\n"):
                    m = k.replace("\r", "").replace(" ", "")
                    if m == "":
                        continue

                    try:
                        ParamChecker.checkEmail(m, param=False)
                    except:
                        formok = False
                        break

                    m_domain = m.split("@")[1]
                    if not m_domain == domain:
                        formok = False
                        errors.append(_("All aliases need to be within the same domain!"))
                        break

                if len(mail) > 300:
                    formok = False

                if not formok:
                    errors.append(_("Invalid related aliases!"))

            if not formok:
                self.session["errors"] = errors
                self.session["reqparams"] = {}

                # @TODO request.params may contain multiple values per key... test & fix
                for k in cherrypy.request.params.iterkeys():
                    self.session["reqparams"][k] = cherrypy.request.params[k]

                self.session.save()

                if mode == "edit":
                    raise HTTPRedirect("/mails/editAlias/?alias={0}".format(alias))
                else:
                    raise HTTPRedirect("/mails/editAlias")
            else:
                items["mode"] = mode
                items["alias"] = alias
                items["mail"] = []
                items["maildrop"] = []

                if mail and len(mail) > 0:
                    for k in mail.split("\n"):
                        m = k.replace("\r", "").replace(" ", "")
                        if m == "":
                            continue

                        items["mail"].append(m)

                if maildrop and len(maildrop) > 0:
                    for k in maildrop.split("\n"):
                        m = k.replace("\r", "").replace(" ", "")
                        if m == "":
                            continue

                        items["maildrop"].append(m)

            return f(self, items)
Ejemplo n.º 47
0
  def check(self):
    errors = []
    checkOK = True

    try:
      ParamChecker.checkUsername(self.uid, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid username'))

    try:
      ParamChecker.checkString(self.sn, min_len=0, max_len=20, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid surname'))

    try:
      ParamChecker.checkString(self.givenName, min_len=0, max_len=20, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid given name'))

    try:
      ParamChecker.checkString(self.homePostalAddress, min_len=0, max_len=255, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid address'))

    '''optional'''
    try:
      ParamChecker.checkBool(self.isMinor, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid selection for "is minor"'))

    '''optional'''
    try:
      ParamChecker.checkPhone(self.homePhone, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(ipf.message)

    '''optional'''
    try:
      ParamChecker.checkPhone(self.mobile, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid mobile number'))

    try:
      ParamChecker.checkEmail(self.mail, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(ipf.message)

    try:
      ParamChecker.checkString(self.loginShell, min_len=0, max_len=20, regex=regex.loginShell, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid login shell'))

    try:
      ParamChecker.checkDate(self.arrivalDate, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid "member since" date'))

    '''optional'''
    try:
      ParamChecker.checkDate(self.leavingDate, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid "membership canceled" date'))

    '''optional'''
    try:
      ParamChecker.checkString(self.sshPublicKey, min_len=0, max_len=1200, regex=regex.sshKey, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid SSH key'))

    '''optional'''
    try:
      ParamChecker.checkPGP(self.pgpKey, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(ipf.message)

    '''optional'''
    try:
      ParamChecker.checkiButtonUID(self.iButtonUID, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(ipf.message)

    try:
      ParamChecker.checkUsername(self.conventionSigner, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid convention signer'))

    '''optional'''
    try:
      ParamChecker.checkEmail(self.xmppID, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid XMPP/Jabber/GTalk ID'))

    '''optional'''
    try:
      ParamChecker.checkBool(self.spaceKey, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid Space-Key value'))

    '''optional'''
    try:
      ParamChecker.checkBool(self.npoMember, param=False, optional=True)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid NPO-Member value'))

    try:
      ParamChecker.checkCountryCode(self.nationality, param=False)
    except InvalidParameterFormat as ipf:
      checkOK = False
      errors.append(_('Invalid nationality'))

    if checkOK:
      return checkOK

    raise InvalidParameterFormat(errors)
Ejemplo n.º 48
0
    def new_f(self, mode, alias, domain, mail=None, maildrop=None):
      formok = True
      errors = []
      items = {}

      if not mode in ['add', 'edit']:
        raise HTTPRedirect('/mails/index')

      if mode == 'add':
        try:
          ParamChecker.checkDomain('domain')
        except InvalidParameterFormat as ipf:
          formok = False
          errors.append(ipf.message)

        alias += '@' + domain

      domain = alias.split('@')[1]

      try:
        ParamChecker.checkDomain(domain, param=False)
      except InvalidParameterFormat as ipf:
        formok = False
        errors.append(ipf.message)

      # @TODO improve check
      try:
        ParamChecker.checkString('maildrop', min_len=0, max_len=300)
      except InvalidParameterFormat as ipf:
        formok = False
        errors.append(_('Invalid mail destination!'))

      if mail and not mail == '':
        for k in mail.split('\n'):
          m = k.replace('\r', '').replace(' ', '')
          if m == '':
            continue

          try:
            ParamChecker.checkEmail(m, param=False)
          except:
            formok = False
            break

          m_domain = m.split('@')[1]
          if not m_domain == domain:
            formok = False
            errors.append(_('All aliases need to be within the same domain!'))
            break

        if len(mail) > 300:
          formok = False

        if not formok:
          errors.append(_('Invalid related aliases!'))

      if not formok:
        self.session['errors'] = errors
        self.session['reqparams'] = {}

        # @TODO request.params may contain multiple values per key... test & fix
        for k in cherrypy.request.params.iterkeys():
          self.session['reqparams'][k] = cherrypy.request.params[k]

        self.session.save()

        if mode == 'edit':
          raise HTTPRedirect('/mails/editAlias/?alias={0}'.format(alias))
        else:
          raise HTTPRedirect('/mails/editAlias')
      else:
        items['mode'] = mode
        items['alias'] = alias
        items['mail'] = []
        items['maildrop'] = []

        if mail and len(mail) > 0:
          for k in mail.split('\n'):
            m = k.replace('\r', '').replace(' ', '')
            if m == '':
              continue

            items['mail'].append(m)

        if maildrop and len(maildrop) > 0:
          for k in maildrop.split('\n'):
            m = k.replace('\r', '').replace(' ', '')
            if m == '':
              continue

            items['maildrop'].append(m)

      return f(self, items)