xref: /dokuwiki/inc/Ui/UserResendPwd.php (revision 903616ed12dcfe945867ad1068c86fba11c6f55d)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\Extension\Event;
6use dokuwiki\Form\Form;
7
8/**
9 * DokuWiki Resend Password Request Interface
10 *
11 * @package dokuwiki\Ui
12 */
13class UserResendPwd extends Ui
14{
15    /**
16     * Display the form to request a new password for an existing account
17     *
18     * @author   Benoit Chesneau <benoit@bchesneau.info>
19     * @author   Andreas Gohr <andi@splitbrain.org>
20     *
21     * @triggers HTMLFORM_RESENDPWD_OUTPUT
22     * @return void
23     */
24    public function show()
25    {
26        global $conf;
27        global $INPUT;
28
29        $token = preg_replace('/[^a-f0-9]+/', '', $INPUT->str('pwauth'));
30
31        // print intro
32        print p_locale_xhtml('resetpwd');
33        print '<div class="centeralign">';
34
35        if (!$conf['autopasswd'] && $token) {
36            $form = $this->formSetNewPassword($token);
37        } else {
38            $form = $this->formResendPassword();
39        }
40
41        //print form that might be modified by HTMLFORM_RESENDPWD_OUTPUT event handlers
42        print $form->toHTML('resendpwd');
43
44        print '</div>';
45    }
46
47    /**
48     * create a form ui to set new password
49     *
50     * @params string $token  cleaned pwauth request variable
51     * @return Form
52     */
53    protected function formSetNewPassword($token)
54    {
55        global $lang;
56
57        // create the form
58        $form = new Form(['id' => 'dw__resendpwd']);
59        $form->addTagOpen('div')->addClass('no');
60        $form->addFieldsetOpen($lang['btn_resendpwd']);
61        $form->setHiddenField('token', $token);
62        $form->setHiddenField('do', 'resendpwd');
63        $input = $form->addPasswordInput('pass', $lang['pass'])->attr('size', '50')->addClass('edit');
64        $input->getLabel()->attr('class', 'block');
65        $form->addHTML("<br>\n");
66        $input = $form->addPasswordInput('passchk', $lang['passchk'])->attr('size', '50')->addClass('edit');
67        $input->getLabel()->attr('class', 'block');
68        $form->addHTML("<br>\n");
69        $form->addButton('', $lang['btn_resendpwd'])->attr('type', 'submit');
70        $form->addFieldsetClose();
71        $form->addTagClose('div');
72        return $form;
73    }
74
75    /**
76     * create a form ui to request new password
77     *
78     * @return Form
79     */
80    protected function formResendPassword()
81    {
82        global $lang;
83
84        // create the form
85        $form = new Form(['id' => 'dw__resendpwd']);
86        $form->addTagOpen('div')->addClass('no');
87        $form->addFieldsetOpen($lang['btn_resendpwd']);
88        $form->setHiddenField('do', 'resendpwd');
89        $form->setHiddenField('save', '1');
90        $form->addHTML("<br>\n");
91        $input = $form->addTextInput('login', $lang['user'])->addClass('edit');
92        $input->getLabel()->attr('class', 'block');
93        $form->addHTML("<br>\n");
94        $form->addHTML("<br>\n");
95        $form->addButton('', $lang['btn_resendpwd'])->attr('type', 'submit');
96        $form->addFieldsetClose();
97        $form->addTagClose('div');
98        return $form;
99    }
100
101}
102