passwordreset.tpl.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php
  2. /* Copyright (C) 2022 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. // To show this page, we need parameters: setnewpassword=1&username=...&passworduidhash=...
  18. if (!defined('NOBROWSERNOTIF')) {
  19. define('NOBROWSERNOTIF', 1);
  20. }
  21. // Protection to avoid direct call of template
  22. if (empty($conf) || !is_object($conf)) {
  23. print "Error, template page can't be called as URL";
  24. exit;
  25. }
  26. // DDOS protection
  27. $size = (int) $_SERVER['CONTENT_LENGTH'];
  28. if ($size > 10000) {
  29. $langs->loadLangs(array("errors", "install"));
  30. httponly_accessforbidden('<center>'.$langs->trans("ErrorRequestTooLarge").'<br><a href="'.DOL_URL_ROOT.'">'.$langs->trans("ClickHereToGoToApp").'</a></center>', 413, 1);
  31. }
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  33. header('Cache-Control: Public, must-revalidate');
  34. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  35. if (GETPOST('dol_hide_topmenu')) {
  36. $conf->dol_hide_topmenu = 1;
  37. }
  38. if (GETPOST('dol_hide_leftmenu')) {
  39. $conf->dol_hide_leftmenu = 1;
  40. }
  41. if (GETPOST('dol_optimize_smallscreen')) {
  42. $conf->dol_optimize_smallscreen = 1;
  43. }
  44. if (GETPOST('dol_no_mouse_hover')) {
  45. $conf->dol_no_mouse_hover = 1;
  46. }
  47. if (GETPOST('dol_use_jmobile')) {
  48. $conf->dol_use_jmobile = 1;
  49. }
  50. // If we force to use jmobile, then we reenable javascript
  51. if (!empty($conf->dol_use_jmobile)) {
  52. $conf->use_javascript_ajax = 1;
  53. }
  54. $php_self = $_SERVER['PHP_SELF'];
  55. $php_self .= dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '';
  56. $php_self = str_replace('action=validatenewpassword', '', $php_self);
  57. $titleofpage = $langs->trans('ResetPassword');
  58. // Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second
  59. $arrayofjs = array();
  60. $disablenofollow = 1;
  61. if (!preg_match('/'.constant('DOL_APPLICATION_TITLE').'/', $title)) {
  62. $disablenofollow = 0;
  63. }
  64. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  65. $disablenofollow = 0;
  66. }
  67. top_htmlhead('', $titleofpage, 0, 0, $arrayofjs, array(), 1, $disablenofollow);
  68. $colorbackhmenu1 = '60,70,100'; // topmenu
  69. if (!isset($conf->global->THEME_ELDY_TOPMENU_BACK1)) {
  70. $conf->global->THEME_ELDY_TOPMENU_BACK1 = $colorbackhmenu1;
  71. }
  72. $colorbackhmenu1 = empty($user->conf->THEME_ELDY_ENABLE_PERSONALIZED) ? (empty($conf->global->THEME_ELDY_TOPMENU_BACK1) ? $colorbackhmenu1 : $conf->global->THEME_ELDY_TOPMENU_BACK1) : (empty($user->conf->THEME_ELDY_TOPMENU_BACK1) ? $colorbackhmenu1 : $user->conf->THEME_ELDY_TOPMENU_BACK1);
  73. $colorbackhmenu1 = join(',', colorStringToArray($colorbackhmenu1)); // Normalize value to 'x,y,z'
  74. $edituser = new User($db);
  75. // Validate parameters
  76. if ($setnewpassword && $username && $passworduidhash) {
  77. $result = $edituser->fetch('', $username);
  78. if ($result < 0) {
  79. $message = '<div class="error">'.dol_escape_htmltag($langs->trans("ErrorTechnicalError")).'</div>';
  80. } else {
  81. global $dolibarr_main_instance_unique_id;
  82. //print $edituser->pass_temp.'-'.$edituser->id.'-'.$dolibarr_main_instance_unique_id.' '.$passworduidhash;
  83. if ($edituser->pass_temp && dol_verifyHash($edituser->pass_temp.'-'.$edituser->id.'-'.$dolibarr_main_instance_unique_id, $passworduidhash)) {
  84. // Clear session
  85. unset($_SESSION['dol_login']);
  86. // Parameters to reset the user are validated
  87. } else {
  88. $langs->load("errors");
  89. $message = '<div class="error">'.$langs->trans("ErrorFailedToValidatePasswordReset").'</div>';
  90. }
  91. }
  92. } else {
  93. $langs->load("errors");
  94. $message = '<div class="error">'.$langs->trans("ErrorFailedToValidatePasswordReset").'</div>';
  95. }
  96. ?>
  97. <!-- BEGIN PHP TEMPLATE PASSWORDFORGOTTEN.TPL.PHP -->
  98. <body class="body bodylogin"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND) ? '' : ' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; background-image: url(\''.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode('logos/'.$conf->global->MAIN_LOGIN_BACKGROUND).'\')"'; ?>>
  99. <?php if (empty($conf->dol_use_jmobile)) { ?>
  100. <script>
  101. $(document).ready(function () {
  102. // Set focus on correct field
  103. <?php if ($focus_element) {
  104. ?>$('#<?php echo $focus_element; ?>').focus(); <?php
  105. } ?> // Warning to use this only on visible element
  106. });
  107. </script>
  108. <?php } ?>
  109. <div class="login_center center"<?php
  110. if (empty($conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND)) {
  111. $backstyle = 'background: linear-gradient('.($conf->browser->layout == 'phone' ? '0deg' : '4deg').', rgb(240,240,240) 52%, rgb('.$colorbackhmenu1.') 52.1%);';
  112. // old style: $backstyle = 'background-image: linear-gradient(rgb('.$colorbackhmenu1.',0.3), rgb(240,240,240));';
  113. $backstyle = getDolGlobalString('MAIN_LOGIN_BACKGROUND_STYLE', $backstyle);
  114. print empty($conf->global->MAIN_LOGIN_BACKGROUND) ? ' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; '.$backstyle.'"' : '';
  115. }
  116. ?>>
  117. <div class="login_vertical_align">
  118. <form id="login" name="login" method="POST" action="<?php echo $php_self; ?>">
  119. <input type="hidden" name="token" value="<?php echo newToken(); ?>">
  120. <input type="hidden" name="action" value="buildnewpassword">
  121. <!-- Title with version -->
  122. <div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
  123. <?php
  124. if (!empty($disablenofollow)) {
  125. echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank" rel="noopener noreferrer external">';
  126. }
  127. echo dol_escape_htmltag($title);
  128. if (!empty($disablenofollow)) {
  129. echo '</a>';
  130. }
  131. ?>
  132. </div>
  133. <div class="login_table">
  134. <div id="login_line1">
  135. <div id="login_left">
  136. <img alt="" title="" src="<?php echo $urllogo; ?>" id="img_logo" />
  137. </div>
  138. <br>
  139. <div id="login_right">
  140. <div class="tagtable centpercent" title="Login pass" >
  141. <!-- New pass 1 -->
  142. <div class="trinputlogin">
  143. <div class="tagtd nowraponall center valignmiddle tdinputlogin">
  144. <!-- <span class="span-icon-user">-->
  145. <span class="fa fa-user"></span>
  146. <input type="text" maxlength="255" placeholder="<?php echo $langs->trans("NewPassword"); ?>" <?php echo $disabled; ?> id="newpass1" name="newpass1" class="flat input-icon-user minwidth150" value="<?php echo dol_escape_htmltag($newpass1); ?>" tabindex="1" autofocus />
  147. </div>
  148. </div>
  149. <div class="trinputlogin">
  150. <div class="tagtd nowraponall center valignmiddle tdinputlogin">
  151. <!-- <span class="span-icon-user">-->
  152. <span class="fa fa-user"></span>
  153. <input type="text" maxlength="255" placeholder="<?php echo $langs->trans("PasswordRetype"); ?>" <?php echo $disabled; ?> id="newpass2" name="newpass2" class="flat input-icon-user minwidth150" value="<?php echo dol_escape_htmltag($newpass2); ?>" tabindex="1" />
  154. </div>
  155. </div>
  156. <?php
  157. $captcha = 0;
  158. if (!empty($captcha)) {
  159. // Add a variable param to force not using cache (jmobile)
  160. $php_self = preg_replace('/[&\?]time=(\d+)/', '', $php_self); // Remove param time
  161. if (preg_match('/\?/', $php_self)) {
  162. $php_self .= '&time='.dol_print_date(dol_now(), 'dayhourlog');
  163. } else {
  164. $php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog');
  165. }
  166. // TODO: provide accessible captcha variants
  167. ?>
  168. <!-- Captcha -->
  169. <div class="trinputlogin">
  170. <div class="tagtd tdinputlogin nowrap none valignmiddle">
  171. <span class="fa fa-unlock"></span>
  172. <span class="nofa inline-block">
  173. <input id="securitycode" placeholder="<?php echo $langs->trans("SecurityCode"); ?>" class="flat input-icon-security width125" type="text" maxlength="5" name="code" tabindex="3" autocomplete="off" />
  174. </span>
  175. <span class="nowrap inline-block">
  176. <img class="inline-block valignmiddle" src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />
  177. <a class="inline-block valignmiddle" href="<?php echo $php_self; ?>" tabindex="4"><?php echo $captcha_refresh; ?></a>
  178. </span>
  179. </div></div>
  180. <?php
  181. }
  182. if (!empty($morelogincontent)) {
  183. if (is_array($morelogincontent)) {
  184. foreach ($morelogincontent as $format => $option) {
  185. if ($format == 'table') {
  186. echo '<!-- Option by hook -->';
  187. echo $option;
  188. }
  189. }
  190. } else {
  191. echo '<!-- Option by hook -->';
  192. echo $morelogincontent;
  193. }
  194. }
  195. ?>
  196. </div>
  197. </div> <!-- end div login_right -->
  198. </div> <!-- end div login_line1 -->
  199. <div id="login_line2" style="clear: both">
  200. <!-- Button "Regenerate and Send password" -->
  201. <br><input type="submit" <?php echo $disabled; ?> class="button small" name="button_password" value="<?php echo $langs->trans('Save'); ?>" tabindex="4" />
  202. <br>
  203. <div class="center" style="margin-top: 15px;">
  204. <?php
  205. $moreparam = '';
  206. if (!empty($conf->dol_hide_topmenu)) {
  207. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_hide_topmenu='.$conf->dol_hide_topmenu;
  208. }
  209. if (!empty($conf->dol_hide_leftmenu)) {
  210. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_hide_leftmenu='.$conf->dol_hide_leftmenu;
  211. }
  212. if (!empty($conf->dol_no_mouse_hover)) {
  213. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_no_mouse_hover='.$conf->dol_no_mouse_hover;
  214. }
  215. if (!empty($conf->dol_use_jmobile)) {
  216. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_use_jmobile='.$conf->dol_use_jmobile;
  217. }
  218. print '<a class="alogin" href="'.$dol_url_root.'/index.php'.$moreparam.'">'.$langs->trans('BackToLoginPage').'</a>';
  219. ?>
  220. </div>
  221. </div>
  222. </div>
  223. </form>
  224. <div class="center login_main_home divpasswordmessagedesc paddingtopbottom<?php echo empty($conf->global->MAIN_LOGIN_BACKGROUND) ? '' : ' backgroundsemitransparent boxshadow'; ?>" style="max-width: 70%">
  225. <?php
  226. if ($mode == 'dolibarr' || !$disabled) {
  227. if (empty($message)) {
  228. print '<span class="passwordmessagedesc opacitymedium">';
  229. print $langs->trans('EnterNewPasswordHere');
  230. print '</span>';
  231. }
  232. } else {
  233. print '<div class="warning center">';
  234. print $langs->trans('AuthenticationDoesNotAllowSendNewPassword', $mode);
  235. print '</div>';
  236. }
  237. ?>
  238. </div>
  239. <br>
  240. <?php if (!empty($message)) { ?>
  241. <div class="center login_main_message">
  242. <?php dol_htmloutput_mesg($message, '', '', 1); ?>
  243. </div>
  244. <?php } ?>
  245. <!-- Common footer is not used for passwordforgotten page, this is same than footer but inside passwordforgotten tpl -->
  246. <?php
  247. if (!empty($conf->global->MAIN_HTML_FOOTER)) {
  248. print $conf->global->MAIN_HTML_FOOTER;
  249. }
  250. if (!empty($morelogincontent) && is_array($morelogincontent)) {
  251. foreach ($morelogincontent as $format => $option) {
  252. if ($format == 'js') {
  253. echo "\n".'<!-- Javascript by hook -->';
  254. echo $option."\n";
  255. }
  256. }
  257. } elseif (!empty($moreloginextracontent)) {
  258. echo '<!-- Javascript by hook -->';
  259. echo $moreloginextracontent;
  260. }
  261. // Google Analytics
  262. // TODO Add a hook here
  263. if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) {
  264. $tmptagarray = explode(',', $conf->global->MAIN_GOOGLE_AN_ID);
  265. foreach ($tmptagarray as $tmptag) {
  266. print "\n";
  267. print "<!-- JS CODE TO ENABLE for google analtics tag -->\n";
  268. print "
  269. <!-- Global site tag (gtag.js) - Google Analytics -->
  270. <script async src=\"https://www.googletagmanager.com/gtag/js?id=".trim($tmptag)."\"></script>
  271. <script>
  272. window.dataLayer = window.dataLayer || [];
  273. function gtag(){dataLayer.push(arguments);}
  274. gtag('js', new Date());
  275. gtag('config', '".trim($tmptag)."');
  276. </script>";
  277. print "\n";
  278. }
  279. }
  280. // TODO Replace this with a hook
  281. // Google Adsense (need Google module)
  282. if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT)) {
  283. if (empty($conf->dol_use_jmobile)) {
  284. ?>
  285. <div class="center"><br>
  286. <script><!--
  287. google_ad_client = "<?php echo $conf->global->MAIN_GOOGLE_AD_CLIENT ?>";
  288. google_ad_slot = "<?php echo $conf->global->MAIN_GOOGLE_AD_SLOT ?>";
  289. google_ad_width = <?php echo $conf->global->MAIN_GOOGLE_AD_WIDTH ?>;
  290. google_ad_height = <?php echo $conf->global->MAIN_GOOGLE_AD_HEIGHT ?>;
  291. //-->
  292. </script>
  293. <script src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  294. </div>
  295. <?php
  296. }
  297. }
  298. ?>
  299. </div>
  300. </div> <!-- end of center -->
  301. </body>
  302. </html>
  303. <!-- END PHP TEMPLATE -->