Пример #1
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)
Пример #2
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)
Пример #3
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')
Пример #4
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')
Пример #5
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)
Пример #6
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)