28 require
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/usergroups.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
32 if (!empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.
'/core/class/ldap.class.php';
35 $langs->loadLangs(array(
'errors',
'users',
'companies',
'ldap',
'other'));
38 if (!empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
40 header(
"Location: ".DOL_URL_ROOT.
'/');
44 $action =
GETPOST(
'action',
'aZ09');
45 $mode = $dolibarr_main_authentication;
46 if (!$mode) $mode =
'http';
48 $username =
GETPOST(
'username',
'alphanohtml');
49 $passwordhash =
GETPOST(
'passwordhash',
'alpha');
50 $conf->entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : 1);
53 $hookmanager->initHooks(array(
'passwordforgottenpage'));
56 if (
GETPOST(
'dol_hide_leftmenu',
'alpha') || !empty($_SESSION[
'dol_hide_leftmenu'])) $conf->dol_hide_leftmenu = 1;
57 if (
GETPOST(
'dol_hide_topmenu',
'alpha') || !empty($_SESSION[
'dol_hide_topmenu'])) $conf->dol_hide_topmenu = 1;
58 if (
GETPOST(
'dol_optimize_smallscreen',
'alpha') || !empty($_SESSION[
'dol_optimize_smallscreen'])) $conf->dol_optimize_smallscreen = 1;
59 if (
GETPOST(
'dol_no_mouse_hover',
'alpha') || !empty($_SESSION[
'dol_no_mouse_hover'])) $conf->dol_no_mouse_hover = 1;
60 if (
GETPOST(
'dol_use_jmobile',
'alpha') || !empty($_SESSION[
'dol_use_jmobile'])) $conf->dol_use_jmobile = 1;
67 $parameters = array(
'username' => $username);
68 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
70 $message = $hookmanager->error;
73 if (empty($reshook)) {
75 if ($action ==
'validatenewpassword' && $username && $passwordhash)
77 $edituser =
new User($db);
78 $result = $edituser->fetch(
'', $_GET[
"username"]);
81 $message =
'<div class="error">'.dol_escape_htmltag($langs->trans(
"ErrorLoginDoesNotExists", $username)).
'</div>';
86 unset($_SESSION[
'dol_login']);
87 $_SESSION[
'dol_loginmesg'] = $langs->trans(
'NewPasswordValidated');
89 $newpassword = $edituser->setPassword($user, $edituser->pass_temp, 0);
90 dol_syslog(
"passwordforgotten.php new password for user->id=".$edituser->id.
" validated in database");
91 header(
"Location: ".DOL_URL_ROOT.
'/');
94 $langs->load(
"errors");
95 $message =
'<div class="error">'.$langs->trans(
"ErrorFailedToValidatePasswordReset").
'</div>';
100 if ($action ==
'buildnewpassword' && $username)
102 $sessionkey =
'dol_antispam_value';
103 $ok = (array_key_exists($sessionkey, $_SESSION) ===
true && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST[
'code'])));
108 $message =
'<div class="error">'.$langs->trans(
"ErrorBadValueForCode").
'</div>';
110 $isanemail = preg_match(
'/@/', $username);
112 $edituser =
new User($db);
113 $result = $edituser->fetch(
'', $username,
'', 1);
114 if ($result == 0 && $isanemail)
116 $result = $edituser->fetch(
'',
'',
'', 1, -1, $username);
119 if ($result <= 0 && $edituser->error ==
'USERNOTFOUND')
121 $message =
'<div class="warning paddingtopbottom'.(empty($conf->global->MAIN_LOGIN_BACKGROUND) ?
'' :
' backgroundsemitransparent').
'">';
123 $message .= $langs->trans(
"IfLoginExistPasswordRequestSent");
125 $message .= $langs->trans(
"IfEmailExistPasswordRequestSent");
127 $message .=
'</div>';
130 if (!$edituser->email)
132 $message =
'<div class="error">'.$langs->trans(
"ErrorLoginHasNoEmail").
'</div>';
134 $newpassword = $edituser->setPassword($user,
'', 1);
135 if ($newpassword < 0)
138 $message =
'<div class="error">'.$langs->trans(
"ErrorFailedToChangePassword").
'</div>';
141 if ($edituser->send_password($user, $newpassword, 1) > 0)
143 $message =
'<div class="warning paddingtopbottom'.(empty($conf->global->MAIN_LOGIN_BACKGROUND) ?
'' :
' backgroundsemitransparent').
'">';
145 $message .= $langs->trans(
"IfLoginExistPasswordRequestSent");
147 $message .= $langs->trans(
"IfEmailExistPasswordRequestSent");
150 $message .=
'</div>';
153 $message .=
'<div class="error">'.$edituser->error.
'</div>';
170 $title =
'Dolibarr '.DOL_VERSION;
171 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $title = $conf->global->MAIN_APPLICATION_TITLE;
174 if (file_exists(DOL_DOCUMENT_ROOT.
"/theme/".$conf->theme.
"/tpl/passwordforgotten.tpl.php"))
176 $template_dir = DOL_DOCUMENT_ROOT.
"/theme/".$conf->theme.
"/tpl/";
178 $template_dir = DOL_DOCUMENT_ROOT.
"/core/tpl/";
181 if (!$username) $focus_element =
'username';
182 else $focus_element =
'password';
185 $disabled =
'disabled';
186 if (preg_match(
'/dolibarr/i', $mode)) $disabled =
'';
187 if (!empty($conf->global->MAIN_SECURITY_ENABLE_SENDPASSWORD)) $disabled =
'';
192 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
193 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small))
195 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
196 } elseif (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo))
198 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
200 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/img/dolibarr_logo.svg'))
202 $urllogo = DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/dolibarr_logo.svg';
203 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg'))
205 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
209 if (function_exists(
"imagecreatefrompng") && !$disabled)
212 $captcha_refresh =
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"');
216 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'));
217 $hookmanager->executeHooks(
'getPasswordForgottenPageOptions', $parameters);
218 if (is_array($hookmanager->resArray) && !empty($hookmanager->resArray)) {
219 $morelogincontent = $hookmanager->resArray;
221 $morelogincontent = $hookmanager->resPrint;
225 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'));
226 $reshook = $hookmanager->executeHooks(
'getPasswordForgottenPageExtraOptions', $parameters);
227 $moreloginextracontent = $hookmanager->resPrint;
229 include $template_dir.
'passwordforgotten.tpl.php';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
if($reshook< 0) if(empty($reshook)) $dol_url_root
View.
dol_verifyHash($chain, $hash, $type= '0')
Compute a hash and compare it to the given one For backward compatibility reasons, if the hash is not in the password_hash format, we will try to match against md5 and sha1md5 If constant MAIN_SECURITY_HASH_ALGO is defined, we use this function as hashing function.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.