xref: /dokuwiki/inc/Ui/Login.php (revision 4085a5aa9d31b42657f3eb3773fd11e607515354)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\Form\Form;
6use dokuwiki\Menu\Item\Register;
7use dokuwiki\Menu\Item\Resendpwd;
8
9/**
10 * DokuWiki User Login Interface (Login Form)
11 *
12 * @package dokuwiki\Ui
13 */
14class Login extends Ui
15{
16    protected $showIcon = false;
17
18    /**
19     * Login Ui constructor
20     *
21     * @param bool $showIcon Whether to show svg icons in the register and resendpwd links or not
22     */
23    public function __construct($showIcon = false)
24    {
25        $this->showIcon = (bool)$showIcon;
26    }
27
28    /**
29     * Display the Login Form Panel
30     *
31     * @return void
32     * @author   Andreas Gohr <andi@splitbrain.org>
33     *
34     */
35    public function show()
36    {
37        global $lang;
38        global $conf;
39        global $ID;
40        global $INPUT;
41
42        // print intro
43        echo p_locale_xhtml('login');
44        echo '<div class="centeralign">' . NL;
45
46        // create the login form
47        $form = new Form(['id' => 'dw__login', 'action' => wl($ID)]);
48        $form->addTagOpen('div')->addClass('no');
49        $form->addFieldsetOpen($lang['btn_login']);
50        $form->setHiddenField('id', $ID);
51        $form->setHiddenField('do', 'login');
52
53        $input = $form->addTextInput('u', $lang['user'])->id('focus__this')->addClass('edit')
54            ->val(($INPUT->bool('http_credentials')) ? '' : $INPUT->str('u'));
55        $input->getLabel()->attr('class', 'block');
56        $input->attr('autocomplete', 'username');
57        $form->addHTML("<br>\n");
58
59        $input = $form->addPasswordInput('p', $lang['pass'])->addClass('block edit');
60        $input->getLabel()->attr('class', 'block');
61        $input->attr('autocomplete', 'current-password');
62        $form->addHTML("<br>\n");
63
64        if ($conf['rememberme']) {
65            $form->addCheckbox('r', $lang['remember'])->id('remember__me')->val('1');
66        }
67        $form->addButton('', $lang['btn_login'])->attr('type', 'submit');
68        $form->addFieldsetClose();
69        $form->addTagClose('div');
70
71        if (actionOK('register')) {
72            $registerLink = (new Register())->asHtmlLink('', $this->showIcon);
73            $form->addHTML('<p>' . $lang['reghere'] . ': ' . $registerLink . '</p>');
74        }
75
76        if (actionOK('resendpwd')) {
77            $resendPwLink = (new Resendpwd())->asHtmlLink('', $this->showIcon);
78            $form->addHTML('<p>' . $lang['pwdforget'] . ': ' . $resendPwLink . '</p>');
79        }
80
81        echo $form->toHTML('Login');
82
83        echo '</div>';
84    }
85}
86