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