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        $form->addHTML("<br>\n");
57
58        $input = $form->addPasswordInput('p', $lang['pass'])->addClass('block edit');
59        $input->getLabel()->attr('class', 'block');
60        $form->addHTML("<br>\n");
61
62        if ($conf['rememberme']) {
63            $form->addCheckbox('r', $lang['remember'])->id('remember__me')->val('1');
64        }
65        $form->addButton('', $lang['btn_login'])->attr('type', 'submit');
66        $form->addFieldsetClose();
67        $form->addTagClose('div');
68
69        if (actionOK('register')) {
70            $registerLink = (new Register())->asHtmlLink('', $this->showIcon);
71            $form->addHTML('<p>' . $lang['reghere'] . ': ' . $registerLink . '</p>');
72        }
73
74        if (actionOK('resendpwd')) {
75            $resendPwLink = (new Resendpwd())->asHtmlLink('', $this->showIcon);
76            $form->addHTML('<p>' . $lang['pwdforget'] . ': ' . $resendPwLink . '</p>');
77        }
78
79        echo $form->toHTML('Login');
80
81        echo '</div>';
82    }
83}
84