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