xref: /dokuwiki/inc/Ui/UserResendPwd.php (revision 2c210ad72adfec6edcda2464d0f4e194d7aa8b3c)
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 HTML_RESENDPWDFORM_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        // emit HTML_RESENDPWDFORM_OUTPUT event
42        Event::createAndTrigger('HTML_RESENDPWDFORM_OUTPUT', $form, null, false);
43        print $form->toHTML();
44
45        print '</div>';
46    }
47
48    /**
49     * create a form ui to set new password
50     *
51     * @params string $token  cleaned pwauth request variable
52     * @return Form
53     */
54    protected function formSetNewPassword($token)
55    {
56        global $lang;
57
58        // create the form
59        $form = new Form(['id' => 'dw__resendpwd']);
60        $form->addTagOpen('div')->addClass('no');
61        $form->addFieldsetOpen($lang['btn_resendpwd']);
62        $form->setHiddenField('token', $token);
63        $form->setHiddenField('do', 'resendpwd');
64        $input = $form->addPasswordInput('pass', $lang['pass'])->attr('size', '50')->addClass('edit');
65        $input->getLabel()->attr('class', 'block');
66        $form->addHTML("<br>\n");
67        $input = $form->addPasswordInput('passchk', $lang['passchk'])->attr('size', '50')->addClass('edit');
68        $input->getLabel()->attr('class', 'block');
69        $form->addHTML("<br>\n");
70        $form->addButton('', $lang['btn_resendpwd'])->attr('type', 'submit');
71        $form->addFieldsetClose();
72        $form->addTagClose('div');
73        return $form;
74    }
75
76    /**
77     * create a form ui to request new password
78     *
79     * @return Form
80     */
81    protected function formResendPassword()
82    {
83        global $lang;
84
85        // create the form
86        $form = new Form(['id' => 'dw__resendpwd']);
87        $form->addTagOpen('div')->addClass('no');
88        $form->addFieldsetOpen($lang['btn_resendpwd']);
89        $form->setHiddenField('do', 'resendpwd');
90        $form->setHiddenField('save', '1');
91        $form->addHTML("<br>\n");
92        $input = $form->addTextInput('login', $lang['user'])->addClass('edit');
93        $input->getLabel()->attr('class', 'block');
94        $form->addHTML("<br>\n");
95        $form->addHTML("<br>\n");
96        $form->addButton('', $lang['btn_resendpwd'])->attr('type', 'submit');
97        $form->addFieldsetClose();
98        $form->addTagClose('div');
99        return $form;
100    }
101
102}
103