Overview
Comment:Utilisation de l'objet Form
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: e0f0708659c8659a9761a35ffcaf89e5695ff079
User & Date: bohwaz on 2017-05-25 05:46:45
Other Links: branch diff | manifest | tags
Context
2017-05-25
06:16
Passage de la taille de mot de passe à 6 caractères minimum check-in: 92f97b5ca6 user: bohwaz tags: dev
05:46
Utilisation de l'objet Form check-in: e0f0708659 user: bohwaz tags: dev
05:46
Changement de la taille de page de SQLite check-in: 1fec967f50 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Form.php from [3de82224f0] to [c4752f5492].

27
28
29
30
31
32
33





34
35
36
37
38
39
40
41
42
43
44
		return (count($this->errors) > 0);
	}

	public function &getErrors()
	{
		return $this->errors;
	}






	public function getErrorMessages()
	{
		return;
	}

	public function __invoke($key)
	{
		return \KD2\Form::get($key);
	}
}







>
>
>
>
>











27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
		return (count($this->errors) > 0);
	}

	public function &getErrors()
	{
		return $this->errors;
	}

	public function addError($msg)
	{
		$this->errors[] = $msg;
	}

	public function getErrorMessages()
	{
		return;
	}

	public function __invoke($key)
	{
		return \KD2\Form::get($key);
	}
}

Modified src/www/admin/mes_infos_securite.php from [57647c5fb5] to [1a8ba8f765].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace Garradin;

use Garradin\Membres\Session;

require_once __DIR__ . '/_inc.php';

$errors = [];
$confirm = false;

if (f('confirm'))
{
    fc('edit_me_security', [
        'passe'       => 'confirmed',
        'passe_check' => 'required',
    ], $errors);

    if (f('passe_check') && !$session->checkPassword(f('passe_check')))
    {
        $errors[] = 'Le mot de passe fourni ne correspond pas au mot de passe actuel. Merci de bien vouloir renseigner votre mot de passe courant pour confirmer les changements.';
    }
    elseif (f('otp_secret') && !Session::checkOTP(f('otp_secret'), f('code')))
    {
        $errors[] = 'Le code TOTP entré n\'est pas valide.';
    }

    if (count($errors) === 0)
    {
        try {
            $data = [
                'clef_pgp' => f('clef_pgp'),
            ];

            if (f('passe') && !empty($config->get('champs_membres')->get('passe')->editable))








<




|


|



|



|


|







1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

namespace Garradin;

use Garradin\Membres\Session;

require_once __DIR__ . '/_inc.php';


$confirm = false;

if (f('confirm'))
{
    $form->check('edit_me_security', [
        'passe'       => 'confirmed',
        'passe_check' => 'required',
    ]);

    if (f('passe_check') && !$session->checkPassword(f('passe_check')))
    {
        $form->addError('Le mot de passe fourni ne correspond pas au mot de passe actuel. Merci de bien vouloir renseigner votre mot de passe courant pour confirmer les changements.');
    }
    elseif (f('otp_secret') && !Session::checkOTP(f('otp_secret'), f('code')))
    {
        $form->addError('Le code TOTP entré n\'est pas valide.');
    }

    if (!$form->hasErrors())
    {
        try {
            $data = [
                'clef_pgp' => f('clef_pgp'),
            ];

            if (f('passe') && !empty($config->get('champs_membres')->get('passe')->editable))
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
            }

            $session->editSecurity($data);
            Utils::redirect('/admin/');
        }
        catch (UserException $e)
        {
            $errors[] = $e->getMessage();
        }
    }

    $confirm = true;
}
elseif (f('save'))
{
    fc('edit_me_security', [
        'passe'       => 'confirmed',
    ], $errors);

    if (f('clef_pgp') && !$session->getPGPFingerprint(f('clef_pgp')))
    {
        $errors[] = 'Clé PGP invalide : impossible de récupérer l\'empreinte de la clé.';
    }
    
    if (count($errors) === 0)
    {
        $confirm = true;
    }
}

$tpl->assign('form_errors', $errors);
$tpl->assign('confirm', $confirm);

if (f('otp') == 'generate')
{
    $otp = $session->getNewOTPSecret();
    $tpl->assign('otp', $otp);
}







|







|

|



|


|





<







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
            }

            $session->editSecurity($data);
            Utils::redirect('/admin/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }

    $confirm = true;
}
elseif (f('save'))
{
    $form->check('edit_me_security', [
        'passe'       => 'confirmed',
    ]);

    if (f('clef_pgp') && !$session->getPGPFingerprint(f('clef_pgp')))
    {
        $form->addError('Clé PGP invalide : impossible de récupérer l\'empreinte de la clé.');
    }
    
    if (!$form->hasErrors())
    {
        $confirm = true;
    }
}


$tpl->assign('confirm', $confirm);

if (f('otp') == 'generate')
{
    $otp = $session->getNewOTPSecret();
    $tpl->assign('otp', $otp);
}

Modified src/www/admin/static/admin.css from [2b3fa68bc0] to [e49b15a429].

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66




67
68
69
70
71
72
73
74
75
76
77
    --gMainColor: 156, 79, 21;
    --gSecondColor: 217, 134, 40;
}

