xref: /dokuwiki/inc/Ui/Login.php (revision 628d5475960b57769a64aba8fb0d0aab3de4dae4)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\Extension\Event;
6use dokuwiki\Form\Form;
7
8/**
9 * DokuWiki User Login Interface (Login Form)
10 *
11 * @package dokuwiki\Ui
12 */
13class Login extends Ui
14{
15    protected $showIcon = false;
16
17    /**
18     * Login Ui constructor
19     *
20     * @param bool $showIcon  Whether to show svg icons in the register and resendpwd links or not
21     */
22    public function __construct($showIcon = false)
23    {
24        $this->showIcon = (bool)$showIcon;
25    }
26
27    /**
28     * Display the Login Form Panel
29     *
30     * @author   Andreas Gohr <andi@splitbrain.org>
31     *
32     * @triggers HTML_LOGINFORM_OUTPUT
33     * @return void
34     */
35    public function show()
36    {
37        global $lang;
38        global $conf;
39        global $ID;
40        global $INPUT;
41
42        // print intro
43        print p_locale_xhtml('login');
44        print '<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 \dokuwiki\Menu\Item\Register())->asHtmlLink('', $this->showIcon);
71            $form->addHTML('<p>'.$lang['reghere'].': '. $registerLink .'</p>');
72        }
73
74        if (actionOK('resendpwd')) {
75            $resendPwLink = (new \dokuwiki\Menu\Item\Resendpwd())->asHtmlLink('', $this->showIcon);
76            $form->addHTML('<p>'.$lang['pwdforget'].': '. $resendPwLink .'</p>');
77        }
78
79        // emit HTML_LOGINFORM_OUTPUT event
80        Event::createAndTrigger('HTML_LOGINFORM_OUTPUT', $form, null, false);
81        print $form->toHTML();
82
83        print '</div>';
84    }
85
86}
87