dolibarr 22.0.5
passwordreset.tpl.php
1<?php
2/* Copyright (C) 2022 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20// Page called to validate a password change
21// To show this page, we need parameters: setnewpassword=1&username=...&passworduidhash=...
22
23if (!defined('NOBROWSERNOTIF')) {
24 define('NOBROWSERNOTIF', 1);
25}
49// Only vars provided by including page - htdocs/user/passwordforgotten.php:
50// $newpass1 and $newpass2 are not set!!!
51'
52@phan-var-force string $captcha
53@phan-var-force string $disabled
54@phan-var-force string $dol_url_root
55@phan-var-force string $focus_element
56@phan-var-force string $mode
57@phan-var-force string $message
58@phan-var-force string $title
59@phan-var-force string $urllogo
60@phan-var-force User $user
61@phan-var-force string $username
62@phan-var-force string $setnewpassword
63@phan-var-force string $passworduidhash
64';
65// Protection to avoid direct call of template
66if (empty($conf) || !is_object($conf)) {
67 print "Error, template page can't be called as URL";
68 exit(1);
69}
70
71// DDOS protection
72$size = (int) ($_SERVER['CONTENT_LENGTH'] ?? 0);
73if ($size > 10000) {
74 $langs->loadLangs(array("errors", "install"));
75 httponly_accessforbidden('<center>'.$langs->trans("ErrorRequestTooLarge").'<br><a href="'.DOL_URL_ROOT.'">'.$langs->trans("ClickHereToGoToApp").'</a></center>', 413, 1);
76}
77
78require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
79
80
81/*
82 * View
83 */
84
85header('Cache-Control: Public, must-revalidate');
86
87if (GETPOST('dol_hide_topmenu')) {
88 $conf->dol_hide_topmenu = 1;
89}
90if (GETPOST('dol_hide_leftmenu')) {
91 $conf->dol_hide_leftmenu = 1;
92}
93if (GETPOST('dol_optimize_smallscreen')) {
94 $conf->dol_optimize_smallscreen = 1;
95}
96if (GETPOST('dol_no_mouse_hover')) {
97 $conf->dol_no_mouse_hover = 1;
98}
99if (GETPOST('dol_use_jmobile')) {
100 $conf->dol_use_jmobile = 1;
101}
102
103// If we force to use jmobile, then we reenable javascript
104if (!empty($conf->dol_use_jmobile)) {
105 $conf->use_javascript_ajax = 1;
106}
107
108$php_self = $_SERVER['PHP_SELF'];
109$php_self .= dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '';
110$php_self = str_replace('action=validatenewpassword', '', $php_self);
111
112$titleofpage = $langs->trans('ResetPassword');
113
114// Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second
115$arrayofjs = array();
116
117$disablenofollow = 1;
118if (!preg_match('/'.constant('DOL_APPLICATION_TITLE').'/', $title)) {
119 $disablenofollow = 0;
120}
121if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
122 $disablenofollow = 0;
123}
124
125top_htmlhead('', $titleofpage, 0, 0, $arrayofjs, array(), 1, $disablenofollow);
126
127
128$colorbackhmenu1 = '60,70,100'; // topmenu
129if (!isset($conf->global->THEME_ELDY_TOPMENU_BACK1)) {
130 $conf->global->THEME_ELDY_TOPMENU_BACK1 = $colorbackhmenu1;
131}
132$colorbackhmenu1 = getDolUserString('THEME_ELDY_ENABLE_PERSONALIZED') ? getDolUserString('THEME_ELDY_TOPMENU_BACK1', $colorbackhmenu1) : getDolGlobalString('THEME_ELDY_TOPMENU_BACK1', $colorbackhmenu1);
133$colorbackhmenu1 = implode(',', colorStringToArray($colorbackhmenu1)); // Normalize value to 'x,y,z'
134
135
136$edituser = new User($db);
137
138
139// Validate parameters
140if ($setnewpassword && $username && $passworduidhash) {
141 $result = $edituser->fetch(0, $username);
142 if ($result < 0) {
143 $message = '<div class="error">'.dol_escape_htmltag($langs->trans("ErrorTechnicalError")).'</div>';
144 } else {
145 global $conf;
146
147 //print $edituser->pass_temp.'-'.$edituser->id.'-'.$conf->file->instance_unique_id.' '.$passworduidhash;
148 if ($edituser->pass_temp && dol_verifyHash($edituser->pass_temp.'-'.$edituser->id.'-'.$conf->file->instance_unique_id, $passworduidhash)) {
149 // Clear session
150 unset($_SESSION['dol_login']);
151
152 // Parameters to reset the user are validated
153 } else {
154 $langs->load("errors");
155 $message = '<div class="error">'.$langs->trans("ErrorFailedToValidatePasswordReset").'</div>';
156 }
157 }
158} else {
159 $langs->load("errors");
160 $message = '<div class="error">'.$langs->trans("ErrorFailedToValidatePasswordReset").'</div>';
161}
162
163
164?>
165<!-- BEGIN PHP TEMPLATE PASSWORDRESET.TPL.PHP -->
166
167<body class="body bodylogin"<?php print !getDolGlobalString('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/' . getDolGlobalString('MAIN_LOGIN_BACKGROUND')).'\')"'; ?>>
168
169<?php if (empty($conf->dol_use_jmobile)) { ?>
170<script>
171$(document).ready(function () {
172 // Set focus on correct field
173 <?php if ($focus_element) {
174 ?>$('#<?php echo $focus_element; ?>').focus(); <?php
175 } ?> // Warning to use this only on visible element
176});
177</script>
178<?php } ?>
179
180
181<div class="login_center center"<?php
182if (!getDolGlobalString('ADD_UNSPLASH_LOGIN_BACKGROUND')) {
183 $backstyle = 'background: linear-gradient('.($conf->browser->layout == 'phone' ? '0deg' : '4deg').', var(--colorbackbody) 52%, rgb('.$colorbackhmenu1.') 52.1%);';
184 // old style: $backstyle = 'background-image: linear-gradient(rgb('.$colorbackhmenu1.',0.3), rgb(240,240,240));';
185 $backstyle = getDolGlobalString('MAIN_LOGIN_BACKGROUND_STYLE', $backstyle);
186 print !getDolGlobalString('MAIN_LOGIN_BACKGROUND') ? ' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; '.$backstyle.'"' : '';
187}
188?>>
189<div class="login_vertical_align">
190
191<form id="login" name="login" method="POST" action="<?php echo $php_self; ?>">
192<input type="hidden" name="token" value="<?php echo newToken(); ?>">
193<input type="hidden" name="action" value="buildnewpassword">
194
195
196<!-- Title with version -->
197<div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
198<?php
199if (!empty($disablenofollow)) {
200 echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank" rel="noopener noreferrer external">';
201}
202echo dol_escape_htmltag($title);
203if (!empty($disablenofollow)) {
204 echo '</a>';
205}
206?>
207</div>
208
209
210
211<div class="login_table">
212
213<div id="login_line1">
214
215<div id="login_left">
216<img alt="" title="" src="<?php echo $urllogo; ?>" id="img_logo" />
217</div>
218
219<br>
220
221<div id="login_right">
222
223<div class="tagtable centpercent" title="Login pass" >
224
225<!-- New pass 1 -->
226<div class="trinputlogin">
227<div class="tagtd nowraponall center valignmiddle tdinputlogin">
228<!-- <span class="span-icon-user">-->
229<span class="fa fa-user"></span>
230<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 />
231</div>
232</div>
233<div class="trinputlogin">
234<div class="tagtd nowraponall center valignmiddle tdinputlogin">
235<!-- <span class="span-icon-user">-->
236<span class="fa fa-user"></span>
237<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" />
238</div>
239</div>
240
241
242<?php
243if (!empty($captcha)) {
244 // Add a variable param to force not using cache (jmobile)
245 $php_self = preg_replace('/[&\?]time=(\d+)/', '', $php_self); // Remove param time
246 if (preg_match('/\?/', $php_self)) {
247 $php_self .= '&time='.dol_print_date(dol_now(), 'dayhourlog');
248 } else {
249 $php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog');
250 }
251
252 $classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php';
253 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
254 $captchaobj = null;
255 if (dol_is_file($classfile)) {
256 // Charging the numbering class
257 $classname = "modCaptcha".ucfirst($captcha);
258 require_once $classfile;
259
260 $captchaobj = new $classname($db, $conf, $langs, $user);
261 }
262
263 if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) {
264 // TODO: get this code using a method of captcha
265 } else {
266 ?>
267 <!-- Captcha -->
268 <div class="trinputlogin">
269 <div class="tagtd tdinputlogin nowrap none valignmiddle">
270
271 <span class="fa fa-unlock"></span>
272 <span class="nofa inline-block">
273 <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" />
274 </span>
275 <span class="nowrap inline-block">
276 <img class="inline-block valignmiddle" src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />
277 <a class="inline-block valignmiddle" href="<?php echo $php_self; ?>" tabindex="4"><?php echo img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"'); ?></a>
278 </span>
279
280 </div>
281 </div>
282 <?php
283 }
284}
285
286if (!empty($morelogincontent)) {
287 if (is_array($morelogincontent)) {
288 foreach ($morelogincontent as $format => $option) {
289 if ($format == 'table') {
290 echo '<!-- Option by hook -->';
291 echo $option;
292 }
293 }
294 } else {
295 echo '<!-- Option by hook -->';
296 echo $morelogincontent;
297 }
298}
299?>
300
301</div>
302
303</div> <!-- end div login_right -->
304
305</div> <!-- end div login_line1 -->
306
307
308<div id="login_line2" style="clear: both">
309
310<!-- Button "Regenerate and Send password" -->
311<br><input type="submit" <?php echo $disabled; ?> class="button small" name="button_password" value="<?php echo $langs->trans('Save'); ?>" tabindex="4" />
312
313<br>
314<div class="center" style="margin-top: 15px;">
315 <?php
316 $moreparam = '';
317 if (!empty($conf->dol_hide_topmenu)) {
318 $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_hide_topmenu='.$conf->dol_hide_topmenu;
319 }
320 if (!empty($conf->dol_hide_leftmenu)) {
321 $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_hide_leftmenu='.$conf->dol_hide_leftmenu;
322 }
323 if (!empty($conf->dol_no_mouse_hover)) {
324 $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_no_mouse_hover='.$conf->dol_no_mouse_hover;
325 }
326 if (!empty($conf->dol_use_jmobile)) {
327 $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_use_jmobile='.$conf->dol_use_jmobile;
328 }
329
330 print '<a class="alogin" href="'.$dol_url_root.'/index.php'.$moreparam.'">'.$langs->trans('BackToLoginPage').'</a>';
331 ?>
332</div>
333
334</div>
335
336</div>
337
338</form>
339
340
341<?php
342if ($mode == 'dolibarr' || !$disabled) {
343 if (empty($message)) {
344 print '<div class="center login_main_home divpasswordmessagedesc paddingtopbottom'.(!getDolGlobalString('MAIN_LOGIN_BACKGROUND') ? '' : ' backgroundsemitransparent boxshadow').'" style="max-width: 70%">';
345 print '<span class="passwordmessagedesc opacitymedium">';
346 print $langs->trans('EnterNewPasswordHere');
347 print '</span>';
348 print '</div>';
349 }
350} else {
351 print '<div class="center login_main_home divpasswordmessagedesc paddingtopbottom'.(!getDolGlobalString('MAIN_LOGIN_BACKGROUND') ? '' : ' backgroundsemitransparent boxshadow').'" style="max-width: 70%">';
352 print '<div class="warning center">';
353 print $langs->trans('AuthenticationDoesNotAllowSendNewPassword', $mode);
354 print '</div>';
355 print '</div>';
356}
357?>
358
359
360<br>
361
362<?php if (!empty($message)) { ?>
363 <div class="center login_main_message">
364 <?php dol_htmloutput_mesg($message, [], '', 1); ?>
365 </div>
366<?php } ?>
367
368
369<!-- Common footer is not used for passwordforgotten page, this is same than footer but inside passwordforgotten tpl -->
370
371<?php
372if (getDolGlobalString('MAIN_HTML_FOOTER')) {
373 print $conf->global->MAIN_HTML_FOOTER;
374}
375
376if (!empty($morelogincontent) && is_array($morelogincontent)) {
377 foreach ($morelogincontent as $format => $option) {
378 if ($format == 'js') {
379 echo "\n".'<!-- Javascript by hook -->';
380 echo $option."\n";
381 }
382 }
383} elseif (!empty($moreloginextracontent)) {
384 echo '<!-- Javascript by hook -->';
385 echo $moreloginextracontent;
386}
387
388// Can add extra content
389$parameters = array();
390$dummyobject = new stdClass();
391$result = $hookmanager->executeHooks('getPasswordResetExtraContent', $parameters, $dummyobject, $action);
392print $hookmanager->resPrint;
393
394?>
395
396
397</div>
398</div> <!-- end of center -->
399
400
401</body>
402</html>
403<!-- END PHP TEMPLATE -->
print $object position
Definition edit.php:206
Class to manage Dolibarr users.
dol_is_file($pathoffile)
Return if path is a file.
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
dol_now($mode='auto')
Return date for now.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...