Exemple #1
0
    def validate(self, model, errors):
        r = self.request
        settings = r.registry.settings
        ldap = False

        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if 'current_password' in r.params and r.params['current_password']:
            if not User.by_credentials(self.session, model.login,
                                       r.params['current_password'], ldap):
                errors.append(_(u'current password is not correct'))
            elif r.params['user.password'] == r.params['current_password']:
                errors.append(_(u'password is unchanged'))

            if r.params['user.password'] != r.params['confirm_password']:
                errors.append(_(u'passwords do not match'))

        if (r.params.get('remove_photo', 'no') == 'no'):
            try:
                photo = r.POST['photofile'].file.read()
                photo_size = len(photo)
                if photo_size > 200000:
                    errors.append(_(u'Invalid photo size: %d' % photo_size))
            except:
                pass

        if errors:
            self.request.session.flash('error;%s' % ','.join(errors))

        return len(errors) == 0
Exemple #2
0
    def validate(self, model, errors):
        r = self.request

        if not User.by_credentials(self.session, model.login,
                                   r.params['current_password']):
            errors.append(_(u'current password is not correct'))
        elif r.params['user.password'] == r.params['current_password']:
            errors.append(_(u'password is inchanged'))

        if r.params['user.password'] != r.params['confirm_password']:
            errors.append(_(u'passwords do not match'))

        return len(errors) == 0
Exemple #3
0
    def validate(self, model, errors):
        r = self.request

        if not User.by_credentials(self.session, model.login,
                                   r.params['current_password']):
            errors.append(_(u'current password is not correct'))
        elif r.params['user.password'] == r.params['current_password']:
            errors.append(_(u'password is inchanged'))

        if r.params['user.password'] != r.params['confirm_password']:
            errors.append(_(u'passwords do not match'))

        return len(errors) == 0
Exemple #4
0
    def render(self):

        passhash = self.request.matchdict['passhash']
        entry = PasswordRecovery.by_hash(self.session, passhash)
        if not entry:
            return HTTPFound(location=route_url('login', self.request))

        if entry.expired:
            msg = 'This password recovery request have expired.'
            self.request.session.flash('error;%s' % msg)
            self.session.delete(entry)
        else:
            errors = []
            if 'form.submitted' in self.request.params:
                r = self.request
                settings = self.request.registry.settings
                ldap = False
                if 'pyvac.use_ldap' in settings:
                    ldap = asbool(settings.get('pyvac.use_ldap'))

                if not len(r.params['user.password']):
                    errors.append(_(u'password cannot be empty'))

                if r.params['user.password'] != r.params['confirm_password']:
                    errors.append(_(u'passwords do not match'))

                if errors:
                    self.request.session.flash('error;%s' % ','.join(errors))

                if not errors:
                    # change user password
                    if ldap:
                        # update in ldap
                        password = [hashPassword(r.params['user.password'])]
                        ldap = LdapCache()
                        ldap.update_user(entry.user, password=password)
                    else:
                        # update locally
                        entry.user.password = r.params['user.password']

                    msg = 'Password successfully changed'
                    self.request.session.flash('info;%s' % msg)
                    self.session.delete(entry)
                    return HTTPFound(location=route_url('login', self.request))

        return {'user': entry.user}
Exemple #5
0
    def render(self):

        passhash = self.request.matchdict['passhash']
        entry = PasswordRecovery.by_hash(self.session, passhash)
        if not entry:
            return HTTPFound(location=route_url('login', self.request))

        if entry.expired:
            msg = 'This password recovery request have expired.'
            self.request.session.flash('error;%s' % msg)
            self.session.delete(entry)
        else:
            errors = []
            if 'form.submitted' in self.request.params:
                r = self.request
                settings = self.request.registry.settings
                ldap = False
                if 'pyvac.use_ldap' in settings:
                    ldap = asbool(settings.get('pyvac.use_ldap'))

                if not len(r.params['user.password']):
                    errors.append(_(u'password cannot be empty'))

                if r.params['user.password'] != r.params['confirm_password']:
                    errors.append(_(u'passwords do not match'))

                if errors:
                    self.request.session.flash('error;%s' % ','.join(errors))

                if not errors:
                    # change user password
                    if ldap:
                        # update in ldap
                        password = [hashPassword(r.params['user.password'])]
                        ldap = LdapCache()
                        ldap.update_user(entry.user, password=password)
                    else:
                        # update locally
                        entry.user.password = r.params['user.password']

                    msg = 'Password successfully changed'
                    self.request.session.flash('info;%s' % msg)
                    self.session.delete(entry)
                    return HTTPFound(location=route_url('login', self.request))

        return {'user': entry.user}
