Overview
Comment:Improve login form messages
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: cb81b4f7434f008d9008201a11c539c4d4b92109
User & Date: bohwaz on 2020-11-08 03:24:06
Other Links: branch diff | manifest | tags
Context
2020-11-08
03:24
Fix install and other forms with passwords check-in: 14966850df user: bohwaz tags: dev
03:24
Improve login form messages check-in: cb81b4f743 user: bohwaz tags: dev
02:11
Implement list of transactions linked to a service check-in: 54b9d03a1c user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Template.php from [0dc1ec7995] to [946dddaa81].

135
136
137
138
139
140
141




142
143
144
145
146
147
148
149
		$form = $this->getTemplateVars('form');

		if (!$form->hasErrors())
		{
			return '';
		}





		return '<div class="block error"><ul><li>' . implode('</li><li>', $form->getErrorMessages(!empty($params['membre']) ? true : false)) . '</li></ul></div>';
	}

	protected function showError($params)
	{
		if (!$params['if'])
		{
			return '';







>
>
>
>
|







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
		$form = $this->getTemplateVars('form');

		if (!$form->hasErrors())
		{
			return '';
		}

		$errors = $form->getErrorMessages(!empty($params['membre']) ? true : false);
		$errors = array_map([$this, 'escape'], $errors);
		$errors = array_map('nl2br', $errors);

		return '<div class="block error"><ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>';
	}

	protected function showError($params)
	{
		if (!$params['if'])
		{
			return '';

Modified src/templates/admin/login.tpl from [bfb4d0b3a6] to [07fd7dea03].

1
2
3
4
5
6
7
8
9
10
11
{include file="admin/_head.tpl" title="Connexion" js=1}

{form_errors}
{show_error if=$fail message="Connexion impossible. Vérifiez l'adresse e-mail et le mot de passe."}

{if $changed}
    <p class="block confirm">
        Votre mot de passe a bien été modifié.<br />
        Vous pouvez maintenant l'utiliser pour vous reconnecter.
    </p>
{/if}



<







1
2
3

4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Connexion" js=1}

{form_errors}


{if $changed}
    <p class="block confirm">
        Votre mot de passe a bien été modifié.<br />
        Vous pouvez maintenant l'utiliser pour vous reconnecter.
    </p>
{/if}
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Connexion</legend>
        <dl>
            <dt><label for="f_id">{$champ.title}</label></dt>
            <dd><input type="text" name="_id" id="f_id" value="{form_field name=_id}" /></dd>
            <dt><label for="f_passe">Mot de passe</label></dt>
            <dd><input type="password" name="passe" id="f_passe" value="" autocomplete="current-password" />
                {if $ssl_enabled}
                    <b class="icn confirm" title="Connexion chiffrée">&#x1f512;</b>
                    <span class="confirm">Connexion sécurisée</span>
                {else}
                    <b class="icn error" title="Connexion non chiffrée">&#x1f513;</b>
                    {if $prefer_ssl}
                        <span class="error">Connexion non-sécurisée&nbsp;!</span>







|


|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Connexion</legend>
        <dl>
            <dt><label for="f_id">{$id_field_name}</label></dt>
            <dd><input type="text" name="_id" id="f_id" value="{form_field name=_id}" /></dd>
            <dt><label for="f_passe">Mot de passe</label></dt>
            <dd><input type="password" name="password" id="f_passe" value="" autocomplete="current-password" />
                {if $ssl_enabled}
                    <b class="icn confirm" title="Connexion chiffrée">&#x1f512;</b>
                    <span class="confirm">Connexion sécurisée</span>
                {else}
                    <b class="icn error" title="Connexion non chiffrée">&#x1f513;</b>
                    {if $prefer_ssl}
                        <span class="error">Connexion non-sécurisée&nbsp;!</span>

Modified src/www/admin/login.php from [3ef470efd1] to [10a6843bd1].

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

    header('Content-Type: image/gif');
    echo base64_decode("R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==");

    exit;
}

$login = null;

// Soumission du formulaire
if (f('login'))
{
    $form->check('login', [
        '_id'       => 'required|string',
        'passe'     => 'required|string',
        'permanent' => 'boolean',
    ]);


    if (!$form->hasErrors() && ($login = $session->login(f('_id'), f('passe'), (bool) f('permanent'))))
    {
        Utils::redirect(ADMIN_URL);


    }
}

$session->cleanOldCookies();


$champs = $config->get('champs_membres');


$champ = $champs->get($config->get('champ_identifiant'));


$tpl->assign('ssl_enabled', empty($_SERVER['HTTPS']) ? false : true);
$tpl->assign('prefer_ssl', (bool)PREFER_HTTPS);
$tpl->assign('own_https_url', str_replace('http://', 'https://', utils::getSelfURL()));

$tpl->assign('champ', $champ);
$tpl->assign('fail', $login === false);
$tpl->assign('changed', qg('changed') !== null);

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







|
|
|
<
|
|
|
<
<
<
>
|
<
|
<
>
>

|
|
<
>
|
<
>

<
>





|
<



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

    header('Content-Type: image/gif');
    echo base64_decode("R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==");

    exit;
}

$champs = $config->get('champs_membres');
$id_field = (object) $champs->get($config->get('champ_identifiant'));
$id_field_name = $id_field->title;


$form->runIf('login', function () use ($id_field_name, $session) {
    if (!trim(f('_id'))) {



        throw new UserException(sprintf('L\'identifiant (%s) n\'a pas été renseigné.', $id_field_name));
    }



    if (!trim(f('password'))) {
        throw new UserException('Le mot de passe n\'a pas été renseigné.');
    }

    if (!$session->login(f('_id'), f('password'), (bool) f('permanent'))) {

        throw new UserException(sprintf("Connexion impossible.\nVérifiez votre identifiant (%s) et votre mot de passe.", $id_field_name));
    }

}, 'login', ADMIN_URL);


$session->cleanOldCookies();

$tpl->assign('ssl_enabled', empty($_SERVER['HTTPS']) ? false : true);
$tpl->assign('prefer_ssl', (bool)PREFER_HTTPS);
$tpl->assign('own_https_url', str_replace('http://', 'https://', utils::getSelfURL()));

$tpl->assign(compact('id_field_name'));

$tpl->assign('changed', qg('changed') !== null);

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