1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
<?php
namespace dokuwiki\Ui;
use dokuwiki\Extension\AuthPlugin;
use dokuwiki\Form\Form;
use dokuwiki\JWT;
/**
* DokuWiki User Profile Interface
*
* @package dokuwiki\Ui
*/
class UserProfile extends Ui
{
/**
* Display the User Profile Form Panel
*
* @return void
* @author Andreas Gohr <andi@splitbrain.org>
*
*/
public function show()
{
/** @var AuthPlugin $auth */
global $auth;
global $INFO;
global $INPUT;
$userinfo = [
'user' => $_SERVER['REMOTE_USER'],
'name' => $INPUT->post->str('fullname', $INFO['userinfo']['name'], true),
'mail' => $INPUT->post->str('email', $INFO['userinfo']['mail'], true),
];
echo p_locale_xhtml('updateprofile');
echo '<div class="centeralign">';
echo $this->updateProfileForm($userinfo)->toHTML('UpdateProfile');
echo $this->tokenForm($userinfo['user'])->toHTML();
if ($auth->canDo('delUser') && actionOK('profile_delete')) {
$this->deleteProfileForm()->toHTML('ProfileDelete');
}
echo '</div>';
}
/**
* Add the password confirmation field to the form if configured
*
* @param Form $form
* @return void
*/
protected function addPasswordConfirmation(Form $form)
{
global $lang;
global $conf;
if (!$conf['profileconfirm']) return;
$form->addHTML("<br>\n");
$attr = ['size' => '50', 'required' => 'required'];
$input = $form->addPasswordInput('oldpass', $lang['oldpass'])->attrs($attr)
->addClass('edit');
$input->getLabel()->attr('class', 'block');
$form->addHTML("<br>\n");
}
/**
* Create the profile form
*
* @return Form
*/
protected function updateProfileForm($userinfo)
{
global $lang;
/** @var AuthPlugin $auth */
global $auth;
$form = new Form(['id' => 'dw__register']);
$form->addTagOpen('div')->addClass('no');
$form->addFieldsetOpen($lang['profile']);
$form->setHiddenField('do', 'profile');
$form->setHiddenField('save', '1');
$attr = ['size' => '50', 'disabled' => 'disabled'];
$input = $form->addTextInput('login', $lang['user'])
->attrs($attr)
->addClass('edit')
->val($userinfo['user']);
$input->getLabel()->attr('class', 'block');
$form->addHTML("<br>\n");
$attr = ['size' => '50'];
if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
$input = $form->addTextInput('fullname', $lang['fullname'])
->attrs($attr)
->addClass('edit')
->val($userinfo['name']);
$input->getLabel()->attr('class', 'block');
$form->addHTML("<br>\n");
$attr = ['type' => 'email', 'size' => '50'];
if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
$input = $form->addTextInput('email', $lang['email'])
->attrs($attr)
->addClass('edit')
->val($userinfo['mail']);
$input->getLabel()->attr('class', 'block');
$form->addHTML("<br>\n");
if ($auth->canDo('modPass')) {
$attr = ['size' => '50'];
$input = $form->addPasswordInput('newpass', $lang['newpass'])->attrs($attr)->addClass('edit');
$input->getLabel()->attr('class', 'block');
$form->addHTML("<br>\n");
$input = $form->addPasswordInput('passchk', $lang['passchk'])->attrs($attr)->addClass('edit');
$input->getLabel()->attr('class', 'block');
$form->addHTML("<br>\n");
}
$this->addPasswordConfirmation($form);
$form->addButton('', $lang['btn_save'])->attr('type', 'submit');
$form->addButton('', $lang['btn_reset'])->attr('type', 'reset');
$form->addFieldsetClose();
$form->addTagClose('div');
return $form;
}
/**
* Create the profile delete form
*
* @return Form
*/
protected function deleteProfileForm()
{
global $lang;
$form = new Form(['id' => 'dw__profiledelete']);
$form->addTagOpen('div')->addClass('no');
$form->addFieldsetOpen($lang['profdeleteuser']);
$form->setHiddenField('do', 'profile_delete');
$form->setHiddenField('delete', '1');
$form->addCheckbox('confirm_delete', $lang['profconfdelete'])
->attrs(['required' => 'required'])
->id('dw__confirmdelete')
->val('1');
$this->addPasswordConfirmation($form);
$form->addButton('', $lang['btn_deleteuser'])->attr('type', 'submit');
$form->addFieldsetClose();
$form->addTagClose('div');
return $form;
}
/**
* Get the authentication token form
*
* @param string $user
* @return Form
*/
protected function tokenForm($user)
{
global $lang;
$token = JWT::fromUser($user);
$form = new Form(['id' => 'dw__profiletoken', 'action' => wl(), 'method' => 'POST']);
$form->setHiddenField('do', 'authtoken');
$form->setHiddenField('id', 'ID');
$form->addFieldsetOpen($lang['proftokenlegend']);
$form->addHTML('<p>' . $lang['proftokeninfo'] . '</p>');
$form->addHTML('<p><code style="display: block; word-break: break-word">' . $token->getToken() . '</code></p>');
$form->addButton('regen', $lang['proftokengenerate']);
$form->addFieldsetClose();
return $form;
}
}
|