Exemple #6
0
    def render(self):

        passhash = self.request.matchdict["passhash"]
        entry = PasswordRecovery.by_hash(self.session, passhash)
        if not entry:
            return HTTPFound(location=route_url("login", self.request))

        if entry.expired:
            msg = "This password recovery request have expired."
            self.request.session.flash("error;%s" % msg)
            self.session.delete(entry)
        else:
            errors = []
            if "form.submitted" in self.request.params:
                r = self.request
                settings = self.request.registry.settings
                ldap = False
                if "pyvac.use_ldap" in settings:
                    ldap = asbool(settings.get("pyvac.use_ldap"))

                if not len(r.params["user.password"]):
                    errors.append(_(u"password cannot be empty"))

                if r.params["user.password"] != r.params["confirm_password"]:
                    errors.append(_(u"passwords do not match"))

                if errors:
                    self.request.session.flash("error;%s" % ",".join(errors))

                if not errors:
                    # change user password
                    if ldap:
                        # update in ldap
                        password = [hashPassword(r.params["user.password"])]
                        ldap = LdapCache()
                        ldap.update_user(entry.user, password=password)
                    else:
                        # update locally
                        entry.user.password = r.params["user.password"]

                    msg = "Password successfully changed"
                    self.request.session.flash("info;%s" % msg)
                    self.session.delete(entry)
                    return HTTPFound(location=route_url("login", self.request))

        return {"user": entry.user}
Exemple #7
0
    def validate(self, model, errors):
        r = self.request
        if 'user.password' in r.params:
            if r.params['user.password'] != r.params['confirm_password']:
                errors.append(_('passwords do not match'))

        if 'user.login' not in r.params:
            if 'user.ldap_user' in r.params and r.params['user.ldap_user']:
                r_space = re.compile(r'\s+')
                # generate login for ldap user
                login = '******' % (r.params['user.firstname'].strip().lower(),
                                   r.params['user.lastname'].strip().lower())
                # remove all spaces
                login = r_space.sub('', login)
                model.login = login
            else:
                errors.append(_('login is required'))

        return len(errors) == 0
Exemple #8
0
    def validate(self, model, errors):
        r = self.request
        if 'user.password' in r.params:
            if r.params['user.password'] != r.params['confirm_password']:
                errors.append(_('passwords do not match'))

        if 'user.login' not in r.params:
            if 'user.ldap_user' in r.params and r.params['user.ldap_user']:
                r_space = re.compile(r'\s+')
                # generate login for ldap user
                login = '******' % (r.params['user.firstname'].strip().lower(),
                                   r.params['user.lastname'].strip().lower())
                # remove all spaces
                login = r_space.sub('', login)
                model.login = login
            else:
                errors.append(_('login is required'))

        return len(errors) == 0
Exemple #9
0
    def validate(self, model, errors):
        r = self.request
        settings = r.registry.settings
        ldap = False

        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if 'current_password' in r.params and r.params['current_password']:
            if not User.by_credentials(self.session, model.login,
                                       r.params['current_password'], ldap):
                errors.append(_('current password is not correct'))
            elif r.params['user.password'] == r.params['current_password']:
                errors.append(_('password is unchanged'))

            if r.params['user.password'] != r.params['confirm_password']:
                errors.append(_('passwords do not match'))

        if (r.params.get('remove_photo', 'no') == 'no'):
            try:
                photo = r.POST['photofile'].file.read()
                photo_size = len(photo)
                if photo_size > 200000:
                    errors.append(_('Invalid photo size: %d' % photo_size))
            except:
                pass

        for up in model.pools:
            key = 'up%d' % up.id
            if key in r.params:
                new = r.params[key]
                # add some sanity checks
                try:
                    float(new)
                except Exception as exc:
                    log.error('cannot update %s: %s' % (up, exc))
                    errors.append(
                        _('Wrong value for %s: %s' % (up.fullname, new)))

        if errors:
            self.request.session.flash('error;%s' % ','.join(errors))

        return len(errors) == 0
Exemple #10
0
    def validate(self, model, errors):
        r = self.request
        settings = r.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if 'current_password' in r.params and r.params['current_password']:
            if not User.by_credentials(self.session, model.login,
                                       r.params['current_password'], ldap):
                errors.append(_(u'current password is not correct'))
            elif r.params['user.password'] == r.params['current_password']:
                errors.append(_(u'password is unchanged'))

            if r.params['user.password'] != r.params['confirm_password']:
                errors.append(_(u'passwords do not match'))

            if errors:
                self.request.session.flash('error;%s' % ','.join(errors))

        return len(errors) == 0
Exemple #11
0
 def type(self):
     """
     Get name of chosen vacation type.
     """
     return _(self.vacation_type.name, self.user.country)