Project

General

Profile

Actions

Evolution #1001

closed

Empêcher les adhérents de rentrer la date actuelle à la place de la ddn

Added by Amaury Froment over 7 years ago. Updated about 6 years ago.

Status:
Fermé
Priority:
Normal
Category:
Core
Target version:
Start date:
01/21/2017
Due date:
% Done:

0%

Estimated time:

Description

Contexte: https://github.com/trasher/galette/pull/1
J'ai modifié la class Adherent.php pour brider un peu les inscriptions et éviter ainsi que les adhérents puissent taper a date courante à la place de leur date de naissance.
Mon plugin a besoin d'une date de naissance valide pour calculer des tarifs.
J'ai donc fait un contrôle de l'age:
un age dépassant ]200ans..1an[ est invalide.
(idée: On pourrait laisser l'admin choisir le type de filtre ou le choix de l'activer ou non.)
détails du code:

case 'date_crea_adh':
    try {
        $d = \DateTime::createFromFormat(_T("Y-m-d"), $value);

        if ( $d === false ) {
            //try with non localized date
            $d = \DateTime::createFromFormat("Y-m-d", $value);
            if ( $d === false ) {
                throw new \Exception('Incorrect format');
            }
        }
        $this->$prop = $d->format('Y-m-d');
    } catch (\Exception $e) {
        Analog::log(
            'Wrong date format. field: ' . $key .
            ', value: ' . $value . ', expected fmt: ' .
            _T("Y-m-d") . ' | ' . $e->getMessage(),
            Analog::INFO
        );
        $errors[] = str_replace(
            array(
                '%date_format',
                '%field'
            ),
            array(
                _T("Y-m-d"),
                $this->_fields[$key]['label']
            ),
            _T("- Wrong date format (%date_format) for %field!")
        );
    }
    break;
case 'ddn_adh':
    try {
        $d = \DateTime::createFromFormat(_T("Y-m-d"), $value);

        $birthdate= \DateTime::createFromFormat('j/m/Y',$value);
        $today= new \DateTime("now");
        //echo('today:');
        //var_dump($today);
        //echo('birthdate:');
        //var_dump($birthdate);
        //echo('diff:');
        $age=$birthdate->diff($today);
        //var_dump($age->format('%R%Y'));

        $age=$age->format('%Y');
        if($age>200 || $age<1)
            {
            $d=false;
            }

        if ( $d === false ) {
            //try with non localized date
            $d = \DateTime::createFromFormat("Y-m-d", $value);
            if ( $d === false ) {
                throw new \Exception('Incorrect format');
            }
        }
        $this->$prop = $d->format('Y-m-d');
    } catch (\Exception $e) {
        Analog::log(
            'Wrong date format. field: ' . $key .
            ', value: ' . $value . ', expected fmt: ' .
            _T("Y-m-d") . ' | ' . $e->getMessage(),
            Analog::INFO
        );
        $errors[] = str_replace(
            array(
                '%date_format',
                '%field'
            ),
            array(
                _T("Y-m-d"),
                $this->_fields[$key]['label']
            ),
            _T("- Wrong date format (%date_format) for %field!")
        );
    }
    break;
Actions #1

Updated by Johan Cwiklinski over 6 years ago

  • Target version deleted (0.9)
Actions #2

Updated by Johan Cwiklinski about 6 years ago

  • Description updated (diff)
Actions #3

Updated by Johan Cwiklinski about 6 years ago

  • Status changed from Nouveau to In Progress
  • Target version set to 0.9.2
Actions #4

Updated by Johan Cwiklinski about 6 years ago

  • Status changed from In Progress to Résolu
  • % Done changed from 0 to 100
Actions #5

Updated by Johan Cwiklinski about 6 years ago

  • Status changed from Résolu to Fermé
  • % Done changed from 100 to 0
Actions

Also available in: Atom PDF