html {
    width: 100%;
    height: 100%;
    background: #fff url("gdin_bg.png") no-repeat 0px 0px fixed;
    background-color: rgb(var(--gBgColor));
    /* Pas possible d'utiliser une variable CSS pour l'image de fond, c'est bugué dans Chrome
    cf. https://bugs.chromium.org/p/chromium/issues/detail?id=618165 */
}

body {
    font-size: 100%;
    color: #000;
    font-family: "Trebuchet MS", Arial, Helvetica, Sans-serif;
    padding-bottom: 1em;




}

body#popup {
    background: rgb(var(--gBgColor));
}

body#transparent {
    background: transparent;
}

.header {







<
<
<
<







>
>
>
>



|







49
50
51
52
53
54
55




56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    --gMainColor: 156, 79, 21;
    --gSecondColor: 217, 134, 40;
}

html {
    width: 100%;
    height: 100%;




}

body {
    font-size: 100%;
    color: #000;
    font-family: "Trebuchet MS", Arial, Helvetica, Sans-serif;
    padding-bottom: 1em;
    background: #fff url("gdin_bg.png") no-repeat 0px 0px fixed;
    background-color: rgb(var(--gBgColor));
    /* Pas possible d'utiliser une variable CSS pour l'image de fond, c'est bugué dans Chrome
    cf. https://bugs.chromium.org/p/chromium/issues/detail?id=618165 */
}

body#popup {
    background-position: -170px 0px;
}

body#transparent {
    background: transparent;
}

