You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

186 lines
5.5 KiB

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