.header {

Modified src/www/admin/wiki/_chercher_parent.php from [9651102d9e] to [4ec2c6e487].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$parent = (int) qg('parent');

$tpl->assign('parent', $parent);
$tpl->assign('list', $wiki->listBackParentTree($parent));

function tpl_display_tree($params)
{
    if (isset($params->tree))
        $tree = $params->tree;
    else
        $tree = $params;

    $out = '<ul>';

    foreach ($tree as $node)
    {







|
|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$parent = (int) qg('parent');

$tpl->assign('parent', $parent);
$tpl->assign('list', $wiki->listBackParentTree($parent));

function tpl_display_tree($params)
{
    if (isset($params['tree']))
        $tree = $params['tree'];
    else
        $tree = $params;

    $out = '<ul>';

    foreach ($tree as $node)
    {

Modified src/www/admin/wiki/_fichiers.php from [78531b30dd] to [fe7c6001eb].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if ($hash_check = f('uploadHelper_hashCheck'))
{
    echo json_encode(Fichiers::checkHashList($hash_check));
    exit;
}
elseif (f('delete'))
{
    if (fc($csrf_id, [], $form_errors))
    {
        try {
            $fichier = new Fichiers(f('delete'));
            
            if (!$fichier->checkAccess($user))
            {
                throw new UserException('Vous n\'avez pas accès à ce fichier.');
            }

            $fichier->remove();
            Utils::redirect('/admin/wiki/_fichiers.php?page=' . $page->id);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
}
elseif (f('upload') || f('uploadHelper_mode'))
{
    $validate = ['fichier' => 'file|required'];

    if (f('uploadHelper_mode') == 'hash_only')
    {
        $validate = [
            'uploadHelper_fileHash' => 'required',
            'uploadHelper_fileName' => 'required',
        ];
    }

    fc($csrf_id, $validate, $form_errors);

    if (f('uploadHelper_status') > 0)
    {
        $form_errors[] = 'Un seul fichier peut être envoyé en même temps.';
    }
    
    if (count($form_errors) === 0)
    {
        try {
            if (f('uploadHelper_mode') == 'hash_only' && f('uploadHelper_fileHash') && f('uploadHelper_fileName'))
            {
                $fichier = Fichiers::uploadExistingHash(f('uploadHelper_fileName'), f('uploadHelper_fileHash'));
            }
            else







|














|















|



|


|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if ($hash_check = f('uploadHelper_hashCheck'))
{
    echo json_encode(Fichiers::checkHashList($hash_check));
    exit;
}
elseif (f('delete'))
{
    if ($form->check($csrf_id))
    {
        try {
            $fichier = new Fichiers(f('delete'));
            
            if (!$fichier->checkAccess($user))
            {
                throw new UserException('Vous n\'avez pas accès à ce fichier.');
            }

            $fichier->remove();
            Utils::redirect('/admin/wiki/_fichiers.php?page=' . $page->id);
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}
elseif (f('upload') || f('uploadHelper_mode'))
{
    $validate = ['fichier' => 'file|required'];

    if (f('uploadHelper_mode') == 'hash_only')
    {
        $validate = [
            'uploadHelper_fileHash' => 'required',
            'uploadHelper_fileName' => 'required',
        ];
    }

    $form->check($csrf_id, $validate);

    if (f('uploadHelper_status') > 0)
    {
        $form->addError('Un seul fichier peut être envoyé en même temps.');
    }
    
    if (!$form->hasErrors())
    {
        try {
            if (f('uploadHelper_mode') == 'hash_only' && f('uploadHelper_fileHash') && f('uploadHelper_fileName'))
            {
                $fichier = Fichiers::uploadExistingHash(f('uploadHelper_fileName'), f('uploadHelper_fileHash'));
            }
            else
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
                exit;
            }

            Utils::redirect($uri);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }

    if (f('uploadHelper_mode') !== null)
    {
        echo json_encode(['error' => implode(PHP_EOL, $form_errors)]);
        exit;
    }
}

$tpl->assign('fichiers', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, false));
$tpl->assign('images', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, true));








|





|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
                exit;
            }

            Utils::redirect($uri);
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }

    if (f('uploadHelper_mode') !== null)
    {
        echo json_encode(['error' => implode(PHP_EOL, $form->getErrorMessages())]);
        exit;
    }
}

$tpl->assign('fichiers', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, false));
$tpl->assign('images', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, true));

Modified src/www/admin/wiki/creer.php from [f0561e6ff0] to [6111448da5].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$parent = (int) Utils::get('parent') ?: 0;

if (f('create'))
{
    fc('wiki_create', [
        'titre' => 'required',
        'parent'=> 'required|integer'
    ], $form_errors);

    try {
        $id = $wiki->create([
            'titre'  => f('titre'),
            'parent' => $parent,
        ]);

        Utils::redirect('/admin/wiki/editer.php?id='.$id);
    }
    catch (UserException $e)
    {
        $form_errors[] = $e->getMessage();
    }
}

$tpl->display('admin/wiki/creer.tpl');





|



|


|











|




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$parent = (int) qg('parent');

if (f('create'))
{
    $form->check('wiki_create', [
        'titre' => 'required',
        'parent'=> 'required|integer'
    ]);

    try {
        $id = $wiki->create([
            'titre'  => f('titre'),
            'parent' => $parent,
        ]);

        Utils::redirect('/admin/wiki/editer.php?id='.$id);
    }
    catch (UserException $e)
    {
        $form->addError($e->getMessage());
    }
}

$tpl->display('admin/wiki/creer.tpl');

Modified src/www/admin/wiki/editer.php from [2d55183856] to [4efdb79d82].

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
if (f('date'))
{
    $date = f('date') . ' ' . sprintf('%02d:%02d', f('date_h'), f('date_min'));
}

if (f('save'))
{
    fc('wiki_edit_'.$page->id, [
        'titre'          => 'required',
        'uri'            => 'required',
        'parent'         => 'numeric',
        'droit_lecture'  => 'numeric',
        'droit_ecriture' => 'numeric',
    ], $form_errors);
    
    if ($page->date_modification > (int) f('debut_edition'))
    {
        $form_errors[] = 'La page a été modifiée par quelqu\'un d\'autre depuis que vous avez commencé l\'édition.';
    }

    if (count($form_errors) === 0)
    {
        try {
            $wiki->edit($page->id, [
                'titre'         =>  f('titre'),
                'uri'           =>  f('uri'),
                'parent'        =>  f('parent'),
                'droit_lecture' =>  f('droit_lecture'),







|





|



|


|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
if (f('date'))
{
    $date = f('date') . ' ' . sprintf('%02d:%02d', f('date_h'), f('date_min'));
}

if (f('save'))
{
    $form->check('wiki_edit_' . $page->id, [
        'titre'          => 'required',
        'uri'            => 'required',
        'parent'         => 'numeric',
        'droit_lecture'  => 'numeric',
        'droit_ecriture' => 'numeric',
    ]);
    
    if ($page->date_modification > (int) f('debut_edition'))
    {
        $form->addError('La page a été modifiée par quelqu\'un d\'autre depuis que vous avez commencé l\'édition.');
    }

    if (!$form->hasErrors())
    {
        try {
            $wiki->edit($page->id, [
                'titre'         =>  f('titre'),
                'uri'           =>  f('uri'),
                'parent'        =>  f('parent'),
                'droit_lecture' =>  f('droit_lecture'),
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

            $page = $wiki->getById($page->id);

            Utils::redirect('/admin/wiki/?'.$page->uri);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
}

$parent = (int) f('parent') ?: (int) $page->parent;
$tpl->assign('parent', $parent ? $wiki->getTitle($parent) : 0);








|







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

            $page = $wiki->getById($page->id);

            Utils::redirect('/admin/wiki/?'.$page->uri);
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$parent = (int) f('parent') ?: (int) $page->parent;
$tpl->assign('parent', $parent ? $wiki->getTitle($parent) : 0);

Modified src/www/admin/wiki/supprimer.php from [f4dd6d4f24] to [ad2a98e1d6].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if (!$page)
{
    throw new UserException("Cette page n'existe pas.");
}

if (f('delete'))
{
    if (fc('delete_wiki_'.$page->id, [], $form_errors))
    {
        if ($wiki->delete($page->id))
        {
            Utils::redirect('/admin/wiki/');
        }
        else
        {
            $form_errors[] = "D'autres pages utilisent cette page comme rubrique parente.";
        }
    }
}

$tpl->assign('page', $page);

$tpl->display('admin/wiki/supprimer.tpl');







|







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if (!$page)
{
    throw new UserException("Cette page n'existe pas.");
}

if (f('delete'))
{
    if ($form->check('delete_wiki_' . $page->id))
    {
        if ($wiki->delete($page->id))
        {
            Utils::redirect('/admin/wiki/');
        }
        else
        {
            $form->addError('D\'autres pages utilisent cette page comme rubrique parente.');
        }
    }
}

$tpl->assign('page', $page);

$tpl->display('admin/wiki/supprimer.tpl');